All Packages Class Hierarchy This Package Previous Next Index
Class structure.ComparableSet
java.lang.Object

+structure.ComparableSet
 public class ComparableSet
 extends Object
 implements Set
An implementation of sets of comparable objects. The underlying
structure makes use of the comparability of the values to efficiently
implement many of the operations.
When writing objects to be stored in comparable sets, make sure that
the coding of lessThan, equals, and the hashcode functions are
consistent.
 See Also:
 SetList

ComparableSet()
 Construct a set with no elements.

add(Object)
 Add an element to the set.

clear()
 Remove all the elements of the set.

clone()
 Return a duplicate of the set.

contains(Object)
 Determine if a set contains a value.

difference(Set)
 Compute the difference between this set and other.

elements()
 Construct an iterator to traverse the elements of the set.

intersection(Set)
 Compute the intersection of this set and other.

isEmpty()
 Identify if the set is empty.

remove(Object)
 Remove an element from a set.

size()
 Returns the number of elements within the set.

subset(Set)
 Determine if this set is a subset of another.

toString()
 Generate a string representation of the set.

union(Set)
 Compute the union of this set and another.
ComparableSet
public ComparableSet()
 Construct a set with no elements.
 Postcondition:
 constructs a new, empty set
clear
public void clear()
 Remove all the elements of the set.
 Postcondition:
 elements of set are removed
isEmpty
public boolean isEmpty()
 Identify if the set is empty.
 Postcondition:
 returns true iff set is empty
 Returns:
 True iff there are no elements in the set.
add
public void add(Object e)
 Add an element to the set.
 Precondition:
 e is nonnull object
 Postcondition:
 adds element e to set
 Parameters:
 e  is a nonnull object.
remove
public Object remove(Object e)
 Remove an element from a set.
 Precondition:
 e is nonnull object
 Postcondition:
 e is removed from set, value returned
 Parameters:
 e  The value to be removed.
 Returns:
 The actual value removed.
contains
public boolean contains(Object e)
 Determine if a set contains a value.
 Precondition:
 e is nonnull
 Postcondition:
 returns true iff e is in set
 Parameters:
 e  The value sought.
 Returns:
 True iff the sought value is within the set.
subset
public boolean subset(Set other)
 Determine if this set is a subset of another.
 Precondition:
 other is nonnull reference to set
 Postcondition:
 returns true iff this set is subset of other
 Parameters:
 other  Another comparable set.
 Returns:
 True iff every element of this set is in the other.
clone
public Object clone()
 Return a duplicate of the set.
This is a shallow clone; elements are not cloned, themselves.
 Postcondition:
 returns a copy of set
 Returns:
 A copy of this set.
 Overrides:
 clone in class Object
union
public Object union(Set other)
 Compute the union of this set and another.
A value is in the result if it is in either of this or other.
This set is not modified by the action.
 Precondition:
 other is nonnull reference to set
 Postcondition:
 returns union of this set and other.
 Parameters:
 other  The set to be unioned with this.
 Returns:
 The union of the two sets.
intersection
public Object intersection(Set other)
 Compute the intersection of this set and other.
Any value in result is a member of both this and other.
This set is not modified by the operation.
 Precondition:
 other is nonnull reference to set
 Postcondition:
 returns set intersection between this and other
 Parameters:
 other  The set to be intersected with this.
 Returns:
 The result of the intersection of this with other.
difference
public Object difference(Set other)
 Compute the difference between this set and other.
Any value in result is in this set, but not other.
Computation does not modify this set.
 Precondition:
 other is nonnull reference to set
 Postcondition:
 returns the elements in this but not other.
 Parameters:
 other  The values not to be included in result.
 Returns:
 The set of elements in this, but not other.
elements
public Iterator elements()
 Construct an iterator to traverse the elements of the set.
 Postcondition:
 returns iterator to traverse the elements of set
 Returns:
 An iterator to traverse the elements of the set.
size
public int size()
 Returns the number of elements within the set.
 Postcondition:
 returns number of elements in set
 Returns:
 The number of elements within the set.
toString
public String toString()
 Generate a string representation of the set.
 Postcondition:
 returns string representation of this set
 Returns:
 A string representing the set.
 Overrides:
 toString in class Object
All Packages Class Hierarchy This Package Previous Next Index