fi.joensuu.cs.tra
Class Set<E>

java.lang.Object
  extended by java.util.AbstractCollection
      extended by java.util.AbstractSet
          extended by java.util.TreeSet
              extended by fi.joensuu.cs.tra.Set
All Implemented Interfaces:
Cloneable, Collection, Iterable, Serializable, Set, SortedSet

public class Set<E>
extends TreeSet<E>

fi.joensuu.cs.tra.Set extends java.util.TreeSet with comparison methods.

See Also:
TreeSet, TreeMap, Serialized Form

Constructor Summary
Set()
          Constructs a new, empty set, sorted according to the elements' natural order.
Set(Collection<? extends E> c)
          Constructs a new set containing the elements in the specified collection, sorted according to the elements' natural order.
Set(Comparator<? super E> c)
          Constructs a new, empty set, sorted according to the specified comparator.
Set(SortedSet<E> s)
          Constructs a new set containing the same elements as the specified sorted set, sorted according to the same ordering.
 
Method Summary
 boolean add(E o)
          Adds the specified element to this set if it is not already present.
 boolean addAll(Collection<? extends E> c)
          Adds all of the elements in the specified collection to this set.
 void clear()
          Removes all of the elements from this set.
 Object clone()
          Returns a shallow copy of this TreeSet instance.
 Comparator<? super E> comparator()
          Returns the comparator used to order this sorted set, or null if this tree set uses its elements natural ordering.
 boolean contains(Object o)
          Returns true if this set contains the specified element.
 Set<E> difference(Collection<? extends E> c)
          Returns the difference of this Set and the specified Collection.
 boolean equals(Collection<? extends E> c)
          Checks if this Set and the specified Collection contain the same elements.
 E first()
          Returns the first (lowest) element currently in this sorted set.
 SortedSet<E> headSet(E toElement)
          Returns a view of the portion of this set whose elements are strictly less than toElement.
 Set<E> intersection(Collection<? extends E> c)
          Returns the intersection of this Set and the specified Collection.
 boolean isEmpty()
          Returns true if this set contains no elements.
 Iterator<E> iterator()
          Returns an iterator over the elements in this set.
 E last()
          Returns the last (highest) element currently in this sorted set.
 boolean remove(Object o)
          Removes the specified element from this set if it is present.
 int size()
          Returns the number of elements in this set (its cardinality).
 SortedSet<E> subSet(E fromElement, E toElement)
          Returns a view of the portion of this set whose elements range from fromElement, inclusive, to toElement, exclusive.
 SortedSet<E> tailSet(E fromElement)
          Returns a view of the portion of this set whose elements are greater than or equal to fromElement.
 Set<E> union(Collection<? extends E> c)
          Returns the union of this Set and the specified Collection.
 
Methods inherited from class java.util.AbstractSet
equals, hashCode, removeAll
 
Methods inherited from class java.util.AbstractCollection
containsAll, retainAll, toArray, toArray, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Set
containsAll, equals, hashCode, removeAll, retainAll, toArray, toArray
 

Constructor Detail

Set

public Set()
Constructs a new, empty set, sorted according to the elements' natural order.


Set

public Set(Collection<? extends E> c)
Constructs a new set containing the elements in the specified collection, sorted according to the elements' natural order.


Set

public Set(Comparator<? super E> c)
Constructs a new, empty set, sorted according to the specified comparator.


Set

public Set(SortedSet<E> s)
Constructs a new set containing the same elements as the specified sorted set, sorted according to the same ordering.

Method Detail

add

public boolean add(E o)
Description copied from class: java.util.TreeSet
Adds the specified element to this set if it is not already present.

Specified by:
add in interface Set
Overrides:
add in class TreeSet
Parameters:
o - element to be added to this set.
Returns:
true if the set did not already contain the specified element.

addAll

public boolean addAll(Collection<? extends E> c)
Description copied from class: java.util.TreeSet
Adds all of the elements in the specified collection to this set.

Specified by:
addAll in interface Set
Overrides:
addAll in class TreeSet
Parameters:
c - elements to be added
Returns:
true if this set changed as a result of the call.
See Also:
AbstractCollection.add(Object)

clear

public void clear()
Description copied from class: java.util.TreeSet
Removes all of the elements from this set.

Specified by:
clear in interface Set
Overrides:
clear in class TreeSet

clone

public Object clone()
Description copied from class: java.util.TreeSet
Returns a shallow copy of this TreeSet instance. (The elements themselves are not cloned.)

Overrides:
clone in class TreeSet
Returns:
a shallow copy of this set.
See Also:
Cloneable

comparator

public Comparator<? super E> comparator()
Description copied from class: java.util.TreeSet
Returns the comparator used to order this sorted set, or null if this tree set uses its elements natural ordering.

Specified by:
comparator in interface SortedSet
Overrides:
comparator in class TreeSet
Returns:
the comparator used to order this sorted set, or null if this tree set uses its elements natural ordering.

contains

public boolean contains(Object o)
Description copied from class: java.util.TreeSet
Returns true if this set contains the specified element.

Specified by:
contains in interface Set
Overrides:
contains in class TreeSet
Parameters:
o - the object to be checked for containment in this set.
Returns:
true if this set contains the specified element.

first

public E first()
Description copied from class: java.util.TreeSet
Returns the first (lowest) element currently in this sorted set.

Specified by:
first in interface SortedSet
Overrides:
first in class TreeSet
Returns:
the first (lowest) element currently in this sorted set.

headSet

public SortedSet<E> headSet(E toElement)
Description copied from class: java.util.TreeSet
Returns a view of the portion of this set whose elements are strictly less than toElement. The returned sorted set is backed by this set, so changes in the returned sorted set are reflected in this set, and vice-versa. The returned sorted set supports all optional set operations.

