java.util

Class TreeSet<E>

Implemented Interfaces:
Cloneable, Collection<E>, Iterable<T>, Serializable, Set<E>, SortedSet<E>

public class TreeSet<E>
extends AbstractSet<E>
implements SortedSet<E>, Cloneable, Serializable

This class implements the Set interface, backed by a TreeMap instance. 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, remove and contains).

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. If no such object exists, the set should be "wrapped" using the Collections.synchronizedSet method. This is best done at creation time, to prevent accidental unsynchronized access to the set:

     SortedSet s = Collections.synchronizedSortedSet(new TreeSet(...));
 

The Iterators returned by this class's iterator method are fail-fast: if the set is modified at any time after the iterator is created, in any way except through the iterator's own remove method, the iterator will throw a ConcurrentModificationException. Thus, in the face of concurrent modification, the iterator fails quickly and cleanly, rather than risking arbitrary, non-deterministic behavior at an undetermined time in the future.

Note that the fail-fast behavior of an iterator cannot be guaranteed as it is, generally speaking, impossible to make any hard guarantees in the presence of unsynchronized concurrent modification. Fail-fast iterators throw ConcurrentModificationException on a best-effort basis. Therefore, it would be wrong to write a program that depended on this exception for its correctness: the fail-fast behavior of iterators should be used only to detect bugs.

This class is a member of the ../../../guide/collections/index.html"> Java Collections Framework.

Since:
1.2
See Also:
Collection, Set, HashSet, Comparable, Comparator, Collections.synchronizedSortedSet(SortedSet), TreeMap, Serialized Form

Constructor Summary

TreeSet()
Constructs a new, empty set, sorted according to the elements' natural order.
TreeSet(E> c)
Constructs a new, empty set, sorted according to the specified comparator.
TreeSet(E> c)
Constructs a new set containing the elements in the specified collection, sorted according to the elements' natural order.
TreeSet(SortedSet 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(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.
boolean
contains(Object o)
Returns true if this set contains the specified element.
E
first()
Returns the first (lowest) element currently in this sorted set.
SortedSet
headSet(E toElement)
Returns a view of the portion of this set whose elements are strictly less than toElement.
boolean
isEmpty()
Returns true if this set contains no elements.
Iterator
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
subSet(E fromElement, E toElement)
Returns a view of the portion of this set whose elements range from fromElement, inclusive, to toElement, exclusive.
Comparator
super E> comparator()
Returns the comparator used to order this sorted set, or null if this tree set uses its elements natural ordering.
SortedSet
tailSet(E fromElement)
Returns a view of the portion of this set whose elements are greater than or equal to fromElement.

Methods inherited from class java.util.AbstractSet<E>

equals, hashCode, removeAll

Methods inherited from class java.util.AbstractCollection<E>

T[] toArray, add, addAll, clear, contains, containsAll, isEmpty, iterator, remove, removeAll, retainAll, size, toArray, toString

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Details

TreeSet

public TreeSet()
Constructs a new, empty set, sorted according to the elements' natural order. All elements inserted into the set must implement the Comparable interface. Furthermore, all such elements must be mutually comparable: e1.compareTo(e2) must not throw a ClassCastException for any elements e1 and e2 in the set. If the user attempts to add an element to the set that violates this constraint (for example, the user attempts to add a string element to a set whose elements are integers), the add(Object) call will throw a ClassCastException.
See Also:
Comparable
Usages and Demos :

View More Examples of TreeSet()
   1:     testVisual(new HashSet());
   2:     testVisual(new TreeSet());
   3:   }

View Full Code Here
   1:     fill(a);
   2:     a.addAll(fill(new TreeSet()));
   3:     System.out.println(a);
   4:         ...
   5:     test(new HashSet());
   6:     test(new TreeSet());
   7:   }

View Full Code Here
   1:     System.out.println("TreeSet");
   2:     vizualniTest(new TreeSet());
   3:   }

View Full Code Here
   1:     fill(a, 10);
   2:     a.addAll(fill(new TreeSet(), 10));
   3:     System.out.println(a);
   4:         ...
   5:     test(new HashSet());
   6:     test(new TreeSet());
   7:   }

