|
Extension SDK 10.1.2 | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.util.AbstractCollection java.util.AbstractSet oracle.ide.util.ArraySortedSet
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 |
public ArraySortedSet()
ArraySortedSet
of default size, using
the default sorting order of the objects added to the set.
public ArraySortedSet(int initialSize)
ArraySortedSet
of specified size, using
the default sorting order of the objects addded to the set.
initialSize
- the initial capacity of the setpublic ArraySortedSet(java.util.Comparator comparator)
ArraySortedSet
of default size, using
the specified comparator.
comparator
- the comparator to usepublic ArraySortedSet(int initialSize, java.util.Comparator comparator)
ArraySortedSet
of specified size, using
the specified comparator.
initialSize
- the initial capacity of the setcomparator
- the comparator to usepublic ArraySortedSet(java.lang.Object[] initialContents, java.util.Comparator comparator)
ArraySortedSet
with the given contents
and comparator. All objects in the array will be added to the set.
initialContents
- the initial contents to add to the setcomparator
- the comparator to usepublic ArraySortedSet(java.util.Collection initialContents, java.util.Comparator comparator)
ArraySortedSet
with the given contents
and comparator. All objects in the collection will be added to the set.
initialContents
- the initial contents to add to the setcomparator
- the comparator to use.Method Detail |
public void addAll(java.lang.Object[] objects)
objects
- the objects to addpublic void trimToSize()
public java.util.Comparator comparator()
comparator
in interface java.util.SortedSet
public java.util.SortedSet subSet(java.lang.Object fromElement, java.lang.Object toElement)
subSet
in interface java.util.SortedSet
public java.util.SortedSet headSet(java.lang.Object toElement)
headSet
in interface java.util.SortedSet
public java.util.SortedSet tailSet(java.lang.Object fromElement)
tailSet
in interface java.util.SortedSet
public java.lang.Object first()
first
in interface java.util.SortedSet
public java.lang.Object last()
last
in interface java.util.SortedSet
public int size()
size
in interface java.util.Set
public boolean isEmpty()
isEmpty
in interface java.util.Set
public java.util.Iterator iterator()
iterator
in interface java.util.Set
public java.lang.Object[] toArray()
toArray
in interface java.util.Set
public java.lang.Object[] toArray(java.lang.Object[] a)
toArray
in interface java.util.Set
public boolean add(java.lang.Object o)
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.
add
in interface java.util.Set
o
- element to be added to this set.
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.public boolean remove(java.lang.Object o)
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.)
remove
in interface java.util.Set
o
- object to be removed from this set, if present.
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.public boolean contains(java.lang.Object o)
e
such that (o==null ? e==null :
o.equals(e))
.
contains
in interface java.util.Set
o
- element whose presence in this set is to be tested.
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).public void clear()
clear
in interface java.util.Set
protected java.lang.Object intern(java.lang.Object o)
o
- the object to ensure exists in the Set
|
Extension SDK | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Copyright © 1997, 2004, Oracle. All rights reserved.