|
|||||||||
| 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(Collection<? extends E> collection)
Creates a new sorted set with the same elements as the specified collection. |
|
SortedArraySet(Comparator<? super E> comparator)
Creates a new empty sorted set, sorted according to the specified comparator, with the initial capacity of ten. |
|
SortedArraySet(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(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(Collection<? extends E> c)
|
void |
clear()
|
Comparator<? super E> |
comparator()
Returns the comparator associated with this sorted set, or Comparators.naturalOrder if it uses its elements' natural ordering. |
boolean |
contains(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(Object o)
|
E |
first()
|
SortedSet<E> |
headSet(E toElement)
|
Iterator<E> |
iterator()
|
E |
last()
|
boolean |
remove(Object o)
|
int |
size()
|
SortedSet<E> |
subSet(E fromElement,
E toElement)
|
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
IllegalArgumentException - if initialCapacity is negativeComparators.naturalOrder()public SortedArraySet(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(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(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
ClassCastException - if the elements in the specified collection are
not mutually comparablepublic SortedArraySet(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 Collection<E>add in interface Set<E>add in class AbstractCollection<E>public boolean addAll(Collection<? extends E> c)
addAll in interface Collection<E>addAll in interface Set<E>addAll in class AbstractCollection<E>public void clear()
clear in interface Collection<E>clear in interface Set<E>clear in class AbstractCollection<E>public boolean contains(Object o)
contains in interface Collection<E>contains in interface Set<E>contains in class AbstractCollection<E>public boolean equals(Object o)
equals in interface Collection<E>equals in interface Set<E>equals in class AbstractSet<E>public Iterator<E> iterator()
iterator in interface Iterable<E>iterator in interface Collection<E>iterator in interface Set<E>iterator in class AbstractCollection<E>public boolean remove(Object o)
remove in interface Collection<E>remove in interface Set<E>remove in class AbstractCollection<E>public int size()
size in interface Collection<E>size in interface Set<E>size in class AbstractCollection<E>public Comparator<? super E> comparator()
Comparators.naturalOrder if it uses its elements' natural ordering.
comparator in interface SortedSet<E>
public SortedSet<E> subSet(E fromElement,
E toElement)
subSet in interface SortedSet<E>public SortedSet<E> headSet(E toElement)
headSet in interface SortedSet<E>public SortedSet<E> tailSet(E fromElement)
tailSet in interface SortedSet<E>public E first()
first in interface SortedSet<E>public E last()
last in interface SortedSet<E>
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||