|
JML | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.jmlspecs.samples.sets.IntegerSetAsTree
Sets of integers implemented as binary search trees. This implementation demonstrates the use of JML's helper modifier.
Class Specifications |
private invariant (this.left != null||this.right != null) ==> !this.isEmpty; private invariant this.left != null ==> ( \forall org.jmlspecs.models.JMLInteger i; i != null&&this.left.theSet.has(i); i.intValue() < this.rootValue); private invariant this.right != null ==> ( \forall org.jmlspecs.models.JMLInteger i; i != null&&this.right.theSet.has(i); this.rootValue < i.intValue()); private invariant this.parent != null ==> !this.parent.isEmpty; private invariant this.parent != null&&this.parent.left != null ==> this.parent.left.rootValue < this.parent.rootValue; private invariant this.parent != null&&this.parent.right != null ==> this.parent.rootValue < this.parent.right.rootValue; private invariant this.left != null ==> !this.left.isEmpty&&this.left.rootValue < this.rootValue; private invariant this.right != null ==> !this.right.isEmpty&&this.rootValue < this.right.rootValue; private represents theSet <- this.abstractValue(); |
Specifications inherited from class Object |
represents objectState <- org.jmlspecs.lang.JMLDataGroup.IT; public represents _getClass <- \typeof(this); |
Specifications inherited from interface IntegerSetInterface |
instance public invariant_redundantly this.theSet != null; instance public invariant ( \forall org.jmlspecs.models.JMLType e; this.theSet.has(e); e instanceof org.jmlspecs.models.JMLInteger); public initially this.theSet.isEmpty(); |
Model Field Summary |
Model fields inherited from class java.lang.Object |
_getClass, objectState, theString |
Model fields inherited from interface org.jmlspecs.samples.sets.IntegerSetInterface |
theSet |
Ghost Field Summary |
Ghost fields inherited from class java.lang.Object |
objectTimesFinalized, owner |
Field Summary | |
private boolean |
isEmpty
Is this tree empty? |
private IntegerSetAsTree |
left
The left subtree, which may be null. |
private IntegerSetAsTree |
parent
The parent of this subtree, which may be null. |
private IntegerSetAsTree |
right
The right subtree, which may be null. |
private int |
rootValue
The integer at the root of the set. |
Constructor Summary | |
|
IntegerSetAsTree()
Initialize this integer set to be empty. |
protected |
IntegerSetAsTree(int elem,
IntegerSetAsTree par)
|
Model Method Summary | |
JMLValueSet |
abstractValue()
Return the abstract value of this IntegerSetAsTree. |
Model methods inherited from class java.lang.Object |
hashValue |
Method Summary | |
private void |
constrHelper()
Set the left and right to null. |
private IntegerSetAsTree |
getPredecessor()
|
private IntegerSetAsTree |
getSuccessor()
|
void |
insert(int elem)
Insert the given integer into this set. |
private boolean |
isLeftChild()
Is this node and left child of its parent?. |
boolean |
isMember(int elem)
Tell if the argument is in this set. |
protected String |
printTree(boolean isFirst)
|
void |
remove(int elem)
Remove the given integer from this set. |
private void |
removeHelper(int elem)
Remove the given integer from this set. |
private void |
removeLeaf()
Remove an integer from a leaf node. |
private void |
removeRoot()
Replace the current node with the successor or predecessor. |
String |
toString()
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
private boolean isEmpty
private int rootValue
private IntegerSetAsTree left
private IntegerSetAsTree right
private IntegerSetAsTree parent
Constructor Detail |
public IntegerSetAsTree()
protected IntegerSetAsTree(int elem, IntegerSetAsTree par)
Model Method Detail |
public JMLValueSet abstractValue()
Method Detail |
private void constrHelper()
public void insert(int elem)
IntegerSetInterface
insert
in interface IntegerSetInterface
public boolean isMember(int elem)
IntegerSetInterface
isMember
in interface IntegerSetInterface
public void remove(int elem)
IntegerSetInterface
remove
in interface IntegerSetInterface
private void removeHelper(int elem)
private void removeRoot()
private void removeLeaf()
private boolean isLeftChild()
private IntegerSetAsTree getSuccessor()
private IntegerSetAsTree getPredecessor()
public String toString()
toString
in class Object
protected String printTree(boolean isFirst)
|
JML | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |