|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
This class guarantees that the sorted set will be in ascending element order, sorted according to the natural order of the elements (see Comparable ), or by the comparator provided at set creation time, depending on which constructor is used.
This implementation provides guaranteed log(n) time cost for the basic operations (add ).
Note that the ordering maintained by a set (whether or not an explicit comparator is provided) must be consistent with equals if it is to correctly implement the Set interface. (See Comparable or Comparator for a precise definition of consistent with equals .) This is so because the Set interface is defined in terms of the equals operation, but a TreeSet instance performs all key comparisons using its compareTo (or compare ) method, so two keys that are deemed equal by this method are, from the standpoint of the set, equal. The behavior of a set is well-defined even if its ordering is inconsistent with equals; it just fails to obey the general contract of the Set interface.
Note that this implementation is not synchronized. If multiple threads access a set concurrently, and at least one of the threads modifies the set, it must be synchronized externally. This is typically accomplished by synchronizing on some object that naturally encapsulates the set.
Method Summary | |
void |
add(MeIterator iterator)
Adds all elements of the specified iterator to this set. |
void |
add(java.lang.Object object)
Adds the specified element to this set. |
MeComparator |
comparator()
Returns the comparator used to order this sorted set. |
MeIterator |
iterator()
Returns an iterator over the elements in this set. |
int |
size()
Returns the number of elements in this set (its cardinality). |
Method Detail |
public void add(java.lang.Object object)
object
- Description of the Parameter
java.lang.ClassCastException
- if the specified object cannot be compared
with the elements currently in the set.public int size()
public void add(MeIterator iterator)
iterator
- Description of the Parameter
java.lang.ClassCastException
- if the specified object cannot be compared
with the elements currently in the set.public MeIterator iterator()
public MeComparator comparator()
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |