Package eu.bandm.tools.ramus.runtime2
Class ReverseList<A>
java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractList<A>
eu.bandm.tools.ramus.runtime2.ReverseList<A>
- Type Parameters:
A
- The type of list elements
- All Implemented Interfaces:
Iterable<A>
,Collection<A>
,List<A>
Generic, immutable, reverse single-linked lists.
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.
-
Field Summary
Fields inherited from class java.util.AbstractList
modCount
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionReturns an extension of this list by a given element.static <A> ReverseList<A>
Returns a reverse list copy of the given array.static <A> ReverseList<A>
Returns a reverse list copy of the given list.static <A> ReverseList<A>
cast
(@Opt ReverseList<? extends A> list) static <A> ReverseList<A>
empty()
get
(int i) getFront()
Returns the sublist wothout the last element, if any.getLast()
Returns the last element.boolean
isEmpty()
int
size()
snapshot()
Returns a copy of this reverse list.static <A> List<A>
snapshot
(ReverseList<A> rev) Deprecated.Methods inherited from class java.util.AbstractList
add, add, addAll, clear, equals, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, remove, removeRange, set, subList
Methods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, remove, removeAll, retainAll, toArray, toArray, 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.List
addAll, contains, containsAll, remove, removeAll, replaceAll, retainAll, sort, spliterator, toArray, toArray
-
Constructor Details
-
ReverseList
-
-
Method Details
-
empty
-
cast
-
get
-
size
public int size()- Specified by:
size
in interfaceCollection<A>
- Specified by:
size
in interfaceList<A>
- Specified by:
size
in classAbstractCollection<A>
-
isEmpty
public boolean isEmpty()- Specified by:
isEmpty
in interfaceCollection<A>
- Specified by:
isEmpty
in interfaceList<A>
- Overrides:
isEmpty
in classAbstractCollection<A>
-
getFront
Returns the sublist wothout the last element, if any. -
getLast
Returns the last element.- Throws:
NoSuchElement
- if this list is empty.
-
build
Returns a reverse list copy of the given list.- See Also:
-
build
Returns a reverse list copy of the given array.- See Also:
-
append
Returns an extension of this list by a given element. -
snapshot
Returns a copy of this reverse list.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.
- See Also:
-
snapshot
Deprecated.use the instance methodsnapshot()
instead.Returns a copy of this reverse list.
-
snapshot()
instead.