Package org.apache.hadoop.hbase.util
Class SortedList<E>
java.lang.Object
org.apache.hadoop.hbase.util.SortedList<E>
- All Implemented Interfaces:
Iterable<E>,Collection<E>,List<E>,RandomAccess
Simple sorted list implementation that uses
ArrayList as the underlying
collection so we can support RandomAccess. All mutations create a new copy of the
ArrayList instance, so can be expensive. This class is only intended for use on
small, very rarely written collections that expect highly concurrent reads.
Read operations are performed on a reference to the internal list at the time of invocation, so will not see any mutations to the collection during their operation. Iterating over list elements manually using the RandomAccess pattern involves multiple operations. For this to be safe get a reference to the internal list first using get().
If constructed with a Comparator, the list will be sorted using the comparator.
Adding or changing an element using an index will trigger a resort.
Iterators are read-only. They cannot be used to remove elements.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionSortedList(Collection<? extends E> c, Comparator<? super E> comparator) Constructs a list containing the elements of the given collection, in the order returned by the collection's iterator, that will be sorted with the given comparator.SortedList(Comparator<? super E> comparator) Constructs an empty list with the default initial capacity that will be sorted using the given comparator. -
Method Summary
Modifier and TypeMethodDescriptionvoidbooleanbooleanaddAll(int index, Collection<? extends E> c) booleanaddAll(Collection<? extends E> c) voidclear()booleanbooleancontainsAll(Collection<?> c) get()Returns a reference to the unmodifiable list currently backing the SortedList.get(int index) intbooleanisEmpty()iterator()intlistIterator(int index) remove(int index) booleanbooleanremoveAll(Collection<?> c) booleanretainAll(Collection<?> c) intsize()subList(int fromIndex, int toIndex) Object[]toArray()<T> T[]toArray(T[] a) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, streamMethods inherited from interface java.util.List
equals, hashCode, replaceAll, sort, spliterator
-
Field Details
-
list
-
comparator
-
-
Constructor Details
-
SortedList
Constructs an empty list with the default initial capacity that will be sorted using the given comparator.- Parameters:
comparator- the comparator
-
SortedList
Constructs a list containing the elements of the given collection, in the order returned by the collection's iterator, that will be sorted with the given comparator.- Parameters:
c- the collectioncomparator- the comparator
-
-
Method Details
-
get
Returns a reference to the unmodifiable list currently backing the SortedList. Changes to the SortedList will not be reflected in this list. Use this method to get a reference for iterating over using the RandomAccess pattern. -
size
-
isEmpty
-
contains
-
iterator
-
toArray
-
toArray
-
add
-
remove
-
containsAll
- Specified by:
containsAllin interfaceCollection<E>- Specified by:
containsAllin interfaceList<E>
-
addAll
-
addAll
-
removeAll
-
retainAll
-
clear
-
get
-
set
-
add
-
remove
-
indexOf
-
lastIndexOf
- Specified by:
lastIndexOfin interfaceList<E>
-
listIterator
- Specified by:
listIteratorin interfaceList<E>
-
listIterator
- Specified by:
listIteratorin interfaceList<E>
-
subList
-