sub_arctic.constraints
Class std_constraint_impl

java.lang.Object
  |
  +--sub_arctic.constraints.std_constraint_impl

public class std_constraint_impl
extends java.lang.Object
implements constraint_impl, std_encoding_consts

Class that provides the implementation for standard lightweight constraints. This class understand how to encode and decode an integer encoding of a constraint, and use that to perform operations such as evaluate the constraint, determine if it depends upon a particular value, produce a human readable rendition of the constraint, etc.

There should only be one instance of this class created: std_constraint_impl.the_impl(). This should be shared by all constraints. encoded in standard form.

In order to organize this class into more manageable units, it is actually implemented with four helper classes, one for each of the possible numbers of operands to the constraint. These are: op0_impl, op1_impl, op2_impl, and op3_impl. See those classes for full encoding details.

See Also:
op0_impl, op1_impl, op2_impl, op3_impl

Field Summary
protected static std_constraint_impl _the_impl
          The one and only instance of this class.
protected static int ENABLED
           
protected static int H
           
protected static int PART_A
           
protected static int PART_B
           
protected static int VISIBLE
           
protected static int W
           
protected static int X
           
protected static int Y
           
 
Constructor Summary
protected std_constraint_impl()
          Protected constructor -- no instances of this class should be created outside the one stored statically with the class (the_impl).
 
Method Summary
protected  void add_depend_obj_part(java.util.Vector result, int part_enc, interactor constr_obj, int orient)
          Extract a depended upon object/part from the given object/part encoding and add it to the end of the given vector.
protected  void add_depend_part(java.util.Vector result, int part_enc, int orient)
          Append depended upon part numbers to the given Vector.
 java.lang.String const_str(int enc)
          Create a human readable string corresponding to the constant contained in the given encoded constraint.
 java.util.Vector depend_list(int enc, interactor constr_obj, int orient)
          Extract the set of objects/parts that a constraint depends on.
 boolean depends_on(int enc, interactor constr_obj, int which_obj, int which_part, int nth_child, int orient)
          Test whether the given encoded constraint depends on the indicated neighboring object and part.
 int eval(int enc, interactor constr_obj, int constr_part, int orient)
          Evaluate an encoded constraint (under a given orientation).
 int fetch_value(int objpart_code, interactor constr_obj, int orient)
          Fetch the indicated depended-upon value for the given object and part.
protected  int get_parent_value(interactor from_obj, int from_part, int orient)
          Fetch a particular value from a parent object on behalf of a given part in a particular orientation.
protected  int get_value(interactor from_obj, int from_part, int orient)
          Fetch a particular value on behalf of a given part in a particular orientation.
 java.util.Vector implicit_depend_list(int enc, interactor constr_obj, int orient)
          Extract the dependencies that are implicit in the particular operation encoded in the given standard constraint encoding.
 boolean is_external(int enc)
          Determine if a given constraint encoding represents an external constraint.
 boolean is_none(int enc)
          Determine if a given constraint encoding represents "none" (i.e., that no constraint is to be applied).
 int num_ops(int enc)
          Determine which kind of constraint (how many operands) the given encoding has.
 java.lang.String obj_part_str(int enc, int orient)
          Create a human readable string corresponding to an object/part designator.
 java.lang.String obj_part_tag(int enc, int orient)
          Create a terse human readable string corresponding to an object/part designator.
 java.lang.String opcode_str(int enc)
          Create a human readable string corresponding to the op_code from the given constraint encoding.
 java.lang.String opcode_tag(int enc)
          Create a terse human readable string corresponding to the op_code from the given constraint encoding.
 java.lang.String operand_str(int enc, int orient)
          Create a human readable string corresponding to the operands of the given constraint encoding.
 java.lang.String operand_tag(int enc, int orient)
          Create a terse human readable string corresponding to the operands of the given constraint encoding.
 boolean part_depends_on(int enc, interactor constr_obj, int which_obj, int which_part, int nth_child, int orient)
          Test whether the given encoded object/part indicates the given object and part for dependency purposes.
 java.lang.String str_for(int enc, int orient)
          Create a human readable string corresponding to the given constraint encoding.
 java.lang.String tag_for(int enc, int orient)
          Create a terse human readable string corresponding to the given constraint encoding.
static std_constraint_impl the_impl()
          The one and only instance of this class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_the_impl

protected static final std_constraint_impl _the_impl
The one and only instance of this class. This instance should be shared by all constraints encoded in standard form.

X

protected static final int X

Y

protected static final int Y

W

protected static final int W

H

protected static final int H

VISIBLE

protected static final int VISIBLE

ENABLED

protected static final int ENABLED

PART_A

protected static final int PART_A

PART_B

protected static final int PART_B
Constructor Detail

std_constraint_impl

protected std_constraint_impl()
Protected constructor -- no instances of this class should be created outside the one stored statically with the class (the_impl).
Method Detail

the_impl

public static std_constraint_impl the_impl()
The one and only instance of this class. This instance should be shared by all constraints encoded in standard form.

num_ops

