Skip navigation links

Oracle Fusion Middleware Java API Reference for Oracle Extension SDK
11g Release 2 (11.1.2.3.0)

E17493-04


oracle.javatools.util
Class ArraySortedSet<E>

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractSet<E>
          extended by oracle.javatools.util.ArraySortedSet<E>

All Implemented Interfaces:
java.lang.Cloneable, java.lang.Iterable<E>, java.util.Collection<E>, java.util.Set<E>, java.util.SortedSet<E>
Direct Known Subclasses:
ArraySortedSet

public class ArraySortedSet<E>
extends java.util.AbstractSet<E>
implements java.util.SortedSet<E>, java.lang.Cloneable

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<? extends E> initialContents, java.util.Comparator<? super E> comparator)
          Construct a new ArraySortedSet with the given contents and comparator.
ArraySortedSet(java.util.Comparator<? super E> comparator)
          Construct a new ArraySortedSet of default size, using the specified comparator.
ArraySortedSet(E[] initialContents, java.util.Comparator<? super E> comparator)
          Construct a new ArraySortedSet with the given contents and 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<? super E> comparator)
          Construct a new ArraySortedSet of specified size, using the specified comparator.

 

Method Summary
 boolean add(E o)
          Adds the specified element to this set if it is not already present (optional operation).
 void addAll(E[] objects)
          Adds all objects in the specified array to the set.
 void clear()
          Removes all of the elements from this set (optional operation).
 java.lang.Object clone()
          Creates and returns a copy of this set.
 java.util.Comparator<? super E> 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.
 E first()
          Returns the first (lowest) element currently in this sorted set.
 java.util.SortedSet<E> headSet(E toElement)
          Returns a view of the portion of this sorted set whose elements are strictly less than toElement.
protected  java.lang.Object intern(E 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<E> iterator()
          Returns an iterator over the elements in this set.
 E last()
          Returns the last (highest) element currently in this sorted set.
 E lookup(E o)
          Looks up the specified object in the set, and returns that object found (instead of the one provided.) This can be used, for example, to implement an intern() type method for an object pool.
protected  ArraySortedSet<E> newArraySortedSet(int initialSize, java.util.Comparator<? super E> comparator)
           
 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<E> subSet(E fromElement, E toElement)
          Returns a view of the portion of this sorted set whose elements range from fromElement, inclusive, to toElement, exclusive.
 java.util.SortedSet<E> tailSet(E 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
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<? super E> 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<? super E> 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(E[] initialContents,
                      java.util.Comparator<? super E> 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<? extends E> initialContents,
                      java.util.Comparator<? super E> 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(E[] 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.

lookup

public E lookup(E o)
Looks up the specified object in the set, and returns that object found (instead of the one provided.) This can be used, for example, to implement an intern() type method for an object pool.
Parameters:
o - element whose presence in this set is to be tested.
Returns:
the object in this set that matches the provided object
Throws:
java.lang.ClassCastException - if the type of the specified element is incompatible with this set (optional).

newArraySortedSet

protected ArraySortedSet<E> newArraySortedSet(int initialSize,
                                              java.util.Comparator<? super E> comparator)

clone

public java.lang.Object clone()
Creates and returns a copy of this set. Note that this does not create a deep-copy. The objects contained in the cloned set are the same object instances in the original set.
Overrides:
clone in class java.lang.Object
Returns:
a copy of this set

comparator

public java.util.Comparator<? super E> 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<E>
Returns:
the comparator associated with this sorted set, or null if it uses its elements' natural ordering.

subSet

public java.util.SortedSet<E> subSet(E fromElement,
                                     E 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<E>

headSet

public java.util.SortedSet<E> headSet(E 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<E>

tailSet

public java.util.SortedSet<E> tailSet(E 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<E>

first

public E first()
Returns the first (lowest) element currently in this sorted set.
Specified by:
first in interface java.util.SortedSet<E>

last

public E last()
Returns the last (highest) element currently in this sorted set.
Specified by:
last in interface java.util.SortedSet<E>

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.Collection<E>
Specified by:
size in interface java.util.Set<E>
Specified by:
size in class java.util.AbstractCollection<E>
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.Collection<E>
Specified by:
isEmpty in interface java.util.Set<E>
Overrides:
isEmpty in class java.util.AbstractCollection<E>
Returns:
true if this set contains no elements.

iterator

public java.util.Iterator<E> 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.lang.Iterable<E>
Specified by:
iterator in interface java.util.Collection<E>
Specified by:
iterator in interface java.util.Set<E>
Specified by:
iterator in class java.util.AbstractCollection<E>
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.Collection<E>
Specified by:
toArray in interface java.util.Set<E>
Overrides:
toArray in class java.util.AbstractCollection<E>
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.Collection<E>
Specified by:
toArray in interface java.util.Set<E>
Overrides:
toArray in class java.util.AbstractCollection<E>

add

public boolean add(E 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.Collection<E>
Specified by:
add in interface java.util.Set<E>
Overrides:
add in class java.util.AbstractCollection<E>
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.Collection<E>
Specified by:
remove in interface java.util.Set<E>
Overrides:
remove in class java.util.AbstractCollection<E>
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.Collection<E>
Specified by:
contains in interface java.util.Set<E>
Overrides:
contains in class java.util.AbstractCollection<E>
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.Collection<E>
Specified by:
clear in interface java.util.Set<E>
Overrides:
clear in class java.util.AbstractCollection<E>

intern

protected java.lang.Object intern(E 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)

Skip navigation links

Oracle Fusion Middleware Java API Reference for Oracle Extension SDK
11g Release 2 (11.1.2.3.0)

E17493-04


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