Package components.set
Class Set3<T>
java.lang.Object
components.set.SetSecondary<T>
components.set.Set3<T>
- Type Parameters:
T- type ofSetelements
Set represented as a BinaryTree (maintained as a binary
search tree) of elements with implementations of primary methods.- Mathematical Definitions:
IS_TOTAL_PREORDER ( r: binary relation on T ) : boolean is for all x, y, z: T ((r(x, y) or r(y, x)) and (if (r(x, y) and r(y, z)) then r(x, z))) IS_BST( tree: binary tree of T, r: binary relation on T ): boolean satisfies [tree satisfies the binary search tree ordering property according to the relation r and has no duplicate labels]- Representation Invariant (concrete invariant of $this):
IS_TOTAL_PREORDER([relation computed by $this.order.compare method] and IS_BST($this.tree, $this.order)- Abstraction Relation (interpretation mapping between $this and this):
this = labels($this.tree)
-
Constructor Summary
ConstructorsConstructorDescriptionSet3()No-argument constructor: usesComparable'scompareToorder if available; otherwise, compareshashCodes.Set3(Comparator<T> order) Constructor using givenComparator'scompareorder. -
Method Summary
Modifier and TypeMethodDescriptionfinal voidAddsxto this.final voidclear()Resetsthisto an initial value.final booleanReports whetherxis inthis.iterator()Returns a new object with the same dynamic type asthis, having an initial value.final TRemovesxfrom this, and returns it.final TRemoves and returns an arbitrary element fromthis.final intsize()Reports size (cardinality) ofthis.final voidtransferFrom(Set<T> source) Setsthisto the incoming value ofsource, and resetssourceto an initial value; the declaration notwithstanding, the dynamic type ofsourcemust be the same as the dynamic type ofthis.Methods inherited from class components.set.SetSecondary
add, equals, hashCode, isSubset, remove, toStringMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
Set3
public Set3()No-argument constructor: usesComparable'scompareToorder if available; otherwise, compareshashCodes. -
Set3
Constructor using givenComparator'scompareorder.- Parameters:
order- the order for the BST
-
-
Method Details
-
newInstance
Description copied from interface:StandardReturns a new object with the same dynamic type asthis, having an initial value. If the typeThas a no-argument constructor, then the value of the new returned object satisfies the contract of the no-argument constructor forT. IfTdoes not have a no-argument constructor, then the value of the new returned object satisfies the contract of the constructor call that was used to initializethis.- Returns:
- new object "like"
thiswith an initial value
-
clear
Description copied from interface:StandardResetsthisto an initial value. If the typeThas a no-argument constructor, thenthissatisfies the contract of the no-argument constructor forT. IfTdoes not have a no-argument constructor, thenthissatisfies the contract of the constructor call that was used to initialize#this. -
transferFrom
Description copied from interface:StandardSetsthisto the incoming value ofsource, and resetssourceto an initial value; the declaration notwithstanding, the dynamic type ofsourcemust be the same as the dynamic type ofthis. If the typeThas a no-argument constructor, thensourcesatisfies the contract of the no-argument constructor forT. IfTdoes not have a no-argument constructor, thensourcesatisfies the contract of the constructor call that was used to initialize#source.- Parameters:
source- object whose value is to be transferred
-
add
Description copied from interface:SetKernelAddsxto this.- Parameters:
x- the element to be added
-
remove
Description copied from interface:SetKernelRemovesxfrom this, and returns it.- Parameters:
x- the element to be removed- Returns:
- the element removed
-
removeAny
Description copied from interface:SetKernelRemoves and returns an arbitrary element fromthis.- Returns:
- the element removed from
this
-
contains
Description copied from interface:SetKernelReports whetherxis inthis.- Parameters:
x- the element to be checked- Returns:
- true iff element is in
this
-
size
Description copied from interface:SetKernelReports size (cardinality) ofthis.- Returns:
- the number of elements in
this
-
iterator
-