The sorted set returned by this method will throw an IllegalArgumentException if the user attempts to insert an element greater than or equal to toElement.

Note: this method always returns a view that does not contain its (high) endpoint. If you need a view that does contain this endpoint, and the element type allows for calculation of the successor of a specified value, merely request a headSet bounded by successor(highEndpoint). For example, suppose that s is a sorted set of strings. The following idiom obtains a view containing all of the strings in s that are less than or equal to high:

 SortedSet head = s.headSet(high+"\0");

Specified by:
headSet in interface SortedSet
Overrides:
headSet in class TreeSet
Parameters:
toElement - high endpoint (exclusive) of the headSet.
Returns:
a view of the portion of this set whose elements are strictly less than toElement.

isEmpty

public boolean isEmpty()
Description copied from class: java.util.TreeSet
Returns true if this set contains no elements.

Specified by:
isEmpty in interface Set
Overrides:
isEmpty in class TreeSet
Returns:
true if this set contains no elements.

iterator

public Iterator<E> iterator()
Description copied from class: java.util.TreeSet
Returns an iterator over the elements in this set. The elements are returned in ascending order.

Specified by:
iterator in interface Set
Overrides:
iterator in class TreeSet
Returns:
an iterator over the elements in this set.

last

public E last()
Description copied from class: java.util.TreeSet
Returns the last (highest) element currently in this sorted set.

Specified by:
last in interface SortedSet
Overrides:
last in class TreeSet
Returns:
the last (highest) element currently in this sorted set.

remove

public boolean remove(Object o)
Description copied from class: java.util.TreeSet
Removes the specified element from this set if it is present.

Specified by:
remove in interface Set
Overrides:
remove in class TreeSet
Parameters:
o - object to be removed from this set, if present.
Returns:
true if the set contained the specified element.

size

public int size()
Description copied from class: java.util.TreeSet
Returns the number of elements in this set (its cardinality).

Specified by:
size in interface Set
Overrides:
size in class TreeSet
Returns:
the number of elements in this set (its cardinality).

subSet

public SortedSet<E> subSet(E fromElement,
                           E toElement)
Description copied from class: java.util.TreeSet
Returns a view of the portion of this set whose elements range from fromElement, inclusive, to toElement, exclusive. (If fromElement and toElement are equal, the returned sorted set is empty.) The returned sorted set is backed by this set, so changes in the returned sorted set are reflected in this set, and vice-versa. The returned sorted set supports all optional Set operations.

The sorted set returned by this method will throw an IllegalArgumentException if the user attempts to insert an element outside the specified range.

Note: this method always returns a half-open range (which includes its low endpoint but not its high endpoint). If you need a closed range (which includes both endpoints), and the element type allows for calculation of the successor of a specified value, merely request the subrange from lowEndpoint to successor(highEndpoint). For example, suppose that s is a sorted set of strings. The following idiom obtains a view containing all of the strings in s from low to high, inclusive:

     SortedSet sub = s.subSet(low, high+"\0");
 
A similar technique can be used to generate an open range (which contains neither endpoint). The following idiom obtains a view containing all of the strings in s from low to high, exclusive:
     SortedSet sub = s.subSet(low+"\0", high);
 

Specified by:
subSet in interface SortedSet
Overrides:
subSet in class TreeSet
Parameters:
fromElement - low endpoint (inclusive) of the subSet.
toElement - high endpoint (exclusive) of the subSet.
Returns:
a view of the portion of this set whose elements range from fromElement, inclusive, to toElement, exclusive.

tailSet

public SortedSet<E> tailSet(E fromElement)
Description copied from class: java.util.TreeSet
Returns a view of the portion of this set whose elements are greater than or equal to fromElement. The returned sorted set is backed by this set, so changes in the returned sorted set are reflected in this set, and vice-versa. The returned sorted set supports all optional set operations.

The sorted set returned by this method will throw an IllegalArgumentException if the user attempts to insert an element less than fromElement. Note: this method always returns a view that contains its (low) endpoint. If you need a view that does not contain this endpoint, and the element type allows for calculation of the successor of a specified value, merely request a tailSet bounded by successor(lowEndpoint). For example, suppose that s is a sorted set of strings. The following idiom obtains a view containing all of the strings in s that are strictly greater than low:

     SortedSet tail = s.tailSet(low+"\0");
 

Specified by:
tailSet in interface SortedSet
Overrides:
tailSet in class TreeSet
Parameters:
fromElement - low endpoint (inclusive) of the tailSet.
Returns:
a view of the portion of this set whose elements are greater than or equal to fromElement.

union

public Set<E> union(Collection<? extends E> c)
Returns the union of this Set and the specified Collection.

Parameters:
c - the Collection to combine this Set with.
Returns:
a new Set containing the elements of both this Set and the specified Collection.

intersection

public Set<E> intersection(Collection<? extends E> c)
Returns the intersection of this Set and the specified Collection.

Parameters:
c - the Collection to intersect this Set with.
Returns:
a new Set containing the elements present in both this Set and the specified Collection.

difference

public Set<E> difference(Collection<? extends E> c)
Returns the difference of this Set and the specified Collection.

Parameters:
c - the Collection to subtract from this Set.
Returns:
a new Set containing the elements present in this Set but not in the specified Collection.

equals

public boolean equals(Collection<? extends E> c)
Checks if this Set and the specified Collection contain the same elements.

Parameters:
c - the Collection to compare this Set with.
Returns:
true if the specified collection contains the same elements as this Set, false otherwise.