Oracle Fusion Middleware Java API Reference for Oracle ADF Mobile Client
11g Release 1 (11.1.1)

E17503-02

oracle.adfnmc.java.util
Class TreeSet

java.lang.Object
  extended by oracle.adfnmc.java.util.AbstractCollection
      extended by oracle.adfnmc.java.util.AbstractSet
          extended by oracle.adfnmc.java.util.TreeSet
All Implemented Interfaces:
Serializable, Cloneable, Iterable, Collection, Set, SortedSet

public class TreeSet
extends AbstractSet
implements SortedSet, Cloneable, Serializable

TreeSet is an implementation of SortedSet. All optional operations are supported, adding and removing. The elements can be any objects which are comparable to each other either using their natural order or a specified Comparator.

Since:
1.2

Constructor Summary
TreeSet()
          Constructs a new empty instance of TreeSet which uses natural ordering.
TreeSet(Collection collection)
          Constructs a new instance of TreeSet which uses natural ordering and containing the unique elements in the specified collection.
TreeSet(Comparator comparator)
          Constructs a new empty instance of TreeSet which uses the specified Comparator.
TreeSet(SortedSet set)
          Constructs a new instance of TreeSet containing the elements in the specified SortedSet and using the same Comparator.
 
Method Summary
 boolean add(java.lang.Object object)
          Adds the specified object to this TreeSet.
 boolean addAll(Collection collection)
          Adds the objects in the specified Collection to this TreeSet.
 void clear()
          Removes all elements from this TreeSet, leaving it empty.
 java.lang.Object clone()
          Answers a new TreeSet with the same elements, size and comparator as this TreeSet.
 Comparator comparator()
          Answers the Comparator used to compare elements in this TreeSet.
 boolean contains(java.lang.Object object)
          Searches this TreeSet for the specified object.
 java.lang.Object first()
          Answers the first element in this TreeSet.
 SortedSet headSet(java.lang.Object end)
          Answers a SortedSet of the specified portion of this TreeSet which contains elements less than the end element.
 boolean isEmpty()
          Answers if this TreeSet has no elements, a size of zero.
 Iterator iterator()
          Answers an Iterator on the elements of this TreeSet.
 java.lang.Object last()
          Answers the last element in this TreeSet.
 boolean remove(java.lang.Object object)
          Removes an occurrence of the specified object from this TreeSet.
 int size()
          Answers the number of elements in this TreeSet.
 SortedSet subSet(java.lang.Object start, java.lang.Object end)
          Answers a SortedSet of the specified portion of this TreeSet which contains elements greater or equal to the start element but less than the end element.
 SortedSet tailSet(java.lang.Object start)
          Answers a SortedSet of the specified portion of this TreeSet which contains elements greater or equal to the start element.
 
Methods inherited from class oracle.adfnmc.java.util.AbstractSet
equals, hashCode, removeAll
 
Methods inherited from class oracle.adfnmc.java.util.AbstractCollection
containsAll, retainAll, toArray, toArray, toString
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface oracle.adfnmc.java.util.Set
containsAll, equals, hashCode, removeAll, retainAll, toArray, toArray
 

Constructor Detail

TreeSet

public TreeSet()
Constructs a new empty instance of TreeSet which uses natural ordering.


TreeSet

public TreeSet(Collection collection)
Constructs a new instance of TreeSet which uses natural ordering and containing the unique elements in the specified collection.

Parameters:
collection - the collection of elements to add
Throws:
java.lang.ClassCastException - when an element in the Collection does not implement the Comparable interface, or the elements in the Collection cannot be compared

TreeSet

public TreeSet(Comparator comparator)
Constructs a new empty instance of TreeSet which uses the specified Comparator.

Parameters:
comparator - the Comparator

TreeSet

public TreeSet(SortedSet set)
Constructs a new instance of TreeSet containing the elements in the specified SortedSet and using the same Comparator.

Parameters:
set - the SortedSet of elements to add
Method Detail

add

public boolean add(java.lang.Object object)
Adds the specified object to this TreeSet.

Specified by:
add in interface Collection
Specified by:
add in interface Set
Overrides:
add in class AbstractCollection
Parameters:
object - the object to add
Returns:
true when this TreeSet did not already contain the object, false otherwise
Throws:
java.lang.ClassCastException - when the object cannot be compared with the elements in this TreeSet
java.lang.NullPointerException - when the object is null and the comparator cannot handle null

addAll

public boolean addAll(Collection collection)
Adds the objects in the specified Collection to this TreeSet.

Specified by:
addAll in interface Collection
Specified by:
addAll in interface Set
Overrides:
addAll in class AbstractCollection
Parameters:
collection - the Collection of objects
Returns:
true if this TreeSet is modified, false otherwise
Throws:
java.lang.ClassCastException - when an object in the Collection cannot be compared with the elements in this TreeSet
java.lang.NullPointerException - when an object in the Collection is null and the comparator cannot handle null

