edu.emory.mathcs.backport.java.util
Class TreeSet

java.lang.Object
  extended by java.util.AbstractCollection
      extended by java.util.AbstractSet
          extended by edu.emory.mathcs.backport.java.util.TreeSet
All Implemented Interfaces:
NavigableSet, java.io.Serializable, java.lang.Cloneable, java.lang.Iterable, java.util.Collection, java.util.Set, java.util.SortedSet

public class TreeSet
extends java.util.AbstractSet
implements NavigableSet, java.lang.Cloneable, java.io.Serializable

See Also:
Serialized Form

Constructor Summary
TreeSet()
           
TreeSet(java.util.Collection c)
           
TreeSet(java.util.Comparator comparator)
           
TreeSet(java.util.SortedSet s)
           
 
Method Summary
 boolean add(java.lang.Object o)
           
 boolean addAll(java.util.Collection c)
           
 java.lang.Object ceiling(java.lang.Object e)
          Returns the least element in this set greater than or equal to the given element, or null if there is no such element.
 void clear()
           
 java.lang.Object clone()
           
 java.util.Comparator comparator()
           
 boolean contains(java.lang.Object o)
           
 java.util.Iterator descendingIterator()
          Returns an iterator over the elements in this set, in descending order.
 NavigableSet descendingSet()
          Returns a reverse order view of the elements contained in this set.
 java.lang.Object first()
           
 java.lang.Object floor(java.lang.Object e)
          Returns the greatest element in this set less than or equal to the given element, or null if there is no such element.
 java.util.SortedSet headSet(java.lang.Object toElement)
          
 NavigableSet headSet(java.lang.Object toElement, boolean toInclusive)
          Returns a view of the portion of this set whose elements are less than (or equal to, if inclusive is true) toElement.
 java.lang.Object higher(java.lang.Object e)
          Returns the least element in this set strictly greater than the given element, or null if there is no such element.
 boolean isEmpty()
           
 java.util.Iterator iterator()
          Returns an iterator over the elements in this set, in ascending order.
 java.lang.Object last()
           
 java.lang.Object lower(java.lang.Object e)
          Returns the greatest element in this set strictly less than the given element, or null if there is no such element.
 java.lang.Object pollFirst()
          Retrieves and removes the first (lowest) element, or returns null if this set is empty.
 java.lang.Object pollLast()
          Retrieves and removes the last (highest) element, or returns null if this set is empty.
 boolean remove(java.lang.Object o)
           
 int size()
           
 NavigableSet subSet(java.lang.Object fromElement, boolean fromInclusive, java.lang.Object toElement, boolean toInclusive)
          Returns a view of the portion of this set whose elements range from fromElement to toElement.
 java.util.SortedSet subSet(java.lang.Object fromElement, java.lang.Object toElement)
          
 java.util.SortedSet tailSet(java.lang.Object fromElement)
          
 NavigableSet tailSet(java.lang.Object fromElement, boolean fromInclusive)
          Returns a view of the portion of this set whose elements are greater than (or equal to, if inclusive is true) fromElement.
 java.lang.Object[] toArray()
           
 java.lang.Object[] toArray(java.lang.Object[] a)
           
 
Methods inherited from class java.util.AbstractSet
equals, hashCode, removeAll
 
Methods inherited from class java.util.AbstractCollection
containsAll, retainAll, 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
 

Constructor Detail

TreeSet

public TreeSet()

TreeSet

public TreeSet(java.util.Comparator comparator)

TreeSet

public TreeSet(java.util.Collection c)

TreeSet

public TreeSet(java.util.SortedSet s)
Method Detail

lower

public java.lang.Object lower(java.lang.Object e)
Description copied from interface: NavigableSet
Returns the greatest element in this set strictly less than the given element, or null if there is no such element.

Specified by:
lower in interface NavigableSet
Parameters:
e - the value to match
Returns:
the greatest element less than e, or null if there is no such element

floor

public java.lang.Object floor(java.lang.Object e)
Description copied from interface: NavigableSet
Returns the greatest element in this set less than or equal to the given element, or null if there is no such element.

