public class LinearList<V> extends IList.Mixin<V> implements Cloneable
ArrayList
and
ArrayDeque
, allowing elements to be added and removed from both ends of the collection and
allowing random-access reads and updates. Unlike List
, it can only hold Integer.MAX_VALUE
elements.
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
.
IList.Durable<V>, IList.Mixin<V>
hash
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() |
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) |
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() |
equals, hashCode, toString
finalize, getClass, notify, notifyAll, wait, wait, wait
concat, diff, equals, first, iterator, last, save, slice, split, spliterator, stream, toArray, toArray, toList, update
nth
public 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)
collection
public static <V> LinearList<V> from(Iterable<V> iterable)
iterable
public static <V> LinearList<V> from(Iterator<V> iterator)
iterator
public static <V> LinearList<V> from(IList<V> list)
list
public 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>
idx
public 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()
ICollection
If 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()
clone
in interface ICollection<IList<V>,V>
clone
in class IList.Mixin<V>