A
- The type of list elementspublic class ReverseList<A> extends AbstractList<A>
Instances of this class are called reverse lists in the documentation. This does not refer to the order of their elements, but rather to the fact that they are held together by chains of references from back to front.
Reverse lists are optimized for incremental front-to-back
construction; the append(A)
operation is fast. By contrast,
both random access to individual elements (get(int)
) and
traversal of all elements (AbstractList.iterator()
) are relatively slow.
Making a copy to a read-optimized data structure (snapshot()
) is recommended.
modCount
Constructor and Description |
---|
ReverseList(ReverseList<? extends A> front,
A last) |
Modifier and Type | Method and Description |
---|---|
ReverseList<A> |
append(A last)
Returns an extension of this list by a given element.
|
static <A> ReverseList<A> |
build(A... elems)
Returns a reverse list copy of the given array.
|
static <A> ReverseList<A> |
build(List<? extends A> elems)
Returns a reverse list copy of the given list.
|
static <A> ReverseList<A> |
cast(@Opt ReverseList<? extends A> list) |
static <A> ReverseList<A> |
empty() |
A |
get(int i) |
ReverseList<A> |
getFront()
Returns the sublist wothout the last element, if any.
|
A |
getLast()
Returns the last element.
|
boolean |
isEmpty() |
int |
size() |
List<A> |
snapshot()
Returns a copy of this reverse list.
|
static <A> List<A> |
snapshot(ReverseList<A> rev)
Deprecated.
use the instance method
snapshot() instead. |
add, add, addAll, clear, equals, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, remove, removeRange, set, subList
addAll, contains, containsAll, remove, removeAll, retainAll, toArray, toArray, toString
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
addAll, contains, containsAll, remove, removeAll, replaceAll, retainAll, sort, spliterator, toArray, toArray
parallelStream, removeIf, stream
public ReverseList(ReverseList<? extends A> front, @Opt A last)
public static <A> ReverseList<A> empty()
public static <A> ReverseList<A> cast(@Opt @Opt ReverseList<? extends A> list)
public int size()
size
in interface Collection<A>
size
in interface List<A>
size
in class AbstractCollection<A>
public boolean isEmpty()
isEmpty
in interface Collection<A>
isEmpty
in interface List<A>
isEmpty
in class AbstractCollection<A>
public ReverseList<A> getFront()
@Opt public A getLast()
NoSuchElement
- if this list is empty.public static <A> ReverseList<A> build(List<? extends A> elems)
snapshot()
@SafeVarargs public static <A> ReverseList<A> build(@Opt A... elems)
snapshot()
public ReverseList<A> append(@Opt A last)
public List<A> snapshot()
The returned list is not guaranteed to be either modifiable or unmodifiable. Element access can be expected to be more efficient on the copy than on this reverse list.
build(List)
,
build(Object...)
@Deprecated public static <A> List<A> snapshot(ReverseList<A> rev)
snapshot()
instead.see also the complete user documentation .