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 comapreTo, equals, and the hashcode functions are consistent.

See Also:
SetList

Constructor Index

 o ComparableSet()
Construct a set with no elements.

Method Index

 o add(Object)
Add an element to the set.
 o clear()
Remove all the elements of the set.
 o clone()
Return a duplicate of the set.
 o contains(Object)
Determine if a set contains a value.
 o difference(Set)
Compute the difference between this set and other.
 o elements()
Construct an iterator to traverse the elements of the set.
 o intersection(Set)
Compute the intersection of this set and other.
 o isEmpty()
Identify if the set is empty.
 o remove(Object)
Remove an element from a set.
 o size()
Returns the number of elements within the set.
 o subset(Set)
Determine if this set is a subset of another.
 o toString()
Generate a string representation of the set.
 o union(Set)
Compute the union of this set and another.

Constructors

 o ComparableSet
public ComparableSet()
Construct a set with no elements.

Postcondition:
constructs a new, empty set

Methods

 o clear
public void clear()
Remove all the elements of the set.

Postcondition:
elements of set are removed

 o 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.
 o add
public void add(Object e)
Add an element to the set.

Precondition:
e is non-null object
Postcondition:
adds element e to set

Parameters:
e - is a non-null object.
 o remove
public Object remove(Object e)
Remove an element from a set.

Precondition:
e is non-null object
Postcondition:
e is removed from set, value returned

Parameters:
e - The value to be removed.
Returns:
The actual value removed.
 o contains
public boolean contains(Object e)
Determine if a set contains a value.

Precondition:
e is non-null
Postcondition:
returns true iff e is in set

Parameters:
e - The value sought.
Returns:
True iff the sought value is within the set.
 o subset
public boolean subset(Set other)
Determine if this set is a subset of another.

Precondition:
other is non-null 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.
 o 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
 o 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 non-null 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.
 o 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 non-null 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.
 o 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 non-null 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.
 o 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.
 o 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.
 o 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