View Full Code Here
   1:     LazySortedSet(Broker broker, String statementID, ConnectionContext context) {
   2:         super(broker, statementID, context, new TreeSet());
   3:     }
   4: 
   5:     private SortedSet getSortedSet() {

View Full Code Here

TreeSet

public TreeSet(E> c)
Constructs a new, empty set, sorted according to the specified comparator. All elements inserted into the set must be mutually comparable by the specified comparator: comparator.compare(e1, e2) must not throw a ClassCastException for any elements e1 and e2 in the set. If the user attempts to add an element to the set that violates this constraint, the add(Object) call will throw a ClassCastException.
Parameters:
c - the comparator that will be used to sort this set. A null value indicates that the elements' natural ordering should be used.
Usages and Demos :

View More Examples of TreeSet(E> c)
   1:         Color colour = NeighbourhoodList.postponedInconsistentNeighbourhoods(
   2:                 session).contains(new TreeSet((Set) neighbourhood)) ? getPostponedInconsistentColour(viewport)
   3:                 : getInconsistentColour(viewport);
   4:         RoadStyleUtil.instance().paintNeighbourhood(null, (Set) neighbourhood,
   5:                 colour, g, viewport);

View Full Code Here
   1:         if (replies == null) {
   2:             replies = Collections.synchronizedSet(new TreeSet(BlogURIComparator.HIGHEST_ID_FIRST));
   3:             _replies.put(parent, replies);
   4:         }
   5:         replies.add(reply);

View Full Code Here
   1:                     if(v instanceof SortedSet)
   2:                         toSave.put(k, new TreeSet((SortedSet)v));
   3:                     else if(v instanceof Set)
   4:                         toSave.put(k, new HashSet((Set)v));
   5:                     else if(v instanceof Map)

View Full Code Here
   1:                         roadSegment.getNetwork().getSession()).contains(
   2:                         new TreeSet((Collection) value))) {
   3:                     continue;
   4:                 };
   5:                 return (Collection) value;

View Full Code Here
   1:   protected int compareToSameClass(Object o){
   2:     TreeSet theseElements = new TreeSet(geometry_.getList());
   3:         ...
   4:     TreeSet otherElements = new TreeSet(((GISCollection) o).geometry_.getList());
   5:     return compare(theseElements, otherElements);
   6:   }

View Full Code Here

TreeSet

public TreeSet(E> c)
Constructs a new set containing the elements in the specified collection, sorted according to the elements' natural order. All keys inserted into the set must implement the Comparable interface. Furthermore, all such keys must be mutually comparable: k1.compareTo(k2) must not throw a ClassCastException for any elements k1 and k2 in the set.
Parameters:
c - The elements that will comprise the new set.
Throws:
ClassCastException - if the keys in the specified collection are not comparable, or are not mutually comparable.
NullPointerException - if the specified collection is null.
Usages and Demos :

View More Examples of TreeSet(E> c)
   1:         Color colour = NeighbourhoodList.postponedInconsistentNeighbourhoods(
   2:                 session).contains(new TreeSet((Set) neighbourhood)) ? getPostponedInconsistentColour(viewport)
   3:                 : getInconsistentColour(viewport);
   4:         RoadStyleUtil.instance().paintNeighbourhood(null, (Set) neighbourhood,
   5:                 colour, g, viewport);

View Full Code Here
   1:         if (replies == null) {
   2:             replies = Collections.synchronizedSet(new TreeSet(BlogURIComparator.HIGHEST_ID_FIRST));
   3:             _replies.put(parent, replies);
   4:         }
   5:         replies.add(reply);

View Full Code Here
   1:                     if(v instanceof SortedSet)
   2:                         toSave.put(k, new TreeSet((SortedSet)v));
   3:                     else if(v instanceof Set)
   4:                         toSave.put(k, new HashSet((Set)v));
   5:                     else if(v instanceof Map)

View Full Code Here
   1:                         roadSegment.getNetwork().getSession()).contains(
   2:                         new TreeSet((Collection) value))) {
   3:                     continue;
   4:                 };
   5:                 return (Collection) value;

View Full Code Here
   1:   protected int compareToSameClass(Object o){
   2:     TreeSet theseElements = new TreeSet(geometry_.getList());
   3:         ...
   4:     TreeSet otherElements = new TreeSet(((GISCollection) o).geometry_.getList());
   5:     return compare(theseElements, otherElements);
   6:   }

View Full Code Here

TreeSet

public TreeSet(SortedSet s)
Constructs a new set containing the same elements as the specified sorted set, sorted according to the same ordering.
Parameters:
s - sorted set whose elements will comprise the new set.
Throws:
NullPointerException - if the specified sorted set is null.
Usages and Demos :

View More Examples of TreeSet(SortedSet s)
   1:         Color colour = NeighbourhoodList.postponedInconsistentNeighbourhoods(
   2:                 session).contains(new TreeSet((Set) neighbourhood)) ? getPostponedInconsistentColour(viewport)
   3:                 : getInconsistentColour(viewport);
   4:         RoadStyleUtil.instance().paintNeighbourhood(null, (Set) neighbourhood,
   5:                 colour, g, viewport);

View Full Code Here
   1:         if (replies == null) {
   2:             replies = Collections.synchronizedSet(new TreeSet(BlogURIComparator.HIGHEST_ID_FIRST));
   3:             _replies.put(parent, replies);
   4:         }
   5:         replies.add(reply);

View Full Code Here
   1:                     if(v instanceof SortedSet)
   2:                         toSave.put(k, new TreeSet((SortedSet)v));
   3:                     else if(v instanceof Set)
   4:                         toSave.put(k, new HashSet((Set)v));
   5:                     else if(v instanceof Map)