public int num_ops(int enc)
Determine which kind of constraint (how many operands) the given encoding has.

Parameters:
int - enc the encoding for the constraint.
Returns:
int the number of operands in the encoded constraint.

const_str

public java.lang.String const_str(int enc)
Create a human readable string corresponding to the constant contained in the given encoded constraint.

Parameters:
int - enc the constraint encoding
Returns:
String a string depicting the designator

obj_part_str

public java.lang.String obj_part_str(int enc,
                                     int orient)
Create a human readable string corresponding to an object/part designator.
Parameters:
int - enc the designator encoding
int - orient the orientation of the encoding (HORIZONTAL or VERTICAL)
Returns:
String a string depicting the designator

opcode_str

public java.lang.String opcode_str(int enc)
Create a human readable string corresponding to the op_code from the given constraint encoding.
Parameters:
int - enc the constraint encoding
Returns:
String a human readable string with the extracted op code

operand_str

public java.lang.String operand_str(int enc,
                                    int orient)
Create a human readable string corresponding to the operands of the given constraint encoding.
Parameters:
int - enc the constraint encoding
int - orient the orientation of the encoding (HORIZONTAL or VERTICAL)
Returns:
String a human readable string for the operands

str_for

public java.lang.String str_for(int enc,
                                int orient)
Create a human readable string corresponding to the given constraint encoding.
Specified by:
str_for in interface constraint_impl
Parameters:
int - enc the constraint encoding
int - orient the orientation of the encoding (HORIZONTAL or VERTICAL)
Returns:
String a human readable string for the constraint

obj_part_tag

public java.lang.String obj_part_tag(int enc,
                                     int orient)
Create a terse human readable string corresponding to an object/part designator.
Parameters:
int - enc the designator encoding
int - orient the orientation of the encoding (HORIZONTAL or VERTICAL)
Returns:
String a string depicting the designator

opcode_tag

public java.lang.String opcode_tag(int enc)
Create a terse human readable string corresponding to the op_code from the given constraint encoding.
Parameters:
int - enc the constraint encoding
Returns:
String a human readable string with the extracted op code

operand_tag

public java.lang.String operand_tag(int enc,
                                    int orient)
Create a terse human readable string corresponding to the operands of the given constraint encoding.
Parameters:
int - enc the constraint encoding
int - orient the orientation of the encoding (HORIZONTAL or VERTICAL)
Returns:
String a human readable string for the operands

tag_for

public java.lang.String tag_for(int enc,
                                int orient)
Create a terse human readable string corresponding to the given constraint encoding.
Specified by:
tag_for in interface constraint_impl
Parameters:
int - enc the constraint encoding
int - orient the orientation of the encoding (HORIZONTAL or VERTICAL)
Returns:
String a human readable string for the constraint

get_value

protected int get_value(interactor from_obj,
                        int from_part,
                        int orient)
Fetch a particular value on behalf of a given part in a particular orientation. This is used for non-parent values only. No coord transform is applied to the value before it is returned

Parameters:
interactor - from_obj object we are getting the value from
int - from_part component of that object we want
int - orient orientation (should be HORIZONTAL or VERTICAL)
See Also:
get_parent_value(sub_arctic.lib.interactor, int, int)

get_parent_value

protected int get_parent_value(interactor from_obj,
                               int from_part,
                               int orient)
Fetch a particular value from a parent object on behalf of a given part in a particular orientation. This is used for parent values only. It applied coordinate transform for position values to place them in the local coordinates of the "from_obj" (which is the parent)

Parameters:
interactor - from_obj object we are getting the value from
int - from_part component of that object we want
int - orient orientation (should be HORIZONTAL or VERTICAL)
See Also:
get_parent_value(sub_arctic.lib.interactor, int, int)

fetch_value

public int fetch_value(int objpart_code,
                       interactor constr_obj,
                       int orient)
Fetch the indicated depended-upon value for the given object and part.

