Package eu.bandm.tools.util.java
Class IncrementalList<A>
java.lang.Object
java.util.AbstractCollection<A>
java.util.AbstractList<A>
eu.bandm.tools.util.java.IncrementalList<A>
- Type Parameters:
A- the type of list elements
- All Implemented Interfaces:
Iterable<A>,Collection<A>,List<A>,SequencedCollection<A>
An immutable list that supports efficient persistent updates.
Persistent Updates
This list implementation is immutable. The methods AbstractList.add(E), AbstractList.remove(int), AbstractCollection.remove(Object) and AbstractList.set(int, E) all throw UnsupportedOperationException.
Instead, there are methods append(A) and getFront() that
return a new list that contains one element more or less, respectively,
leaving the original unchanged. The implementation ensures that these
operations does not involve unnecessary copying.
- Since:
- 1.3
-
Field Summary
Fields inherited from class java.util.AbstractList
modCount -
Method Summary
Modifier and TypeMethodDescriptionReturns an extension of this list by a given element.static <A> IncrementalList<A> empty()Returns an empty list.get(int i) getFront()Returns the sublist without the last element, if any.getLast()Returns the last element.booleanisEmpty()static <A> IncrementalList<A> of(A... elems) Returns a incremental list copy of the given array.static <A> IncrementalList<A> Returns an incremental list copy of the given list.intsize()snapshot()Returns a copy of this list.Methods inherited from class java.util.AbstractList
add, add, addAll, clear, equals, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, remove, removeRange, set, subListMethods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, remove, removeAll, retainAll, toArray, toArray, toStringMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface java.util.List
addAll, addFirst, addLast, contains, containsAll, getFirst, remove, removeAll, removeFirst, removeLast, replaceAll, retainAll, reversed, sort, spliterator, toArray, toArray
-
Method Details
-
empty
Returns an empty list.- Type Parameters:
A- the type of list elements- Returns:
- a list containing no elements
-
get
-
size
public int size()- Specified by:
sizein interfaceCollection<A>- Specified by:
sizein interfaceList<A>- Specified by:
sizein classAbstractCollection<A>
-
isEmpty
public boolean isEmpty()- Specified by:
isEmptyin interfaceCollection<A>- Specified by:
isEmptyin interfaceList<A>- Overrides:
isEmptyin classAbstractCollection<A>
-
getFront
Returns the sublist without the last element, if any.This operation is very efficient.
- Returns:
- a list that contains all but the last element; or the empty list if there are no elements
-
getLast
Returns the last element.- Throws:
NoSuchElementException- if this list is empty.
-
of
Returns an incremental list copy of the given list.- Type Parameters:
A- the type of list elements- Parameters:
elems- the elements to copy- Returns:
- a new incremental list that contains each of
elems - Throws:
NullPointerException- ifelemsis null- See Also:
-
of
Returns a incremental list copy of the given array.- Type Parameters:
A- the type of list elements- Parameters:
elems- the elements to copy- Returns:
- a new incremental list that contains each of
elems - Throws:
NullPointerException- ifelemsis null- See Also:
-
append
Returns an extension of this list by a given element.This operation is very efficient.
- Parameters:
last- the element to append- Returns:
- a list that contains all elements of this list followed by
last
-
snapshot
Returns a copy of this 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 list. In particular, the returned list will implement
RandomAccess.- Returns:
- a copy of this list
- See Also:
-