Specified by:
floor in interface NavigableSet
Parameters:
e - the value to match
Returns:
the greatest element less than or equal to e, or null if there is no such element

ceiling

public java.lang.Object ceiling(java.lang.Object e)
Description copied from interface: NavigableSet
Returns the least element in this set greater than or equal to the given element, or null if there is no such element.

Specified by:
ceiling in interface NavigableSet
Parameters:
e - the value to match
Returns:
the least element greater than or equal to e, or null if there is no such element

higher

public java.lang.Object higher(java.lang.Object e)
Description copied from interface: NavigableSet
Returns the least element in this set strictly greater than the given element, or null if there is no such element.

Specified by:
higher in interface NavigableSet
Parameters:
e - the value to match
Returns:
the least element greater than e, or null if there is no such element

pollFirst

public java.lang.Object pollFirst()
Description copied from interface: NavigableSet
Retrieves and removes the first (lowest) element, or returns null if this set is empty.

Specified by:
pollFirst in interface NavigableSet
Returns:
the first element, or null if this set is empty

pollLast

public java.lang.Object pollLast()
Description copied from interface: NavigableSet
Retrieves and removes the last (highest) element, or returns null if this set is empty.

Specified by:
pollLast in interface NavigableSet
Returns:
the last element, or null if this set is empty

iterator

public java.util.Iterator iterator()
Description copied from interface: NavigableSet
Returns an iterator over the elements in this set, in ascending order.

Specified by:
iterator in interface NavigableSet
Specified by:
iterator in interface java.lang.Iterable
Specified by:
iterator in interface java.util.Collection
Specified by:
iterator in interface java.util.Set
Specified by:
iterator in class java.util.AbstractCollection
Returns:
an iterator over the elements in this set, in ascending order

descendingIterator

public java.util.Iterator descendingIterator()
Description copied from interface: NavigableSet
Returns an iterator over the elements in this set, in descending order. Equivalent in effect to descendingSet().iterator().

Specified by:
descendingIterator in interface NavigableSet
Returns:
an iterator over the elements in this set, in descending order

subSet

public java.util.SortedSet subSet(java.lang.Object fromElement,
                                  java.lang.Object toElement)
Description copied from interface: NavigableSet

Equivalent to subSet(fromElement, true, toElement, false).

Specified by:
subSet in interface NavigableSet
Specified by:
subSet in interface java.util.SortedSet

headSet

public java.util.SortedSet headSet(java.lang.Object toElement)
Description copied from interface: NavigableSet

Equivalent to headSet(toElement, false).

Specified by:
headSet in interface NavigableSet
Specified by:
headSet in interface java.util.SortedSet

tailSet

public java.util.SortedSet tailSet(java.lang.Object fromElement)
Description copied from interface: NavigableSet

Equivalent to tailSet(fromElement, true).

Specified by:
tailSet in interface NavigableSet
Specified by:
tailSet in interface java.util.SortedSet

subSet

public NavigableSet subSet(java.lang.Object fromElement,
                           boolean fromInclusive,
                           java.lang.Object toElement,
                           boolean toInclusive)
Description copied from interface: NavigableSet
Returns a view of the portion of this set whose elements range from fromElement to toElement. If fromElement and toElement are equal, the returned set is empty unless fromExclusive and toExclusive are both true. The returned set is backed by this set, so changes in the returned set are reflected in this set, and vice-versa. The returned set supports all optional set operations that this set supports.

The returned set will throw an IllegalArgumentException on an attempt to insert an element outside its range.

Specified by:
subSet in interface NavigableSet
Parameters:
fromElement - low endpoint of the returned set
fromInclusive - true if the low endpoint is to be included in the returned view
toElement - high endpoint of the returned set
toInclusive - true if the high endpoint is to be included in the returned view
Returns:
a view of the portion of this set whose elements range from fromElement, inclusive, to toElement, exclusive

headSet

