Package cruise.umple.compiler
Class ConstraintTree
java.lang.Object
cruise.umple.compiler.ConstraintVariable
cruise.umple.compiler.ConstraintTree
- All Implemented Interfaces:
java.lang.Iterable<ConstraintVariable>
- Direct Known Subclasses:
BasicConstraint
,Guard
,Postcondition
,Precondition
,TraceConstraint
public class ConstraintTree extends ConstraintVariable
ConstraintTrees are a redundant class that are necessary because of lone constraints, i.e. [true] has to be handled, and does not contain an operator
If lone constraints didn't exist then the ConstraintTree class could be condensed into ConstraintOperator. One nice religation of responsibilities is that ConstraintTrees take care of the ! and () symbols, leaving the ConstraintOperator class to be more pure
NEW CLASS****************************************
-
Constructor Summary
Constructors Constructor Description ConstraintTree()
-
Method Summary
Modifier and Type Method Description ConstraintVariable
addElement(ConstraintVariable aElement)
Adds a node to the tree, the three modes are - if nothing exists in the tree: set the element as the root - if the element is an operator: add the root if it is not null as an operand to the operator, and set the operator to the root - if there exists an operator: add the element as an operand to the operator.void
addElementAll(ConstraintVariable cv)
Used by trees to add all the elements of another tree to this treeConstraintTree
clone(ConstraintTree tree)
Copies non-constraint data such as whether the tree should display the ! symbol and whether it should display ( ) around the treeeConstraintTree
createNew()
Creates a new instance of this class, it is used in clone and addElement in order to copy a tree so that there is a deep copy instead of a shallow one This method needs to be overrided for sub classes of ConstaintTree to function properly.void
delete()
boolean
equals(java.lang.Object obj)
boolean
getDisplayBrackets()
boolean
getDisplayNegation()
java.lang.String
getNamedNames()
Whenever ConstraintTrees or named Constriants are added to the constraint tree, a record of that name is added to a set of names This method pretty prints that set of names.java.util.TreeSet<java.lang.String>
getNames()
int
getNumberOfElements()
ConstraintOperator
getRequestor()
ConstraintVariable
getRoot()
boolean
getShouldDisplayBrackets()
java.lang.String
getType()
Mandatory type method for the SuperGenerator to distiguish easily between different ConstraintVariable types.int
hashCode()
boolean
isEqualTo(ConstraintTree inConstraintTree)
---------------------------------------------------------------------------- ---------------------------------Start-------------------------------------- ----------------------------------------------------------------------------boolean
isNegatable()
The public counterpart to the isNegateVariabe method, it checks negativability of this ConstraintTree's root, starting off the recursive decent into the negation of the treejava.util.Iterator<ConstraintVariable>
iterator()
Iterator method, override the method from the Iterableinterface that all ConstraintVariables inherit from Iterates over all of the root's elements, then returns itself boolean
negate()
The public counterpart to the negateVariabe method, it negates this ConstraintTree's root, starting off the recursive decent into the negation of the treeboolean
setDisplayNegation(boolean aDisplayNegation)
boolean
setNames(java.util.TreeSet<java.lang.String> aNames)
boolean
setNumberOfElements(int aNumberOfElements)
boolean
setRequestor(ConstraintOperator aRequestor)
boolean
setRoot(ConstraintVariable aRoot)
boolean
setShouldDisplayBrackets(boolean aShouldDisplayBrackets)
java.lang.String
toString()
-
Constructor Details
-
ConstraintTree
public ConstraintTree()
-
-
Method Details
-
setRoot
-
setRequestor
-
setNames
public boolean setNames(java.util.TreeSet<java.lang.String> aNames) -
setShouldDisplayBrackets
public boolean setShouldDisplayBrackets(boolean aShouldDisplayBrackets) -
setDisplayNegation
public boolean setDisplayNegation(boolean aDisplayNegation) -
setNumberOfElements
public boolean setNumberOfElements(int aNumberOfElements) -
getRoot
-
getRequestor
-
getNames
public java.util.TreeSet<java.lang.String> getNames() -
getShouldDisplayBrackets
public boolean getShouldDisplayBrackets() -
getDisplayNegation
public boolean getDisplayNegation() -
getDisplayBrackets
public boolean getDisplayBrackets() -
getNumberOfElements
public int getNumberOfElements() -
equals
public boolean equals(java.lang.Object obj)- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()- Overrides:
hashCode
in classjava.lang.Object
-
delete
public void delete()- Overrides:
delete
in classConstraintVariable
-
addElementAll
Used by trees to add all the elements of another tree to this tree- Parameters:
cv
- the constraint variable node to add to this tree(if it is a ConstraintTree it will add all of it's sub elements via the addElement method)
-
negate
public boolean negate()The public counterpart to the negateVariabe method, it negates this ConstraintTree's root, starting off the recursive decent into the negation of the tree -
isNegatable
public boolean isNegatable()The public counterpart to the isNegateVariabe method, it checks negativability of this ConstraintTree's root, starting off the recursive decent into the negation of the tree -
clone
Copies non-constraint data such as whether the tree should display the ! symbol and whether it should display ( ) around the treee -
createNew
Creates a new instance of this class, it is used in clone and addElement in order to copy a tree so that there is a deep copy instead of a shallow one This method needs to be overrided for sub classes of ConstaintTree to function properly. -
addElement
Adds a node to the tree, the three modes are - if nothing exists in the tree: set the element as the root - if the element is an operator: add the root if it is not null as an operand to the operator, and set the operator to the root - if there exists an operator: add the element as an operand to the operator.- Parameters:
element
- to be added to the tree
-
getNamedNames
public java.lang.String getNamedNames()Whenever ConstraintTrees or named Constriants are added to the constraint tree, a record of that name is added to a set of names This method pretty prints that set of names. -
iterator
Iterator method, override the method from the Iterableinterface that all ConstraintVariables inherit from Iterates over all of the root's elements, then returns itself - Specified by:
iterator
in interfacejava.lang.Iterable<ConstraintVariable>
- Overrides:
iterator
in classConstraintVariable
-
getType
public java.lang.String getType()Mandatory type method for the SuperGenerator to distiguish easily between different ConstraintVariable types.- Specified by:
getType
in classConstraintVariable
-
isEqualTo
---------------------------------------------------------------------------- ---------------------------------Start-------------------------------------- ---------------------------------------------------------------------------- -
toString
public java.lang.String toString()- Overrides:
toString
in classjava.lang.Object
-