View Full Code Here
   1:                         roadSegment.getNetwork().getSession()).contains(
   2:                         new TreeSet((Collection) value))) {
   3:                     continue;
   4:                 };
   5:                 return (Collection) value;

View Full Code Here
   1:   protected int compareToSameClass(Object o){
   2:     TreeSet theseElements = new TreeSet(geometry_.getList());
   3:         ...
   4:     TreeSet otherElements = new TreeSet(((GISCollection) o).geometry_.getList());
   5:     return compare(theseElements, otherElements);
   6:   }

View Full Code Here

Method Details

add

public boolean add(E o)
Adds the specified element to this set if it is not already present.
Specified by:
add in interface Set<E>
add in interface Collection<E>
Overrides:
add in interface AbstractCollection<E>
Parameters:
o - element to be added to this set.
Returns:
true if the set did not already contain the specified element.
Throws:
ClassCastException - if the specified object cannot be compared with the elements currently in the set.
Usages and Demos :

View More Examples of add(E o)
   1:     public static void main(String[] argv) {
   2:         TreeSet tm = new TreeSet(String.CASE_INSENSITIVE_ORDER);
   3:         ...
   4:         tm.add("Gosling");
   5:         tm.add("da Vinci");
   6:         ...
   7:         tm.add("Java To Go");
   8:         tm.add("Vanguard");
   9:         ...
  10:         tm.add("Darwin");

View Full Code Here
   1: import java.util.Set;
   2: import java.util.TreeSet;
   3: 
   4:         ...
   5:         Layer layer1 = new Layer();
   6:         TreeSet set1 = new TreeSet();
   7:         ...
   8:         set1.add("EPSG:4326");
   9:         ...
  10:         set1.add("EPSG:3005");

View Full Code Here
   1: import java.util.List;
   2: import java.util.TreeSet;
   3: import javax.xml.namespace.QName;
   4:         ...
   5:   {
   6:     TreeSet acc = new TreeSet();
   7:         ...
   8:     acc.add("stylesheet");
   9:         ...
  10:     acc.add("template");

View Full Code Here
   1: import java.util.StringTokenizer;
   2: import java.util.TreeSet;
   3: 
   4:         ...
   5:     
   6:     private TreeSet fNLChoices;
   7:         ...
   8:     private TreeSet fOSChoices;
   9:     private TreeSet fWSChoices;
  10:         ...
  11:         for (int i = 0; i < os.length; i++)
  12:             fOSChoices.add(os[i]);

View Full Code Here

addAll

public boolean addAll(E> c)
Adds all of the elements in the specified collection to this set.
Specified by:
addAll in interface Set<E>
addAll in interface Collection<E>
Overrides:
addAll in interface AbstractCollection<E>
Parameters:
c - elements to be added
Returns:
true if this set changed as a result of the call.
Throws:
ClassCastException - if the elements provided cannot be compared with the elements currently in the set.
NullPointerException - of the specified collection is null.
Usages and Demos :

View More Examples of addAll(E> c)
   1:             Arrays.sort((byte[])obj);
   2:         } else if (obj instanceof TreeSet){
   3:             return obj;
   4:         ...
   5:         } else if (obj instanceof Set){
   6:             TreeSet ts = new TreeSet(comp);
   7:         ...
   8:             ts.addAll((Set)obj);
   9:             return ts;

View Full Code Here
   1: import java.util.Map;
   2: import java.util.TreeSet;
   3: 
   4:         ...
   5:     private boolean running = true;
   6:     private TreeSet sortedFilterItems;
   7: 
   8:         ...
   9:     public FilterCleaner() {
  10:       sortedFilterItems = new TreeSet(new Comparator() {
  11:         public int compare(Object a, Object b) {
  12:         ...
  13:           synchronized (cache) {
  14:             sortedFilterItems.addAll(cache.entrySet());

View Full Code Here
   1: import java.util.Set;
   2: import java.util.TreeSet;
   3: 
   4:         ...
   5:             return new HashSet(_attemptedPeers);
   6:         TreeSet closest = new TreeSet(new XORComparator(target));
   7:         ...
   8:         closest.addAll(_attemptedPeers);
   9:         HashSet rv = new HashSet(max);
  10:         ...
  11:         synchronized (_pendingPeers) {
  12:             _pendingPeers.addAll(pending);

View Full Code Here
   1: import java.util.Set;
   2: import java.util.TreeSet;
   3: 
   4:         ...
   5:     public Set resolve(Descriptor descriptor) throws InstallException {
   6:         TreeSet installs = new TreeSet(comparator);
   7: 
   8:         ...
   9:                 Set add = resolver.addResolveRoot(bid);
  10:                 installs.addAll(add);
  11:             }

View Full Code Here
   1: import java.util.TimeZone;
   2: import java.util.TreeSet;
   3: import java.util.Vector;
   4:         ...
   5:                                 comparator.setDay(thisDay);
   6:                                 TreeSet eventsThisDay = new TreeSet(comparator);
   7:         ...
   8:                                 eventsThisDay.addAll(calendar.findEventsForDay(thisDay));
   9:                                 events[week].put(new Integer(dayNumber), eventsThisDay);

View Full Code Here

clear

public void clear()
Removes all of the elements from this set.
Specified by:
clear in interface Set<E>
clear in interface Collection<E>
Overrides:
clear in interface AbstractCollection<E>
Usages and Demos :

View More Examples of clear()
   1: import java.util.Iterator;
   2: import java.util.TreeSet;
   3: 
   4:         ...
   5: 
   6:     private TreeSet resourceDescriptors;
   7:     
   8:         ...
   9:     public ResourceList() {
  10:         resourceDescriptors = new TreeSet();
  11:     }
  12:         ...
  13:     public void clear() {
  14:         resourceDescriptors.clear();

View Full Code Here
   1: import java.util.Iterator;
   2: import java.util.TreeSet;
   3: 
   4:         ...
   5: {
   6:     private TreeSet sortedHosts;
   7:     private HashMap addressHostMapping;
   8:         ...
   9:     {
  10:         sortedHosts = new TreeSet( new CaughtHostComparator() );
  11:         addressHostMapping = new HashMap();
  12:         ...
  13:     {
  14:         sortedHosts.clear();

View Full Code Here
   1: 
   2: import java.util.TreeSet;
   3: 
   4:         ...
   5:     long initial_seqno = 0;
   6:     TreeSet msgs = new TreeSet();
   7:     long next_to_remove = 0;
   8:         ...
   9:     public void reset() {
  10:         msgs.clear();
  11:         next_to_remove = initial_seqno;

View Full Code Here
   1:     public Set makeEmptySet() {
   2:         return UnmodifiableSortedSet.decorate(new TreeSet());
   3:     }
   4:         ...
   5:     public Set makeFullSet() {
   6:         TreeSet set = new TreeSet();
   7:         set.addAll(Arrays.asList(getFullElements()));
   8:         ...
   9:         try {
  10:             set.clear();
  11:             fail("Expecting UnsupportedOperationException.");

View Full Code Here
   1: import java.util.Set;
   2: import java.util.TreeSet;
   3: 
   4:         ...
   5:     private int portRange;
   6:     private TreeSet assignedPorts = new TreeSet();
   7: 
   8:         ...
   9:     public void reset() {
  10:         assignedPorts.clear();
  11:     }

View Full Code Here

clone

public Object clone()
Returns a shallow copy of this TreeSet instance. (The elements themselves are not cloned.)
Overrides:
clone in interface Object
Returns:
a shallow copy of this set.
Usages and Demos :

View More Examples of clone()
   1: import java.util.Set;
   2: import java.util.TreeSet;
   3: import gov.llnl.babel.backend.Utilities;
   4:         ...
   5:   private Type      d_return_type;
   6:   private TreeSet   d_throws;
   7: 
   8:         ...
   9:     try {
  10:       m = (Method) super.clone();
  11:       m.d_attributes = new HashMap();
  12:         ...
  13:     m.d_long_name = d_long_name + IOR.GENERIC_PRE_SUFFIX;
  14:     m.d_references = (HashSet) d_references.clone();   

View Full Code Here
   1: import java.util.Stack;
   2: import java.util.TreeSet;
   3: 
   4:         ...
   5:         try {
   6:             ntd = (NodeTypeDef) ntd.clone();
   7:         } catch (CloneNotSupportedException e) {
   8:         ...
   9:         try {
  10:             return (NodeTypeDef) def.clone();
  11:         } catch (CloneNotSupportedException e) {
  12:         ...
  13:     static class WeightedKey implements Comparable {
  14:         private final TreeSet set;

View Full Code Here

contains

public boolean contains(Object o)
Returns true if this set contains the specified element.
Specified by:
contains in interface Set<E>
contains in interface Collection<E>
Overrides:
contains in interface AbstractCollection<E>
Parameters:
o - the object to be checked for containment in this set.
Returns:
true if this set contains the specified element.
Throws:
ClassCastException - if the specified object cannot be compared with the elements currently in the set.
Usages and Demos :

View More Examples of contains(Object o)
   1: import java.util.Iterator;
   2: import java.util.TreeSet;
   3: 
   4:         ...
   5: 
   6:     private TreeSet resourceDescriptors;
   7:     
   8:         ...
   9:     public ResourceList() {
  10:         resourceDescriptors = new TreeSet();
  11:     }
  12:         ...
  13:     public boolean contains(ResourceDescriptor rd) {
  14:         return resourceDescriptors.contains(rd);

View Full Code Here
   1: import java.util.Iterator;
   2: import java.util.TreeSet;
   3: 
   4:         ...
   5: 
   6:    private TreeSet runnables = new TreeSet();
   7: 
   8:         ...
   9:    {
  10:       return runnables.contains(runnable);
  11:    }

View Full Code Here
   1: import java.util.HashMap;
   2: import java.util.TreeSet;
   3: 
   4:         ...
   5:   private HashMap encodings;
   6:   private TreeSet operations;
   7:   private PrinterEncoding[] encodingsCached;
   8:         ...
   9:     this.encodings = new HashMap();
  10:     this.operations = new TreeSet();
  11:     this.name = name;
  12:         ...
  13:   {
  14:     return operations.contains(operationName);

View Full Code Here
   1: 
   2: import java.util.TreeSet;
   3: 
   4:         ...
   5:     private Text fIntroIdText;
   6:     private TreeSet fIntroIds;
   7:     private IProduct fProduct;
   8:         ...
   9:             
  10:             if (error == null && fIntroIds.contains(id))
  11:                 error = PDEUIMessages.ProductIntroWizardPage_introIdExists;
  12:         ...
  13: 
  14:     private TreeSet getCurrentIntroIds() {

View Full Code Here
   1: import java.util.TreeMap;
   2: import java.util.TreeSet;
   3: 
   4:         ...
   5: 
   6:     private TreeSet fIdAttrNames = new TreeSet();
   7: 
   8:         ...
   9:         if (!(attributeName.equals(fLastIdAttrName)
  10:               || fIdAttrNames.contains(attributeName))) {
  11:             fIdAttrNames.add(attributeName);
  12:         ...
  13:     public boolean hasPCDataInContentModel(Element element) {
  14:         return fPCDataElements.contains(element.getTagName());

View Full Code Here

first

public E first()
Returns the first (lowest) element currently in this sorted set.
Specified by:
first in interface SortedSet<E>
Returns:
the first (lowest) element currently in this sorted set.
Throws:
NoSuchElementException - sorted set is empty.
Usages and Demos :

View More Examples of first()
   1: import java.util.Iterator;
   2: import java.util.TreeSet;
   3: 
   4:         ...
   5: 
   6:     private TreeSet resourceDescriptors;
   7:     
   8:         ...
   9:     public ResourceList() {
  10:         resourceDescriptors = new TreeSet();
  11:     }
  12:         ...
  13:     public ResourceDescriptor first() {
  14:         return (ResourceDescriptor) resourceDescriptors.first();

View Full Code Here
   1: import java.util.Iterator;
   2: import java.util.TreeSet;
   3: 
   4:         ...
   5: 
   6:    private TreeSet runnables = new TreeSet();
   7: 
   8:         ...
   9:       {
  10:          SchedulableRunnable next = (SchedulableRunnable) runnables.first();
  11:          long wait = next.getNextRun() - System.currentTimeMillis();

View Full Code Here
   1: import java.util.Set;
   2: import java.util.TreeSet;
   3: 
   4:         ...
   5:     private int portRange;
   6:     private TreeSet assignedPorts = new TreeSet();
   7: 
   8:         ...
   9:             else {
  10:                 int min = ((Integer) assignedPorts.first()).intValue();

View Full Code Here
   1:             lastSequence = initialSequence;
   2:             outgoingQueue = new TreeSet();
   3:         }
   4:         ...
   5:             while(outgoingQueue.size() > 0 &&
   6:                       (om = (OrderedMessage)outgoingQueue.first()).sequence == nextSequence)
   7:             {
   8:         ...
   9: 
  10:             lastSequence = ((OrderedMessage)outgoingQueue.first()).sequence - 1;
  11:             flush();

View Full Code Here
   1: import java.util.Date;
   2: import java.util.TreeSet;
   3: import java.util.Comparator;
   4:         ...
   5: public class Timer {
   6:     TreeSet tasks = new TreeSet(new TimerTaskComparator());
   7: 
   8:         ...
   9:             else {
  10:             TimerTask t = (TimerTask) tasks.first();
  11:             timeout = t.nextTime - System.currentTimeMillis();

View Full Code Here

headSet

public SortedSet headSet(E toElement)
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<E>
Parameters:
toElement - high endpoint (exclusive) of the headSet.
Returns:
a view of the portion of this set whose elements are strictly less than toElement.
Throws:
ClassCastException - if toElement is not compatible with this set's comparator (or, if the set has no comparator, if toElement does not implement Comparable).
IllegalArgumentException - if this set is itself a subSet, headSet, or tailSet, and toElement is not within the specified range of the subSet, headSet, or tailSet.
NullPointerException - if toElement is null and this set uses natural ordering, or its comparator does not tolerate null elements.

isEmpty

public boolean isEmpty()
Returns true if this set contains no elements.
Specified by:
isEmpty in interface Set<E>
isEmpty in interface Collection<E>
Overrides:
isEmpty in interface AbstractCollection<E>
Returns:
true if this set contains no elements.
Usages and Demos :

View More Examples of isEmpty()
   1: import java.util.Iterator;
   2: import java.util.TreeSet;
   3: 
   4:         ...
   5: 
   6:     private TreeSet resourceDescriptors;
   7:     
   8:         ...
   9:     public ResourceList() {
  10:         resourceDescriptors = new TreeSet();
  11:     }
  12:         ...
  13:     public boolean isEmpty() {
  14:         return resourceDescriptors.isEmpty();

View Full Code Here
   1: import java.util.Iterator;
   2: import java.util.TreeSet;
   3: 
   4:         ...
   5: 
   6:   private TreeSet markedProperties;
   7: 
   8:         ...
   9:     this.properties = new HashMap(props.properties);
  10:     this.markedProperties = new TreeSet();
  11:   }
  12:         ...
  13:   {
  14:     return markedProperties.isEmpty() == false;

View Full Code Here
   1: 
   2:         if (peer.links.isEmpty() && data.length == 0) {
   3:         }
   4:         ...
   5:     private void dijkstra(Peer root, List basisSet) {
   6:         TreeSet todo = new TreeSet(new Comparator() {
   7:             public int compare(Object o1, Object o2) {
   8:         ...
   9: 
  10:         while (! todo.isEmpty()) {
  11:             Peer p = (Peer)todo.first();

View Full Code Here
   1:         
   2:         private final TreeSet missingTimes=new TreeSet(), missingCompletions=new TreeSet();
   3:         
   4:         ...
   5:         public synchronized void setMemberLocalTime(Address address, int time) {
   6:             if (missingTimes.isEmpty()) return;
   7:             
   8:         ...
   9:             
  10:             if (missingTimes.isEmpty()) {
  11:                 if (active!=null) active.setFinalTimeVector(view, timeVector);                        
  12:         ...
  13:         public synchronized void setMemberCompleted(Address address) {
  14:             if (missingCompletions.isEmpty()) return;

View Full Code Here

iterator

public Iterator iterator()
Returns an iterator over the elements in this set. The elements are returned in ascending order.
Specified by:
iterator in interface Set<E>
iterator in interface Collection<E>
iterator in interface Iterable<T>
Overrides:
iterator in interface AbstractCollection<E>
Returns:
an iterator over the elements in this set.
Usages and Demos :

View More Examples of iterator()
   1: import jp.ujihara.java.util.Iterator;
   2: import jp.ujihara.java.util.TreeSet;
   3: 
   4:         ...
   5:         FontFactory.registerDirectories();
   6:         TreeSet families = new TreeSet(FontFactory.getRegisteredFamilies());
   7:         ...
   8:         for (Iterator i = families.iterator(); i.hasNext(); ) {
   9:             name = (String) i.next();
  10:         ...
  11:         TreeSet fonts = new TreeSet(FontFactory.getRegisteredFonts());
  12:         for (Iterator i = families.iterator(); i.hasNext(); ) {

View Full Code Here
   1: import java.util.Iterator;
   2: import java.util.TreeSet;
   3: 
   4:         ...
   5: 
   6:     private TreeSet resourceDescriptors;
   7:     
   8:         ...
   9:     public ResourceList() {
  10:         resourceDescriptors = new TreeSet();
  11:     }
  12:         ...
  13:     public Iterator elements() {
  14:         return resourceDescriptors.iterator();

View Full Code Here
   1: import java.util.Iterator;
   2: import java.util.TreeSet;
   3: 
   4:         ...
   5: {
   6:     private TreeSet sortedHosts;
   7:     private HashMap addressHostMapping;
   8:         ...
   9:     {
  10:         sortedHosts = new TreeSet( new CaughtHostComparator() );
  11:         addressHostMapping = new HashMap();
  12:         ...
  13:     {
  14:         return sortedHosts.iterator();

View Full Code Here
   1: import java.util.StringTokenizer;
   2: import java.util.TreeSet;
   3: 
   4:         ...
   5: 
   6:     final TreeSet availablePrinterNames = new TreeSet();
   7:     final Iterator it = printerConfig.findPropertyKeys
   8:         ...
   9:     int index = 0;
  10:     final Iterator printerIt = availablePrinterNames.iterator();
  11:     while (printerIt.hasNext())
  12:         ...
  13: 
  14:     final Iterator encIt = availableEncodingNames.iterator();

View Full Code Here
   1: import java.util.Set;
   2: import java.util.TreeSet;
   3: 
   4:         ...
   5:       Set keySet = folderList.keySet();
   6:       Iterator iter = keySet.iterator();
   7:       while (iter.hasNext()) {
   8:         ...
   9:     ArrayList optionList = new ArrayList();
  10:     TreeSet keySet = new TreeSet(map.keySet());
  11:         ...
  12:     Iterator keyIterator = keySet.iterator();

View Full Code Here

last

public E last()
Returns the last (highest) element currently in this sorted set.
Specified by:
last in interface SortedSet<E>
Returns:
the last (highest) element currently in this sorted set.
Throws:
NoSuchElementException - sorted set is empty.
Usages and Demos :

View More Examples of last()
   1: import java.util.Set;
   2: import java.util.TreeSet;
   3: 
   4:         ...
   5:     private int portRange;
   6:     private TreeSet assignedPorts = new TreeSet();
   7: 
   8:         ...
   9: 
  10:                 int max = ((Integer) assignedPorts.last()).intValue();

View Full Code Here
   1: import java.util.Iterator;
   2: import java.util.TreeSet;
   3: 
   4:         ...
   5:         Iterator iter      = objects.iterator();
   6:         TreeSet ts         = new TreeSet();
   7:         String idRef       = null;
   8:         ...
   9:         {
  10:             last = ((Integer)ts.last()).intValue();
  11:             newIndex = last + 1;

View Full Code Here
   1: import java.util.Iterator;
   2: import java.util.TreeSet;
   3: 
   4:         ...
   5:         Iterator iter = objects.iterator();
   6:         TreeSet ts = new TreeSet();
   7:         String idRef = null;
   8:         ...
   9:         {
  10:             last = ((Integer) ts.last()).intValue();
  11:             newIndex = last + 1;

View Full Code Here
   1:         Iterator iter = objects.iterator();
   2:         TreeSet ts = new TreeSet();
   3:         String idRef = null;
   4:         ...
   5:         {
   6:             last = ((Integer)ts.last()).intValue();
   7:             newIndex = last + 1;
   8:         }
   9:         else

View Full Code Here
   1: import java.util.List;
   2: import java.util.TreeSet;
   3: import java.util.Vector;
   4:         ...
   5:     {       
   6:         TreeSet tabs = new TreeSet(new PortletTabComparator());
   7:         PanedPortletController controller = null;
   8:         ...
   9:             {
  10:                 PortletTab lastTab = (PortletTab) tabs.last();
  11:                 int nextPos = lastTab.getPosition() + 1;

View Full Code Here

remove

public boolean remove(Object o)
Removes the specified element from this set if it is present.
Specified by:
remove in interface Set<E>
remove in interface Collection<E>
Overrides:
remove in interface AbstractCollection<E>
Parameters:
o - object to be removed from this set, if present.
Returns:
true if the set contained the specified element.
Throws:
ClassCastException - if the specified object cannot be compared with the elements currently in the set.
Usages and Demos :

View More Examples of remove(Object o)
   1: 
   2: import java.util.TreeSet;
   3: 
   4:         ...
   5:     private String action;
   6:     private TreeSet namespaces;
   7:     
   8:         ...
   9:         DataConfig config = ConfigRequests.getDataConfig(request);        
  10:         namespaces = new TreeSet(config.getNameSpaces().keySet());
  11:         String def = config.getDefaultNameSpace().getPrefix();
  12:         ...
  13:         if (namespaces.contains(def)) {
  14:             namespaces.remove(def);

View Full Code Here
   1: 
   2: import java.util.TreeSet;
   3: 
   4:         ...
   5:     long initial_seqno = 0;
   6:     TreeSet msgs = new TreeSet();
   7:     long next_to_remove = 0;
   8:         ...
   9:                 if(e.seqno == next_to_remove) {
  10:                     msgs.remove(e);
  11:                     next_to_remove++;

View Full Code Here
   1:     public Set makeEmptySet() {
   2:         return UnmodifiableSortedSet.decorate(new TreeSet());
   3:     }
   4:         ...
   5:     public Set makeFullSet() {
   6:         TreeSet set = new TreeSet();
   7:         set.addAll(Arrays.asList(getFullElements()));
   8:         ...
   9:         try {
  10:             set.remove("x");
  11:             fail("Expecting UnsupportedOperationException.");

View Full Code Here
   1: import java.util.Date;
   2: import java.util.TreeSet;
   3: import java.util.SortedSet;
   4:         ...
   5:             {
   6:                 icons.remove(info);
   7:                 return true;
   8:         ...
   9:     }
  10:     protected TreeSet icons = new TreeSet(new IconInfoComparator());
  11:     protected String title = "undefined";

View Full Code Here
   1: import java.util.Set;
   2: import java.util.TreeSet;
   3: 
   4:         ...
   5:     public Set makeEmptySet() {
   6:         return UnmodifiableSortedSet.decorate(new TreeSet());
   7:     }
   8:         ...
   9:     public Set makeFullSet() {
  10:         TreeSet set = new TreeSet();
  11:         set.addAll(Arrays.asList(getFullElements()));
  12:         ...
  13:         try {
  14:             set.remove("x");

View Full Code Here

size

public int size()
Returns the number of elements in this set (its cardinality).
Specified by:
size in interface Set<E>
size in interface Collection<E>
Overrides:
size in interface AbstractCollection<E>
Returns:
the number of elements in this set (its cardinality).
Usages and Demos :

View More Examples of size()
   1: import java.util.Iterator;
   2: import java.util.TreeSet;
   3: 
   4:         ...
   5: 
   6:     private TreeSet resourceDescriptors;
   7:     
   8:         ...
   9:     public ResourceList() {
  10:         resourceDescriptors = new TreeSet();
  11:     }
  12:         ...
  13:     public int size() {
  14:         return resourceDescriptors.size();

View Full Code Here
   1: import java.util.ResourceBundle;
   2: import java.util.TreeSet;
   3: 
   4:         ...
   5:     
   6:     private TreeSet list = new TreeSet();
   7:     
   8:         ...
   9:     {    
  10:         this.fireTableRowsInserted(0, list.size() - 1);
  11:     }
  12:         ...
  13:         
  14:         return list.size();

View Full Code Here
   1: 
   2:         TreeSet t = new TreeSet(keySet());
   3:         Iterator keys = t.iterator();
   4:         ...
   5:         int nkeys = t.size();
   6:         int i;
   7:         String metaStr = "";
   8:         for (i = 0; i < nkeys; i++)

View Full Code Here
   1: import java.util.List;
   2: import java.util.TreeSet;
   3: 
   4:         ...
   5:     public int size() {
   6:        return set.size();
   7:     }
   8:         ...
   9: 
  10:        if (this.size()==0) {
  11:          newRangeSet.add(boundingRange);
  12:         ...
  13:     public RangeSet findSubSet(Range range, boolean setNewRangeSetBoundingRange) {
  14:         Range[] ranges=new Range[set.size()];

View Full Code Here
   1:     private int expandMessages;
   2:     private TreeSet topicsOfInterest = new TreeSet();
   3:     private DataSource ds = null;
   4:         ...
   5: 
   6:         int count = topicsOfInterest.size();
   7: 
   8:         ...
   9: 
  10:         long[] tOI = new long[topicsOfInterest.size()];
  11: 
  12:         ...
  13:         int noOfTopics = topics.length;
  14:         topicsOfInterest = new TreeSet();

View Full Code Here

subSet

public SortedSet subSet(E fromElement,
                           E toElement)
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<E>
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.
Throws:
ClassCastException - if fromElement and toElement cannot be compared to one another using this set's comparator (or, if the set has no comparator, using natural ordering).
IllegalArgumentException - if fromElement is greater than toElement.
NullPointerException - if fromElement or toElement is null and this set uses natural order, or its comparator does not tolerate null elements.
Usages and Demos :

View More Examples of subSet(E fromElement,E toElement)
   1: import java.util.Date;
   2: import java.util.TreeSet;
   3: import java.util.SortedSet;
   4:         ...
   5:     }
   6:     protected TreeSet icons = new TreeSet(new IconInfoComparator());
   7:     protected String title = "undefined";
   8:         ...
   9:             return;
  10:         SortedSet visibleSet = icons.subSet(minTime, maxTime);
  11:         Iterator i = visibleSet.iterator();

View Full Code Here

super E> comparator

public Comparatorsuper E> comparator()
Returns the comparator used to order this sorted set, or null if this tree set uses its elements natural ordering.
Specified by:
super E> comparator in interface SortedSet<E>
Returns:
the comparator used to order this sorted set, or null if this tree set uses its elements natural ordering.

tailSet

public SortedSet tailSet(E fromElement)
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<E>
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.
Throws:
ClassCastException - if fromElement is not compatible with this set's comparator (or, if the set has no comparator, if fromElement does not implement Comparable).
IllegalArgumentException - if this set is itself a subSet, headSet, or tailSet, and fromElement is not within the specified range of the subSet, headSet, or tailSet.
NullPointerException - if fromElement is null and this set uses natural ordering, or its comparator does not tolerate null elements.
Usages and Demos :

View More Examples of tailSet(E fromElement)
   1: import java.util.StringTokenizer;
   2: import java.util.TreeSet;
   3: 
   4:         ...
   5: 
   6:     protected TreeSet completitions = new TreeSet();
   7:     protected Collection current = null;
   8:         ...
   9:             if (state == 0)
  10:                 possibleValues = completitions.tailSet(text).iterator();

View Full Code Here
   1: import java.util.StringTokenizer;
   2: import java.util.TreeSet;
   3: 
   4:         ...
   5:     
   6:     protected TreeSet completitions = new TreeSet();
   7:     protected LinkedList queryHistory = new LinkedList();
   8:         ...
   9:             }
  10:             Set set = completitions.tailSet(toComplete);
  11:             if (set != null && set.size() > 0) {
  12:         ...
  13:                 for (Iterator i = completitions.tailSet(toComplete).iterator(); i.hasNext(); ) {

View Full Code Here