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
-
Constructor Summary
ConstructorDescriptionSortedList
(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 TypeMethodDescriptionvoid
boolean
boolean
addAll
(int index, Collection<? extends E> c) boolean
addAll
(Collection<? extends E> c) void
clear()
boolean
boolean
containsAll
(Collection<?> c) get()
Returns a reference to the unmodifiable list currently backing the SortedList.get
(int index) int
boolean
isEmpty()
iterator()
int
listIterator
(int index) remove
(int index) boolean
boolean
removeAll
(Collection<?> c) boolean
retainAll
(Collection<?> c) int
size()
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, wait
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream
Methods 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:
containsAll
in interfaceCollection<E>
- Specified by:
containsAll
in interfaceList<E>
-
addAll
-
addAll
-
removeAll
-
retainAll
-
clear
-
get
-
set
-
add
-
remove
-
indexOf
-
lastIndexOf
- Specified by:
lastIndexOf
in interfaceList<E>
-
listIterator
- Specified by:
listIterator
in interfaceList<E>
-
listIterator
- Specified by:
listIterator
in interfaceList<E>
-
subList
-