- 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>
public class ArraySortedSet<E> extends AbstractSet<E> implements SortedSet<E>, Serializable
A compact
SortedSetimplementation that stores the elements in order. The emphasis is to use as little heap space as possible - this is not a general-purposeSortedSetimplementation 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:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description ArraySortedSet()ArraySortedSet(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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanadd(E e)booleanaddAll(Collection<? extends E> c)voidclear()Comparator<? super E>comparator()booleancontains(Object o)booleancontainsAll(Collection<?> c)Efirst()SortedSet<E>headSet(E toElement)booleanisEmpty()Iterator<E>iterator()Elast()booleanremove(Object o)booleanremoveAll(Collection<?> c)booleanretainAll(Collection<?> c)intsize()SortedSet<E>subSet(E fromElement, E toElement)SortedSet<E>tailSet(E fromElement)Object[]toArray()<T> T[]toArray(T[] a)voidtrimToSize()-
Methods inherited from class java.util.AbstractSet
equals, hashCode
-
Methods inherited from class java.util.AbstractCollection
toString
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
-
Methods inherited from interface java.util.SortedSet
spliterator
-
-
-
-
Constructor Detail
-
ArraySortedSet
public ArraySortedSet()
-
ArraySortedSet
public ArraySortedSet(int initialCapacity)
-
ArraySortedSet
public ArraySortedSet(Comparator<? super E> comparator)
-
ArraySortedSet
public ArraySortedSet(Comparator<? super E> comparator, int initialCapacity)
-
ArraySortedSet
public ArraySortedSet(Collection<? extends E> c)
-
-
Method Detail
-
trimToSize
public void trimToSize()
-
comparator
public Comparator<? super E> comparator()
- Specified by:
comparatorin interfaceSortedSet<E>
-
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
public boolean contains(Object o)
- Specified by:
containsin interfaceCollection<E>- Specified by:
containsin interfaceSet<E>- Overrides:
containsin classAbstractCollection<E>
-
toArray
public Object[] 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
public boolean add(E e)
- Specified by:
addin interfaceCollection<E>- Specified by:
addin interfaceSet<E>- Overrides:
addin classAbstractCollection<E>
-
remove
public boolean remove(Object o)
- Specified by:
removein interfaceCollection<E>- Specified by:
removein interfaceSet<E>- Overrides:
removein classAbstractCollection<E>
-
containsAll
public boolean containsAll(Collection<?> c)
- Specified by:
containsAllin interfaceCollection<E>- Specified by:
containsAllin interfaceSet<E>- Overrides:
containsAllin classAbstractCollection<E>
-
addAll
public boolean addAll(Collection<? extends E> c)
- Specified by:
addAllin interfaceCollection<E>- Specified by:
addAllin interfaceSet<E>- Overrides:
addAllin classAbstractCollection<E>
-
retainAll
public boolean retainAll(Collection<?> c)
- Specified by:
retainAllin interfaceCollection<E>- Specified by:
retainAllin interfaceSet<E>- Overrides:
retainAllin classAbstractCollection<E>
-
removeAll
public boolean removeAll(Collection<?> c)
- 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>
-
-