Extension SDK 10.1.2

oracle.ide.util
Class ArraySortedSet

java.lang.Object
  extended byjava.util.AbstractCollection
      extended byjava.util.AbstractSet
          extended byoracle.ide.util.ArraySortedSet
All Implemented Interfaces:
java.util.Collection, java.util.Set, java.util.SortedSet

public class ArraySortedSet
extends java.util.AbstractSet
implements java.util.SortedSet

The ArraySortedSet is an array implementation of the SortedSet interface. This implementation has significantly lower memory overhead than TreeSet (about 4 bytes per element vs. 40 bytes per element) and is intended to be a replacement for the use of TreeSet for sets containing under 3000 elements.

The main drawback of the array implementation is its worst-case performance characteristics when adding or removing elements in reverse sorted order.

This implementation does not support null elements.


Constructor Summary
ArraySortedSet()
          Construct a new ArraySortedSet of default size, using the default sorting order of the objects added to the set.
ArraySortedSet(java.util.Collection initialContents, java.util.Comparator comparator)
          Construct a new ArraySortedSet with the given contents and comparator.
ArraySortedSet(java.util.Comparator comparator)
          Construct a new ArraySortedSet of default size, using the specified comparator.
ArraySortedSet(int initialSize)
          Construct a new ArraySortedSet of specified size, using the default sorting order of the objects addded to the set.
ArraySortedSet(int initialSize, java.util.Comparator comparator)
          Construct a new ArraySortedSet of specified size, using the specified comparator.
ArraySortedSet(java.lang.Object[] initialContents, java.util.Comparator comparator)
          Construct a new ArraySortedSet with the given contents and comparator.
 
Method Summary
 boolean add(java.lang.Object o)
          Adds the specified element to this set if it is not already present (optional operation).
 void addAll(java.lang.Object[] objects)
          Adds all objects in the specified array to the set.
 void clear()
          Removes all of the elements from this set (optional operation).
 java.util.Comparator comparator()
          Returns the comparator associated with this sorted set, or null if it uses its elements' natural ordering.
 boolean contains(java.lang.Object o)
          Returns true if this set contains the specified element.
 java.lang.Object first()
          Returns the first (lowest) element currently in this sorted set.
 java.util.SortedSet headSet(java.lang.Object toElement)
          Returns a view of the portion of this sorted set whose elements are strictly less than toElement.
protected  java.lang.Object intern(java.lang.Object o)
          Utility routine which ensures that the Set will contain the given object.
 boolean isEmpty()
          Returns true if this set contains no elements.
 java.util.Iterator iterator()
          Returns an iterator over the elements in this set.
 java.lang.Object last()
          Returns the last (highest) element currently in this sorted set.
 boolean remove(java.lang.Object o)
          Removes the specified element from this set if it is present (optional operation).
 int size()
          Returns the number of elements in this set (its cardinality).
 java.util.SortedSet subSet(java.lang.Object fromElement, java.lang.Object toElement)
          Returns a view of the portion of this sorted set whose elements range from fromElement, inclusive, to toElement, exclusive.
 java.util.SortedSet tailSet(java.lang.Object fromElement)
          Returns a view of the portion of this sorted set whose elements are greater than or equal to fromElement.
 java.lang.Object[] toArray()
          Returns an array containing all of the elements in this set.
 java.lang.Object[] toArray(java.lang.Object[] a)
          Returns an array containing all of the elements in this set - the runtime type of the returned array is that of the specified array.
 void trimToSize()
          Utility routine to trim the size of the backing array to the minimum necessary to support the size of the set.
 
Methods inherited from class java.util.AbstractSet
equals, hashCode, removeAll
 
Methods inherited from class java.util.AbstractCollection
addAll, containsAll, retainAll, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Set
addAll, containsAll, equals, hashCode, removeAll, retainAll
 

Constructor Detail

ArraySortedSet

public ArraySortedSet()
Construct a new ArraySortedSet of default size, using the default sorting order of the objects added to the set.


ArraySortedSet

public ArraySortedSet(int initialSize)
Construct a new ArraySortedSet of specified size, using the default sorting order of the objects addded to the set.

Parameters:
initialSize - the initial capacity of the set

ArraySortedSet

public ArraySortedSet(java.util.Comparator comparator)
Construct a new ArraySortedSet of default size, using the specified comparator.

Parameters:
comparator - the comparator to use

ArraySortedSet

public ArraySortedSet(int initialSize,
                      java.util.Comparator comparator)
Construct a new ArraySortedSet of specified size, using the specified comparator.

Parameters:
initialSize - the initial capacity of the set
comparator - the comparator to use

ArraySortedSet

public ArraySortedSet(java.lang.Object[] initialContents,
                      java.util.Comparator comparator)
Construct a new ArraySortedSet with the given contents and comparator. All objects in the array will be added to the set.

Parameters:
initialContents - the initial contents to add to the set
comparator - the comparator to use

ArraySortedSet

public ArraySortedSet(java.util.Collection initialContents,
                      java.util.Comparator comparator)
Construct a new ArraySortedSet with the given contents and comparator. All objects in the collection will be added to the set.

Parameters:
initialContents - the initial contents to add to the set
comparator - the comparator to use.
Method Detail

addAll

public void addAll(java.lang.Object[] objects)
Adds all objects in the specified array to the set.

Parameters:
objects - the objects to add

trimToSize

