|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.util.AbstractCollection<E>
java.util.AbstractSet<E>
com.google.common.collect.SortedArraySet<E>
public final class SortedArraySet<E>
A sorted set that keeps its elements in a sorted ArrayList. Null
elements are allowed when the SortedArraySet is constructed with an
explicit comparator that supports nulls.
This class is useful when you may have many sorted sets that only have
zero or one elements each. The performance of this implementation does not
scale to large numbers of elements as well as TreeSet, but
it is much more memory-efficient per entry.
Each SortedArraySet has a capacity, because it is backed by
an ArrayList. The capacity is the size of the array used to store the
elements in the set. It is always at least as large as the set size. As
elements are added to the set, its capacity grows automatically. The details
of the growth policy are not specified beyond the fact that adding an element
has O(lg n) amortized time cost.
An application can increase the capacity of the set before adding a large
number of elements using the ensureCapacity operation. This may
reduce the amount of incremental reallocation.
This implementation is not synchronized. As with ArrayList,
external synchronization is needed if multiple threads access a SortedArraySet instance concurrently and at least one adds or deletes any
elements.
| Constructor Summary | |
|---|---|
SortedArraySet()
Constructs a new empty sorted set, sorted according to the element's natural order, with an initial capacity of ten. |
|
SortedArraySet(java.util.Collection<? extends E> collection)
Creates a new sorted set with the same elements as the specified collection. |
|
SortedArraySet(java.util.Comparator<? super E> comparator)
Creates a new empty sorted set, sorted according to the specified comparator, with the initial capacity of ten. |
|
SortedArraySet(java.util.Comparator<? super E> comparator,
int initialCapacity)
Creates a new empty sorted set, sorted according to the specified comparator, with the specified initial capacity. |
|
SortedArraySet(int initialCapacity)
Constructs a new empty sorted set, sorted according to the element's natural order, with the specified initial capacity. |
|
SortedArraySet(java.util.SortedSet<E> set)
Creates a new sorted set with the same elements and the same ordering as the specified sorted set. |
|
| Method Summary | |
|---|---|
boolean |
add(E o)
|
boolean |
addAll(java.util.Collection<? extends E> c)
|
void |
clear()
|
java.util.Comparator<? super E> |
comparator()
Returns the comparator associated with this sorted set, or Comparators.naturalOrder if it uses its elements' natural ordering. |
boolean |
contains(java.lang.Object o)
|
void |
ensureCapacity(int minCapacity)
Increases the capacity of this sorted set, if necessary, to ensure that it can hold at least the number of elements specified by the minimum capacity argument. |
boolean |
equals(java.lang.Object o)
|
E |
first()
|
java.util.SortedSet<E> |
headSet(E toElement)
|
java.util.Iterator<E> |
iterator()
|
E |
last()
|
boolean |
remove(java.lang.Object o)
|
int |
size()
|
java.util.SortedSet<E> |
subSet(E fromElement,
E toElement)
|
java.util.SortedSet<E> |
tailSet(E fromElement)
|
void |
trimToSize()
Trims the capacity of this sorted set to be the set's current size. |
| Methods inherited from class java.util.AbstractSet |
|---|
hashCode, removeAll |
| Methods inherited from class java.util.AbstractCollection |
|---|
containsAll, isEmpty, retainAll, toArray, toArray, toString |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface java.util.Set |
|---|
containsAll, hashCode, isEmpty, removeAll, retainAll, toArray, toArray |
| Constructor Detail |
|---|
public SortedArraySet()
Comparable interface. Furthermore, all
such elements must be mutally 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
method may throw a ClassCastException.
Comparable,
Comparators.naturalOrder()public SortedArraySet(int initialCapacity)
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 method may throw a ClassCastException.
initialCapacity - the initial capacity of the list
java.lang.IllegalArgumentException - if initialCapacity is negativeComparators.naturalOrder()public SortedArraySet(java.util.Comparator<? super E> 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 method may throw a ClassCastException.
comparator - the comparator used to sort elements in this set
public SortedArraySet(java.util.Comparator<? super E> comparator,
int initialCapacity)
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 method may throw a ClassCastException.
comparator - the comparator used to sort elements in this setpublic SortedArraySet(java.util.Collection<? extends E> collection)
SortedSet instance,
this constructor behaves identically to SortedArraySet(SortedSet).
Otherwise, the elements are sorted according to the elements' natural
order; see SortedArraySet().
collection - the elements that will comprise the new set
java.lang.ClassCastException - if the elements in the specified collection are
not mutually comparablepublic SortedArraySet(java.util.SortedSet<E> set)
set - the set whose elements will comprise the new set| Method Detail |
|---|
public void ensureCapacity(int minCapacity)
minCapacity - the desired minimum capacitypublic void trimToSize()
public boolean add(E o)
add in interface java.util.Collection<E>add in interface java.util.Set<E>add in class java.util.AbstractCollection<E>public boolean addAll(java.util.Collection<? extends E> c)
addAll in interface java.util.Collection<E>addAll in interface java.util.Set<E>addAll in class java.util.AbstractCollection<E>public void clear()
clear in interface java.util.Collection<E>clear in interface java.util.Set<E>clear in class java.util.AbstractCollection<E>public boolean contains(java.lang.Object o)
contains in interface java.util.Collection<E>contains in interface java.util.Set<E>contains in class java.util.AbstractCollection<E>public boolean equals(java.lang.Object o)
equals in interface java.util.Collection<E>equals in interface java.util.Set<E>equals in class java.util.AbstractSet<E>public java.util.Iterator<E> iterator()
iterator in interface java.lang.Iterable<E>iterator in interface java.util.Collection<E>iterator in interface java.util.Set<E>iterator in class java.util.AbstractCollection<E>public boolean remove(java.lang.Object o)
remove in interface java.util.Collection<E>remove in interface java.util.Set<E>remove in class java.util.AbstractCollection<E>public int size()
size in interface java.util.Collection<E>size in interface java.util.Set<E>size in class java.util.AbstractCollection<E>public java.util.Comparator<? super E> comparator()
Comparators.naturalOrder if it uses its elements' natural ordering.
comparator in interface java.util.SortedSet<E>
public java.util.SortedSet<E> subSet(E fromElement,
E toElement)
subSet in interface java.util.SortedSet<E>public java.util.SortedSet<E> headSet(E toElement)
headSet in interface java.util.SortedSet<E>public java.util.SortedSet<E> tailSet(E fromElement)
tailSet in interface java.util.SortedSet<E>public E first()
first in interface java.util.SortedSet<E>public E last()
last in interface java.util.SortedSet<E>
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||