clear

public void clear()
Removes all elements from this TreeSet, leaving it empty.

Specified by:
clear in interface Collection
Specified by:
clear in interface Set
Overrides:
clear in class AbstractCollection
See Also:
isEmpty(), size()

clone

public java.lang.Object clone()
Answers a new TreeSet with the same elements, size and comparator as this TreeSet.

Returns:
a shallow copy of this TreeSet
See Also:
Cloneable

comparator

public Comparator comparator()
Answers the Comparator used to compare elements in this TreeSet.

Specified by:
comparator in interface SortedSet
Returns:
a Comparator or null if the natural ordering is used

contains

public boolean contains(java.lang.Object object)
Searches this TreeSet for the specified object.

Specified by:
contains in interface Collection
Specified by:
contains in interface Set
Overrides:
contains in class AbstractCollection
Parameters:
object - the object to search for
Returns:
true if object is an element of this TreeSet, false otherwise
Throws:
java.lang.ClassCastException - when the object cannot be compared with the elements in this TreeSet
java.lang.NullPointerException - when the object is null and the comparator cannot handle null

first

public java.lang.Object first()
Answers the first element in this TreeSet.

Specified by:
first in interface SortedSet
Returns:
the first element
Throws:
NoSuchElementException - when this TreeSet is empty

headSet

public SortedSet headSet(java.lang.Object end)
Answers a SortedSet of the specified portion of this TreeSet which contains elements less than the end element. The returned SortedSet is backed by this TreeSet so changes to one are reflected by the other.

Specified by:
headSet in interface SortedSet
Parameters:
end - the end element
Returns:
a subset where the elements are less than end
Throws:
java.lang.ClassCastException - when the end object cannot be compared with the elements in this TreeSet
java.lang.NullPointerException - when the end object is null and the comparator cannot handle null

isEmpty

public boolean isEmpty()
Answers if this TreeSet has no elements, a size of zero.

Specified by:
isEmpty in interface Collection
Specified by:
isEmpty in interface Set
Overrides:
isEmpty in class AbstractCollection
Returns:
true if this TreeSet has no elements, false otherwise
See Also:
size()

iterator

public Iterator iterator()
Answers an Iterator on the elements of this TreeSet.

Specified by:
iterator in interface Iterable
Specified by:
iterator in interface Collection
Specified by:
iterator in interface Set
Specified by:
iterator in class AbstractCollection
Returns:
an Iterator on the elements of this TreeSet
See Also:
Iterator

last

public java.lang.Object last()
Answers the last element in this TreeSet.

Specified by:
last in interface SortedSet
Returns:
the last element
Throws:
NoSuchElementException - when this TreeSet is empty

remove

public boolean remove(java.lang.Object object)
Removes an occurrence of the specified object from this TreeSet.

Specified by:
remove in interface Collection
Specified by:
remove in interface Set
Overrides:
remove in class AbstractCollection
Parameters:
object - the object to remove
Returns:
true if this TreeSet is modified, false otherwise
Throws:
java.lang.ClassCastException - when the object cannot be compared with the elements in this TreeSet
java.lang.NullPointerException - when the object is null and the comparator cannot handle null

size

public int size()
Answers the number of elements in this TreeSet.

Specified by:
size in interface Collection
Specified by:
size in interface Set
Specified by:
size in class AbstractCollection
Returns:
the number of elements in this TreeSet

subSet

public SortedSet subSet(java.lang.Object start,
                        java.lang.Object end)
Answers a SortedSet of the specified portion of this TreeSet which contains elements greater or equal to the start element but less than the end element. The returned SortedSet is backed by this TreeSet so changes to one are reflected by the other.

Specified by:
subSet in interface SortedSet
Parameters:
start - the start element
end - the end element
Returns:
a subset where the elements are greater or equal to start and less than end
Throws:
java.lang.ClassCastException - when the start or end object cannot be compared with the elements in this TreeSet
java.lang.NullPointerException - when the start or end object is null and the comparator cannot handle null

tailSet

public SortedSet tailSet(java.lang.Object start)
Answers a SortedSet of the specified portion of this TreeSet which contains elements greater or equal to the start element. The returned SortedSet is backed by this TreeSet so changes to one are reflected by the other.

Specified by:
tailSet in interface SortedSet
Parameters:
start - the start element
Returns:
a subset where the elements are greater or equal to start
Throws:
java.lang.ClassCastException - when the start object cannot be compared with the elements in this TreeSet
java.lang.NullPointerException - when the start object is null and the comparator cannot handle null

Oracle Fusion Middleware Java API Reference for Oracle ADF Mobile Client
11g Release 1 (11.1.1)

E17503-02

Copyright © 2011, Oracle and/or its affiliates. All rights reserved.