java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractSet<E>
com.aoapps.collections.ArraySortedSet<E>
- All Implemented Interfaces:
Serializable,Iterable<E>,Collection<E>,Set<E>,SortedSet<E>
A compact
SortedSet implementation that stores the elements in order.
The emphasis is to use as little heap space as possible - this is not a general-purpose
SortedSet implementation as it has specific constraints about the order elements
may be added or removed. To avoid the possibility of O(n^2) behavior, the elements must
already be sorted and be added in ascending order. Also, only the last element may be
removed.
This set does not support null values.
Creation of a set for an already sorted set is O(n) compared to TreeSet's O(n log n). Other operations perform at O(log n) with times very similar to TreeSet.
This set is not thread safe.
- Author:
- AO Industries, Inc.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionArraySortedSet(int initialCapacity) ArraySortedSet(Collection<? extends E> c) ArraySortedSet(Comparator<? super E> comparator) ArraySortedSet(Comparator<? super E> comparator, int initialCapacity) ArraySortedSet(SortedSet<E> s) -
Method Summary
Modifier and TypeMethodDescriptionbooleanbooleanaddAll(Collection<? extends E> c) voidclear()Comparator<? super E> booleanbooleancontainsAll(Collection<?> c) first()booleanisEmpty()iterator()last()booleanbooleanremoveAll(Collection<?> c) booleanretainAll(Collection<?> c) intsize()Object[]toArray()<T> T[]toArray(T[] a) voidMethods inherited from class java.util.AbstractSet
equals, hashCodeMethods inherited from class java.util.AbstractCollection
toStringMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface java.util.SortedSet
spliterator
-
Constructor Details
-
ArraySortedSet
public ArraySortedSet() -
ArraySortedSet
public ArraySortedSet(int initialCapacity) -
ArraySortedSet
-
ArraySortedSet
-
ArraySortedSet
-
ArraySortedSet
-
-
Method Details
-
trimToSize
public void trimToSize() -
comparator
- Specified by:
comparatorin interfaceSortedSet<E>
-
subSet
-
headSet
-
tailSet
-
first
-
last
-
size
public int size()- Specified by:
sizein interfaceCollection<E>- Specified by:
sizein interfaceSet<E>- Specified by:
sizein classAbstractCollection<E>
-
isEmpty
public boolean isEmpty()- Specified by:
isEmptyin interfaceCollection<E>- Specified by:
isEmptyin interfaceSet<E>- Overrides:
isEmptyin classAbstractCollection<E>
-
contains
- Specified by:
containsin interfaceCollection<E>- Specified by:
containsin interfaceSet<E>- Overrides:
containsin classAbstractCollection<E>
-
iterator
-
toArray
- Specified by:
toArrayin interfaceCollection<E>- Specified by:
toArrayin interfaceSet<E>- Overrides:
toArrayin classAbstractCollection<E>
-
toArray
public <T> T[] toArray(T[] a) - Specified by:
toArrayin interfaceCollection<E>- Specified by:
toArrayin interfaceSet<E>- Overrides:
toArrayin classAbstractCollection<E>
-
add
- Specified by:
addin interfaceCollection<E>- Specified by:
addin interfaceSet<E>- Overrides:
addin classAbstractCollection<E>
-
remove
- Specified by:
removein interfaceCollection<E>- Specified by:
removein interfaceSet<E>- Overrides:
removein classAbstractCollection<E>
-
containsAll
- Specified by:
containsAllin interfaceCollection<E>- Specified by:
containsAllin interfaceSet<E>- Overrides:
containsAllin classAbstractCollection<E>
-
addAll
- Specified by:
addAllin interfaceCollection<E>- Specified by:
addAllin interfaceSet<E>- Overrides:
addAllin classAbstractCollection<E>
-
retainAll
- Specified by:
retainAllin interfaceCollection<E>- Specified by:
retainAllin interfaceSet<E>- Overrides:
retainAllin classAbstractCollection<E>
-
removeAll
- Specified by:
removeAllin interfaceCollection<E>- Specified by:
removeAllin interfaceSet<E>- Overrides:
removeAllin classAbstractSet<E>
-
clear
public void clear()- Specified by:
clearin interfaceCollection<E>- Specified by:
clearin interfaceSet<E>- Overrides:
clearin classAbstractCollection<E>
-
