public class LinearList<V> extends Object implements IList<V>, Cloneable
ArrayList and
ArrayDeque, allowing elements to be added and removed from both ends of the collection and
allowing random-access reads and updates.
Calls to IList.concat(IList), IList.slice(long, long), and IList.split(int) create virtual collections which
retain a reference to the whole underlying collection, and are somewhat less efficient than LinearList.
| Constructor and Description |
|---|
LinearList() |
LinearList(int capacity) |
| Modifier and Type | Method and Description |
|---|---|
LinearList<V> |
addFirst(V value) |
LinearList<V> |
addLast(V value) |
LinearList<V> |
clear() |
LinearList<V> |
clone() |
boolean |
equals(Object obj) |
IList<V> |
forked()
This returns a data structure which is forked, which is equivalent to Clojure's persistent
data structures, also sometimes called functional or immutable.
|
static <V> LinearList<V> |
from(Collection<V> collection) |
static <V> LinearList<V> |
from(IList<V> list) |
static <V> LinearList<V> |
from(Iterable<V> iterable) |
static <V> LinearList<V> |
from(Iterator<V> iterator) |
int |
hashCode() |
boolean |
isLinear() |
Iterator<V> |
iterator() |
IList<V> |
linear()
This returns a data structure which is linear, or temporarily mutable.
|
V |
nth(long idx) |
static <V> LinearList<V> |
of(V... elements) |
V |
popFirst()
Removes, and returns, the first element of the list.
|
V |
popLast()
Removes, and returns, the last element of the list.
|
LinearList<V> |
removeFirst() |
LinearList<V> |
removeLast() |
LinearList<V> |
set(long idx,
V value) |
long |
size() |
String |
toString() |
finalize, getClass, notify, notifyAll, wait, wait, waitconcat, equals, first, last, save, slice, split, spliterator, stream, toArray, toArray, toList, updatenthpublic LinearList()
public LinearList(int capacity)
capacity - the initial capacity of the listpublic static <V> LinearList<V> of(V... elements)
public static <V> LinearList<V> from(Collection<V> collection)
collectionpublic static <V> LinearList<V> from(Iterable<V> iterable)
iterablepublic static <V> LinearList<V> from(Iterator<V> iterator)
iteratorpublic static <V> LinearList<V> from(IList<V> list)
listpublic boolean isLinear()
public LinearList<V> addLast(V value)
public LinearList<V> addFirst(V value)
public LinearList<V> removeFirst()
removeFirst in interface IList<V>public LinearList<V> removeLast()
removeLast in interface IList<V>public LinearList<V> clear()
public LinearList<V> set(long idx, V value)
set in interface IList<V>idx overwritten with value. If idx is equal to ICollection.size(), the value is appended.public V nth(long idx)
nth in interface ICollection<IList<V>,V>idxpublic V popFirst()
IndexOutOfBoundsException - if the list is emptypublic V popLast()
IndexOutOfBoundsException - if the list is emptypublic long size()
size in interface ICollection<IList<V>,V>public IList<V> forked()
ICollectionIf only a single function or scope uses the data structure, it can be left as a linear data structure, which can have significant performance benefits.
If the data structure is already forked, it will simply return itself.
public IList<V> linear()
ICollection
If ICollection.forked() is called on a linear collection, all references to that linear collection should be discarded.
If the data structure is already linear, it will simply return itself.
public LinearList<V> clone()