public NavigableSet headSet(java.lang.Object toElement,
                            boolean toInclusive)
Description copied from interface: NavigableSet
Returns a view of the portion of this set whose elements are less than (or equal to, if inclusive is true) toElement. The returned set is backed by this set, so changes in the returned set are reflected in this set, and vice-versa. The returned set supports all optional set operations that this set supports.

The returned set will throw an IllegalArgumentException on an attempt to insert an element outside its range.

Specified by:
headSet in interface NavigableSet
Parameters:
toElement - high endpoint of the returned set
toInclusive - true if the high endpoint is to be included in the returned view
Returns:
a view of the portion of this set whose elements are less than (or equal to, if inclusive is true) toElement

tailSet

public NavigableSet tailSet(java.lang.Object fromElement,
                            boolean fromInclusive)
Description copied from interface: NavigableSet
Returns a view of the portion of this set whose elements are greater than (or equal to, if inclusive is true) fromElement. The returned set is backed by this set, so changes in the returned set are reflected in this set, and vice-versa. The returned set supports all optional set operations that this set supports.

The returned set will throw an IllegalArgumentException on an attempt to insert an element outside its range.

Specified by:
tailSet in interface NavigableSet
Parameters:
fromElement - low endpoint of the returned set
fromInclusive - true if the low endpoint is to be included in the returned view
Returns:
a view of the portion of this set whose elements are greater than or equal to fromElement

descendingSet

public NavigableSet descendingSet()
Description copied from interface: NavigableSet
Returns a reverse order view of the elements contained in this set. The descending set is backed by this set, so changes to the set are reflected in the descending set, and vice-versa. If either set is modified while an iteration over either set is in progress (except through the iterator's own remove operation), the results of the iteration are undefined.

The returned set has an ordering equivalent to Collections.reverseOrder(comparator()). The expression s.descendingSet().descendingSet() returns a view of s essentially equivalent to s.

Specified by:
descendingSet in interface NavigableSet
Returns:
a reverse order view of this set

comparator

public java.util.Comparator comparator()
Specified by:
comparator in interface java.util.SortedSet

first

public java.lang.Object first()
Specified by:
first in interface java.util.SortedSet

last

public java.lang.Object last()
Specified by:
last in interface java.util.SortedSet

size

public int size()
Specified by:
size in interface java.util.Collection
Specified by:
size in interface java.util.Set
Specified by:
size in class java.util.AbstractCollection

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface java.util.Collection
Specified by:
isEmpty in interface java.util.Set
Overrides:
isEmpty in class java.util.AbstractCollection

contains

public boolean contains(java.lang.Object o)
Specified by:
contains in interface java.util.Collection
Specified by:
contains in interface java.util.Set
Overrides:
contains in class java.util.AbstractCollection

toArray

public java.lang.Object[] toArray()
Specified by:
toArray in interface java.util.Collection
Specified by:
toArray in interface java.util.Set
Overrides:
toArray in class java.util.AbstractCollection

toArray

public java.lang.Object[] toArray(java.lang.Object[] a)
Specified by:
toArray in interface java.util.Collection
Specified by:
toArray in interface java.util.Set
Overrides:
toArray in class java.util.AbstractCollection

add

public boolean add(java.lang.Object o)
Specified by:
add in interface java.util.Collection
Specified by:
add in interface java.util.Set
Overrides:
add in class java.util.AbstractCollection

remove

public boolean remove(java.lang.Object o)
Specified by:
remove in interface java.util.Collection
Specified by:
remove in interface java.util.Set
Overrides:
remove in class java.util.AbstractCollection

addAll

public boolean addAll(java.util.Collection c)
Specified by:
addAll in interface java.util.Collection
Specified by:
addAll in interface java.util.Set
Overrides:
addAll in class java.util.AbstractCollection

clear

public void clear()
Specified by:
clear in interface java.util.Collection
Specified by:
clear in interface java.util.Set
Overrides:
clear in class java.util.AbstractCollection

clone

public java.lang.Object clone()
Overrides:
clone in class java.lang.Object