public void trimToSize()
Utility routine to trim the size of the backing array to the minimum necessary to support the size of the set.


comparator

public java.util.Comparator comparator()
Returns the comparator associated with this sorted set, or null if it uses its elements' natural ordering.

Specified by:
comparator in interface java.util.SortedSet
Returns:
the comparator associated with this sorted set, or null if it uses its elements' natural ordering.

subSet

public java.util.SortedSet subSet(java.lang.Object fromElement,
                                  java.lang.Object toElement)
Returns a view of the portion of this sorted 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 sorted set, so changes in the returned sorted set are reflected in this sorted set, and vice-versa. The returned sorted set supports all optional set operations that this sorted set supports.

Specified by:
subSet in interface java.util.SortedSet

headSet

public java.util.SortedSet headSet(java.lang.Object toElement)
Returns a view of the portion of this sorted set whose elements are strictly less than toElement. The returned sorted set is backed by this sorted set, so changes in the returned sorted set are reflected in this sorted set, and vice-versa. The returned sorted set supports all optional set operations.

Specified by:
headSet in interface java.util.SortedSet

tailSet

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

Specified by:
tailSet in interface java.util.SortedSet

first

public java.lang.Object first()
Returns the first (lowest) element currently in this sorted set.

Specified by:
first in interface java.util.SortedSet

last

public java.lang.Object last()
Returns the last (highest) element currently in this sorted set.

Specified by:
last in interface java.util.SortedSet

size

public int size()
Returns the number of elements in this set (its cardinality). If this set contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.

Specified by:
size in interface java.util.Set
Returns:
the number of elements in this set (its cardinality).

isEmpty

public boolean isEmpty()
Returns true if this set contains no elements.

Specified by:
isEmpty in interface java.util.Set
Returns:
true if this set contains no elements.

iterator

public java.util.Iterator iterator()
Returns an iterator over the elements in this set. The elements are returned in no particular order (unless this set is an instance of some class that provides a guarantee).

Specified by:
iterator in interface java.util.Set
Returns:
an iterator over the elements in this set.

toArray

public java.lang.Object[] toArray()
Returns an array containing all of the elements in this set. Obeys the general contract of the Collection.toArray method.

Specified by:
toArray in interface java.util.Set
Returns:
an array containing all of the elements in this set.

toArray

public java.lang.Object[] toArray(java.lang.Object[] a)
Returns an array containing all of the elements in this set - the runtime type of the returned array is that of the specified array.

Specified by:
toArray in interface java.util.Set

add

public boolean add(java.lang.Object o)
Adds the specified element to this set if it is not already present (optional operation). More formally, adds the specified element, o, to this set if this set contains no element e such that (o==null ? e==null : o.equals(e)). If this set already contains the specified element, the call leaves this set unchanged and returns false. In combination with the restriction on constructors, this ensures that sets never contain duplicate elements.

The stipulation above does not imply that sets must accept all elements; sets may refuse to add any particular element, including null, and throwing an exception, as described in the specification for Collection.add. Individual set implementations should clearly document any restrictions on the the elements that they may contain.

Specified by:
add in interface java.util.Set
Parameters:
o - element to be added to this set.
Returns:
true if this set did not already contain the specified element.
Throws:
java.lang.UnsupportedOperationException - if the add method is not supported by this set.
java.lang.ClassCastException - if the class of the specified element prevents it from being added to this set.
java.lang.NullPointerException - if the specified element is null and this set does not support null elements.
java.lang.IllegalArgumentException - if some aspect of the specified element prevents it from being added to this set.

remove

public boolean remove(java.lang.Object o)
Removes the specified element from this set if it is present (optional operation). More formally, removes an element e such that (o==null ? e==null : o.equals(e)), if the set contains such an element. Returns true if the set contained the specified element (or equivalently, if the set changed as a result of the call). (The set will not contain the specified element once the call returns.)

Specified by:
remove in interface java.util.Set
Parameters:
o - object to be removed from this set, if present.
Returns:
true if the set contained the specified element.
Throws:
java.lang.ClassCastException - if the type of the specified element is incompatible with this set (optional).
java.lang.NullPointerException - if the specified element is null and this set does not support null elements (optional).
java.lang.UnsupportedOperationException - if the remove method is not supported by this set.

contains

public boolean contains(java.lang.Object o)
Returns true if this set contains the specified element. More formally, returns true if and only if this set contains an element e such that (o==null ? e==null : o.equals(e)).

Specified by:
contains in interface java.util.Set
Parameters:
o - element whose presence in this set is to be tested.
Returns:
true if this set contains the specified element.
Throws:
java.lang.ClassCastException - if the type of the specified element is incompatible with this set (optional).
java.lang.NullPointerException - if the specified element is null and this set does not support null elements (optional).

clear

public void clear()
Removes all of the elements from this set (optional operation). This set will be empty after this call returns (unless it throws an exception).

Specified by:
clear in interface java.util.Set

intern

protected java.lang.Object intern(java.lang.Object o)
Utility routine which ensures that the Set will contain the given object. If the object already exists in the Set, it is returned. Otherwise, it is added and the same object returned. This allows this set implementation to be used for pooling Objects.

Parameters:
o - the object to ensure exists in the Set
Returns:
the object contained in the Set (or added to the Set)

Extension SDK

 

Copyright © 1997, 2004, Oracle. All rights reserved.