Parameters:
int - objpart_code encoding of object/part we need to fetch
interactor - constr_obj constrained object we are fetching value for. fetched values are found relative to this object.
int - orient orientation of fetched value (should be HORIZONTAL or VERTICAL).
Returns:
int fetched value (brought up to date if necessary

is_none

public boolean is_none(int enc)
Determine if a given constraint encoding represents "none" (i.e., that no constraint is to be applied).

Specified by:
is_none in interface constraint_impl
Parameters:
int - enc the encoding for the constraint.
Returns:
boolean whether the encoding indicates "none".

is_external

public boolean is_external(int enc)
Determine if a given constraint encoding represents an external constraint.

Specified by:
is_external in interface constraint_impl
Parameters:
int - enc the encoding for the constraint.
boolean - whether the encoding indicates an external constraint.

eval

public int eval(int enc,
                interactor constr_obj,
                int constr_part,
                int orient)
Evaluate an encoded constraint (under a given orientation). The constraint is being applied to the given part of the given object (i.e. the constr_part part of the constr_obj object). The encoding typically will designate parameter values relative to that object (i.e. the width of the parent of the object).

Specified by:
eval in interface constraint_impl
Parameters:
int - enc the encoding of the constraint
interactor - constr_obj the object being constrained
int - constr_part the part being constrained
int - orient the orientation of the constraint
Returns:
int the result of the evaluation

depends_on

public boolean depends_on(int enc,
                          interactor constr_obj,
                          int which_obj,
                          int which_part,
                          int nth_child,
                          int orient)
Test whether the given encoded constraint depends on the indicated neighboring object and part. The constraint is attached to the constr_obj object and this test is expressed relative to that object. The object and part that we determining dependency upon is encoded in test_which_obj and test_which_part. For tests of child objects, an indication of the index of that child is also given.

If this is an "external" constraint that maintains its own dependency edges and works through the external notification system, then this method may safely return false in all cases.

Specified by:
depends_on in interface constraint_impl
Parameters:
int - enc The encoding for the constraint.
interactor - constr_obj The object the constraint is attached to
int - test_which_obj The neighboring object we are asking about. This can be one of the values OBJCODE_SELF, OBJCODE_PARENT, OBJCODE_SOME_CHILD, OBJCODE_PREV_SIBLING, or OBJCODE_NEXT_SIBLING.
int - test_which_part The part we are asking about.
int - nth_child for SOME_CHILD, this provides the index of the child (and is ignored otherwise).
int - orient Orientation of the constraint. This should be HORIZONTAL or VERTICAL.
Returns:
boolean whether the given constraint depends upon the given value

part_depends_on

public boolean part_depends_on(int enc,
                               interactor constr_obj,
                               int which_obj,
                               int which_part,
                               int nth_child,
                               int orient)
Test whether the given encoded object/part indicates the given object and part for dependency purposes. For example, part_depends_on(enc, cobj, OBJCODE_PARENT, PARTCODE_W, 0, HORIZONTAL) would test if the object/part encoded in enc and part of the constraint attached to cobj indicates a dependency on the width of the parent of cobj.
Parameters:
int - enc The encoding we are testing.
interactor - constr_obj The object the constraint is attached to
int - test_which_obj The object we are asking about. This can be one of the values OBJCODE_SELF, OBJCODE_PARENT, OBJCODE_SOME_CHILD, OBJCODE_PREV_SIBLING, or OBJCODE_NEXT_SIBLING.
int - test_which_part The part we are asking about.
int - nth_child for SOME_CHILD, this provides the index of the child (and is ignored otherwise).
int - orient Orientation of the constraint. This should be HORIZONTAL or VERTICAL.
Returns:
boolean whether the given constraint depends upon the given value

depend_list

public java.util.Vector depend_list(int enc,
                                    interactor constr_obj,
                                    int orient)
Extract the set of objects/parts that a constraint depends on. This produces a Vector with pairs of entries, the first being an interactor, and the second being an Integer which is the part number of that interactor that is depended upon.

Specified by:
depend_list in interface constraint_impl
Parameters:
int - enc encoding value for the constraint in question.
interactor - constr_obj the object the constraint is attached to (hence its referents are relative to).
int - orient Orientation of the constraint. This should be HORIZONTAL or VERTICAL.
Returns:
Vector containing pairs of objects, the first being an interactor which is depended upon, and the second being an Integer giving the part number of the part depended upon.

implicit_depend_list

public java.util.Vector implicit_depend_list(int enc,
                                             interactor constr_obj,
                                             int orient)
Extract the dependencies that are implicit in the particular operation encoded in the given standard constraint encoding.

Specified by:
implicit_depend_list in interface constraint_impl
Parameters:
int - enc encoding value for the constraint in question.
interactor - constr_obj the object the constraint is attached to (hence its referents are relative to).
int - orient Orientation of the constraint. This should be HORIZONTAL or VERTICAL.
Returns:
Vector containing pairs of objects, the first being an interactor which is depended upon, and the second being an Integer giving the part number of the part depended upon.

add_depend_obj_part

protected void add_depend_obj_part(java.util.Vector result,
                                   int part_enc,
                                   interactor constr_obj,
                                   int orient)
Extract a depended upon object/part from the given object/part encoding and add it to the end of the given vector. This is used by depend_list() to produce parts of its result. Appended to the Vector will be two values, an interactor which is the object depended upon, and an Integer with the part number within that object that is depended upon.

Parameters:
Vector - result the Vector object we add to the end of.
int - part_enc encoding value for object/part in question.
interactor - constr_obj the object the constraint is attached to (hence its referents are relative to).
int - orient Orientation of the constraint. This should be HORIZONTAL or VERTICAL.

add_depend_part

protected void add_depend_part(java.util.Vector result,
                               int part_enc,
                               int orient)
Append depended upon part numbers to the given Vector. This assumes that the last element of the vector contains the object depended on. If the part encoding given requires multiple dependencies additional dependent object values will be added so that we always have object/part pairs.

Parameters:
Vector - result the Vector object we add to the end of.
int - part_enc encoding value for part in question.
int - orient Orientation of the constraint. This should be HORIZONTAL or VERTICAL.