public class ReferenceImmutableList<K> extends AbstractReferenceList<K> implements ReferenceList<K>, java.util.RandomAccess, java.lang.Cloneable, java.io.Serializable
Instances of this class are immutable and (contrarily to mutable array-based list implementations) the backing array is not exposed. Instances can be built using a variety of methods, but note that constructors using an array will not make a defensive copy.
This class implements the bulk method getElements()
using
high-performance system calls (e.g., System.arraycopy()
) instead of
expensive loops.
AbstractReferenceList.ReferenceRandomAccessSubList<K>, AbstractReferenceList.ReferenceSubList<K>
Constructor and Description |
---|
ReferenceImmutableList(java.util.Collection<? extends K> c)
Creates a new immutable list and fills it with a given collection.
|
ReferenceImmutableList(K[] a)
Creates a new immutable list using a given array.
|
ReferenceImmutableList(K[] a,
int offset,
int length)
Creates a new immutable list and fills it with the elements of a given array.
|
ReferenceImmutableList(ObjectIterator<? extends K> i)
Creates a new immutable list and fills it with the elements returned by a type-specific iterator..
|
ReferenceImmutableList(ReferenceCollection<? extends K> c)
Creates a new immutable list and fills it with a given type-specific collection.
|
ReferenceImmutableList(ReferenceList<? extends K> l)
Creates a new immutable list and fills it with a given type-specific list.
|
Modifier and Type | Method and Description |
---|---|
void |
add(int index,
K k)
Deprecated.
|
boolean |
add(K k)
Deprecated.
|
boolean |
addAll(java.util.Collection<? extends K> c)
Deprecated.
|
boolean |
addAll(int index,
java.util.Collection<? extends K> c)
Deprecated.
|
void |
addElements(int index,
K[] a,
int offset,
int length)
Deprecated.
|
void |
clear()
Deprecated.
|
ReferenceImmutableList<K> |
clone() |
boolean |
equals(java.lang.Object o) |
boolean |
equals(ReferenceImmutableList<K> l)
Compares this type-specific immutable list to another one.
|
void |
forEach(java.util.function.Consumer<? super K> action) |
K |
get(int index) |
void |
getElements(int from,
java.lang.Object[] a,
int offset,
int length)
Copies element of this type-specific list into the given array using optimized system calls.
|
int |
indexOf(java.lang.Object k) |
boolean |
isEmpty()
Checks whether the stack is empty.
|
int |
lastIndexOf(java.lang.Object k) |
ObjectListIterator<K> |
listIterator(int index)
Returns a type-specific list iterator on the list starting at a given index.
|
static <K> ReferenceImmutableList<K> |
of()
Returns an empty immutable list.
|
static <K> ReferenceImmutableList<K> |
of(K... init)
Creates an immutable list using a list of elements.
|
K |
remove(int index)
Deprecated.
|
boolean |
remove(java.lang.Object k)
Deprecated.
|
boolean |
removeAll(java.util.Collection<?> c)
Deprecated.
|
void |
removeElements(int from,
int to)
Deprecated.
|
boolean |
removeIf(java.util.function.Predicate<? super K> c)
Deprecated.
|
void |
replaceAll(java.util.function.UnaryOperator<K> operator)
Deprecated.
|
boolean |
retainAll(java.util.Collection<?> c)
Deprecated.
|
K |
set(int index,
K k)
Deprecated.
|
void |
setElements(int index,
K[] a,
int offset,
int length)
Deprecated.
|
int |
size() |
void |
size(int size)
Deprecated.
|
void |
sort(java.util.Comparator<? super K> comparator)
Deprecated.
|
ObjectSpliterator<K> |
spliterator()
Returns a type-specific spliterator on the elements of this list.
|
ReferenceList<K> |
subList(int from,
int to)
Returns a type-specific view of the portion of this list from the index
from , inclusive, to the index to , exclusive. |
java.lang.Object[] |
toArray() |
<K> K[] |
toArray(K[] a) |
static <K> java.util.stream.Collector<K,?,ReferenceImmutableList<K>> |
toList()
Returns a
Collector that collects a Stream 's elements into a new ImmutableList. |
static <K> java.util.stream.Collector<K,?,ReferenceImmutableList<K>> |
toListWithExpectedSize(int expectedSize)
Returns a
Collector that collects a Stream 's elements into a new ImmutableList, potentially pre-allocated to handle the given size. |
void |
unstableSort(java.util.Comparator<? super K> comparator)
Deprecated.
|
addElements, contains, hashCode, iterator, listIterator, peek, pop, push, top, toString
addAll, addAll, addElements, addElements, iterator, listIterator, of, of, removeElements, setElements, setElements, setElements, size, sort, unstableSort
public ReferenceImmutableList(K[] a)
Note that this constructor does not perform a defensive copy.
a
- the array that will be used to back this immutable list.public ReferenceImmutableList(java.util.Collection<? extends K> c)
c
- a collection that will be used to fill the immutable list.public ReferenceImmutableList(ReferenceCollection<? extends K> c)
c
- a type-specific collection that will be used to fill the immutable list.public ReferenceImmutableList(ReferenceList<? extends K> l)
l
- a type-specific list that will be used to fill the immutable list.public ReferenceImmutableList(K[] a, int offset, int length)
a
- an array whose elements will be used to fill the immutable list.offset
- the first element to use.length
- the number of elements to use.public ReferenceImmutableList(ObjectIterator<? extends K> i)
i
- a type-specific iterator whose returned elements will fill the immutable list.public static <K> ReferenceImmutableList<K> of()
of
in interface ReferenceList<K>
@SafeVarargs public static <K> ReferenceImmutableList<K> of(K... init)
Note that this method does not perform a defensive copy.
of
in interface ReferenceList<K>
init
- a list of elements that will be used to initialize the list.public static <K> java.util.stream.Collector<K,?,ReferenceImmutableList<K>> toList()
Collector
that collects a Stream
's elements into a new ImmutableList.public static <K> java.util.stream.Collector<K,?,ReferenceImmutableList<K>> toListWithExpectedSize(int expectedSize)
Collector
that collects a Stream
's elements into a new ImmutableList, potentially pre-allocated to handle the given size.public int indexOf(java.lang.Object k)
indexOf
in interface java.util.List<K>
indexOf
in class AbstractReferenceList<K>
public int lastIndexOf(java.lang.Object k)
lastIndexOf
in interface java.util.List<K>
lastIndexOf
in class AbstractReferenceList<K>
public int size()
public boolean isEmpty()
Stack
public void getElements(int from, java.lang.Object[] a, int offset, int length)
getElements
in interface ReferenceList<K>
getElements
in class AbstractReferenceList<K>
from
- the start index (inclusive).a
- the destination array.offset
- the offset into the destination array where to store the first element copied.length
- the number of elements to be copied.public void forEach(java.util.function.Consumer<? super K> action)
AbstractReferenceList
forEach
in interface java.lang.Iterable<K>
forEach
in class AbstractReferenceList<K>
public java.lang.Object[] toArray()
toArray
in interface java.util.Collection<K>
toArray
in interface java.util.List<K>
toArray
in class AbstractReferenceList<K>
public <K> K[] toArray(K[] a)
toArray
in interface java.util.Collection<K>
toArray
in interface java.util.List<K>
toArray
in class AbstractReferenceList<K>
public ObjectListIterator<K> listIterator(int index)
AbstractReferenceList
listIterator
in interface ReferenceList<K>
listIterator
in interface java.util.List<K>
listIterator
in class AbstractReferenceList<K>
List.listIterator(int)
public ObjectSpliterator<K> spliterator()
ReferenceList
List spliterators must report at least Spliterator.SIZED
and Spliterator.ORDERED
.
See List.spliterator()
for more documentation on the requirements
of the returned spliterator.
spliterator
in interface ObjectIterable<K>
spliterator
in interface ReferenceCollection<K>
spliterator
in interface ReferenceList<K>
spliterator
in interface java.lang.Iterable<K>
spliterator
in interface java.util.Collection<K>
spliterator
in interface java.util.List<K>
public ReferenceList<K> subList(int from, int to)
from
, inclusive, to the index to
, exclusive.subList
in interface ReferenceList<K>
subList
in interface java.util.List<K>
subList
in class AbstractReferenceList<K>
List.subList(int,int)
ImmutableList
due to complications of implementation details.
This may change in a future version (in other words, do not consider the return type of
this method to be stable if making a subclass of ImmutableList
).public ReferenceImmutableList<K> clone()
clone
in class java.lang.Object
public boolean equals(ReferenceImmutableList<K> l)
l
- a type-specific immutable list.public boolean equals(java.lang.Object o)
equals
in interface java.util.Collection<K>
equals
in interface java.util.List<K>
equals
in class AbstractReferenceList<K>
@Deprecated public final void add(int index, K k)
AbstractReferenceList
add
in interface java.util.List<K>
add
in class AbstractReferenceList<K>
UnsupportedOperationException
as this is an immutable type.@Deprecated public final boolean add(K k)
AbstractReferenceList
add
in interface java.util.Collection<K>
add
in interface java.util.List<K>
add
in class AbstractReferenceList<K>
UnsupportedOperationException
as this is an immutable type.@Deprecated public final boolean addAll(java.util.Collection<? extends K> c)
AbstractReferenceList
addAll
in interface java.util.Collection<K>
addAll
in interface java.util.List<K>
addAll
in class AbstractReferenceList<K>
UnsupportedOperationException
as this is an immutable type.@Deprecated public final boolean addAll(int index, java.util.Collection<? extends K> c)
AbstractReferenceList
addAll
in interface java.util.List<K>
addAll
in class AbstractReferenceList<K>
UnsupportedOperationException
as this is an immutable type.@Deprecated public final K remove(int index)
AbstractReferenceList
remove
in interface java.util.List<K>
remove
in class AbstractReferenceList<K>
UnsupportedOperationException
as this is an immutable type.@Deprecated public final boolean remove(java.lang.Object k)
remove
in interface java.util.Collection<K>
remove
in interface java.util.List<K>
remove
in class java.util.AbstractCollection<K>
UnsupportedOperationException
as this is an immutable type.@Deprecated public final boolean removeAll(java.util.Collection<?> c)
removeAll
in interface java.util.Collection<K>
removeAll
in interface java.util.List<K>
removeAll
in class java.util.AbstractCollection<K>
UnsupportedOperationException
as this is an immutable type.@Deprecated public final boolean retainAll(java.util.Collection<?> c)
retainAll
in interface java.util.Collection<K>
retainAll
in interface java.util.List<K>
retainAll
in class java.util.AbstractCollection<K>
UnsupportedOperationException
as this is an immutable type.@Deprecated public final boolean removeIf(java.util.function.Predicate<? super K> c)
removeIf
in interface java.util.Collection<K>
UnsupportedOperationException
as this is an immutable type.@Deprecated public final void replaceAll(java.util.function.UnaryOperator<K> operator)
replaceAll
in interface java.util.List<K>
UnsupportedOperationException
as this is an immutable type.@Deprecated public final K set(int index, K k)
AbstractReferenceList
set
in interface java.util.List<K>
set
in class AbstractReferenceList<K>
UnsupportedOperationException
as this is an immutable type.@Deprecated public final void clear()
AbstractReferenceList
clear
in interface java.util.Collection<K>
clear
in interface java.util.List<K>
clear
in class AbstractReferenceList<K>
UnsupportedOperationException
as this is an immutable type.@Deprecated public final void size(int size)
ReferenceList
If the specified size is smaller than the current size, the last elements are
discarded. Otherwise, they are filled with 0/null
/false
.
size
in interface ReferenceList<K>
size
in class AbstractReferenceList<K>
size
- the new size.UnsupportedOperationException
as this is an immutable type.@Deprecated public final void removeElements(int from, int to)
AbstractReferenceList
This is a trivial iterator-based based implementation. It is expected that implementations will override this method with a more optimized version.
removeElements
in interface ReferenceList<K>
removeElements
in class AbstractReferenceList<K>
from
- the start index (inclusive).to
- the end index (exclusive).UnsupportedOperationException
as this is an immutable type.@Deprecated public final void addElements(int index, K[] a, int offset, int length)
AbstractReferenceList
This is a trivial iterator-based implementation. It is expected that implementations will override this method with a more optimized version.
addElements
in interface ReferenceList<K>
addElements
in class AbstractReferenceList<K>
index
- the index at which to add elements.a
- the array containing the elements.offset
- the offset of the first element to add.length
- the number of elements to add.UnsupportedOperationException
as this is an immutable type.@Deprecated public final void setElements(int index, K[] a, int offset, int length)
ReferenceList
ListIterator iter = listIterator(index);
int i = 0;
while (i < length) {
iter.next();
iter.set(a[offset + i++]);
}
However, the exact implementation may be more efficient, taking into account
whether random access is faster or not, or at the discretion of subclasses,
abuse internals.setElements
in interface ReferenceList<K>
setElements
in class AbstractReferenceList<K>
index
- the index at which to start setting elements.a
- the array containing the elementsoffset
- the offset of the first element to add.length
- the number of elements to add.UnsupportedOperationException
as this is an immutable type.@Deprecated public final void sort(java.util.Comparator<? super K> comparator)
ReferenceList
Pass null
to sort using natural ordering.
Unless a subclass specifies otherwise, the results of the method if the list is concurrently modified during the sort are unspecified.
sort
in interface ReferenceList<K>
sort
in interface java.util.List<K>
UnsupportedOperationException
as this is an immutable type.@Deprecated public final void unstableSort(java.util.Comparator<? super K> comparator)
ReferenceList
List.sort(java.util.Comparator)
in that the results are
not assured to be stable, but may be a bit faster.
Pass null
to sort using natural ordering.
Unless a subclass specifies otherwise, the results of the method if the list is concurrently modified during the sort are unspecified.
unstableSort
in interface ReferenceList<K>
UnsupportedOperationException
as this is an immutable type.