public class IntImmutableList extends AbstractIntList implements IntList, 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.
AbstractIntList.IntRandomAccessSubList, AbstractIntList.IntSubList
Constructor and Description |
---|
IntImmutableList(java.util.Collection<? extends java.lang.Integer> c)
Creates a new immutable list and fills it with a given collection.
|
IntImmutableList(int[] a)
Creates a new immutable list using a given array.
|
IntImmutableList(int[] a,
int offset,
int length)
Creates a new immutable list and fills it with the elements of a given array.
|
IntImmutableList(IntCollection c)
Creates a new immutable list and fills it with a given type-specific collection.
|
IntImmutableList(IntIterator i)
Creates a new immutable list and fills it with the elements returned by a type-specific iterator..
|
IntImmutableList(IntList l)
Creates a new immutable list and fills it with a given type-specific list.
|
Modifier and Type | Method and Description |
---|---|
boolean |
add(int k)
Deprecated.
|
boolean |
add(java.lang.Integer k)
Deprecated.
|
void |
add(int index,
int k)
Deprecated.
|
void |
add(int index,
java.lang.Integer k)
Deprecated.
|
boolean |
addAll(java.util.Collection<? extends java.lang.Integer> c)
Deprecated.
|
boolean |
addAll(IntCollection c)
Deprecated.
|
boolean |
addAll(int index,
java.util.Collection<? extends java.lang.Integer> c)
Deprecated.
|
boolean |
addAll(int index,
IntCollection c)
Deprecated.
|
boolean |
addAll(int index,
IntList c)
Deprecated.
|
boolean |
addAll(IntList c)
Deprecated.
|
void |
addElements(int index,
int[] a,
int offset,
int length)
Deprecated.
|
void |
clear()
Deprecated.
|
IntImmutableList |
clone() |
int |
compareTo(IntImmutableList l)
Compares this immutable list to another immutable list.
|
int |
compareTo(java.util.List<? extends java.lang.Integer> l)
Compares this list to another object.
|
boolean |
equals(IntImmutableList l)
Compares this type-specific immutable list to another one.
|
boolean |
equals(java.lang.Object o) |
void |
forEach(java.util.function.IntConsumer action)
Performs the given action for each element of this type-specific
Iterable
until all elements have been processed or the action throws an
exception. |
void |
getElements(int from,
int[] a,
int offset,
int length)
Copies element of this type-specific list into the given array using optimized system calls.
|
int |
getInt(int index)
Returns the element at the specified position in this list.
|
int |
indexOf(int k)
Returns the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element.
|
boolean |
isEmpty()
Checks whether the stack is empty.
|
int |
lastIndexOf(int k)
Returns the index of the last occurrence of the specified element in this list, or -1 if this list does not contain the element.
|
IntListIterator |
listIterator(int index)
Returns a type-specific list iterator on the list starting at a given index.
|
static IntImmutableList |
of()
Returns an empty immutable list.
|
static IntImmutableList |
of(int... init)
Creates an immutable list using a list of elements.
|
boolean |
rem(int k)
Deprecated.
|
java.lang.Integer |
remove(int index)
Deprecated.
|
boolean |
remove(java.lang.Object k)
Deprecated.
|
boolean |
removeAll(java.util.Collection<?> c)
Deprecated.
|
boolean |
removeAll(IntCollection c)
Deprecated.
|
void |
removeElements(int from,
int to)
Deprecated.
|
boolean |
removeIf(java.util.function.IntPredicate c)
Deprecated.
|
boolean |
removeIf(java.util.function.Predicate<? super java.lang.Integer> c)
Deprecated.
|
int |
removeInt(int index)
Deprecated.
|
void |
replaceAll(java.util.function.IntUnaryOperator operator)
Deprecated.
|
void |
replaceAll(java.util.function.UnaryOperator<java.lang.Integer> operator)
Deprecated.
|
boolean |
retainAll(java.util.Collection<?> c)
Deprecated.
|
boolean |
retainAll(IntCollection c)
Deprecated.
|
int |
set(int index,
int k)
Deprecated.
|
java.lang.Integer |
set(int index,
java.lang.Integer k)
Deprecated.
|
void |
setElements(int index,
int[] a,
int offset,
int length)
Deprecated.
|
int |
size() |
void |
size(int size)
Deprecated.
|
void |
sort(java.util.Comparator<? super java.lang.Integer> comparator)
Deprecated.
|
void |
sort(IntComparator comp)
Deprecated.
|
IntSpliterator |
spliterator()
Returns a type-specific spliterator on the elements of this list.
|
IntList |
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. |
int[] |
toArray(int[] a)
Returns an array containing all of the elements in this collection; the runtime type of the returned array is that of the specified array.
|
int[] |
toIntArray()
Returns a primitive type array containing the items of this collection.
|
static IntImmutableList |
toList(java.util.stream.IntStream stream)
Collects the result of a primitive
Stream into a new ImmutableList. |
static IntImmutableList |
toListWithExpectedSize(java.util.stream.IntStream stream,
int expectedSize)
Collects the result of a primitive
Stream into a new ImmutableList, potentially pre-allocated to handle the given size. |
void |
unstableSort(java.util.Comparator<? super java.lang.Integer> comparator)
Deprecated.
|
void |
unstableSort(IntComparator comp)
Deprecated.
|
addElements, contains, hashCode, iterator, listIterator, peekInt, popInt, push, replaceAll, topInt, toString
contains, containsAll, containsAll, forEach, removeIf, toIntArray
add, add, add, add, addAll, addAll, addAll, addElements, addElements, contains, get, indexOf, iterator, lastIndexOf, listIterator, of, of, of, remove, remove, removeElements, removeInt, replaceAll, replaceAll, replaceAll, set, set, setElements, setElements, setElements, size, sort, sort, unstableSort, unstableSort
addAll, addAll, clear, containsAll, hashCode, removeAll, retainAll, toArray, toArray
addAll, contains, containsAll, intIterator, intParallelStream, intSpliterator, intStream, parallelStream, rem, removeAll, removeIf, removeIf, removeIf, retainAll, stream, toIntArray
forEach, forEach
public IntImmutableList(int[] a)
Note that this constructor does not perform a defensive copy.
a
- the array that will be used to back this immutable list.public IntImmutableList(java.util.Collection<? extends java.lang.Integer> c)
c
- a collection that will be used to fill the immutable list.public IntImmutableList(IntCollection c)
c
- a type-specific collection that will be used to fill the immutable list.public IntImmutableList(IntList l)
l
- a type-specific list that will be used to fill the immutable list.public IntImmutableList(int[] 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 IntImmutableList(IntIterator i)
i
- a type-specific iterator whose returned elements will fill the immutable list.public static IntImmutableList of()
public static IntImmutableList of(int... init)
Note that this method does not perform a defensive copy.
public static IntImmutableList toList(java.util.stream.IntStream stream)
Stream
into a new ImmutableList.
This method performs a terminal operation on the given Stream
Collector
is necessary because there is no
primitive Collector
equivalent in the Java API.public static IntImmutableList toListWithExpectedSize(java.util.stream.IntStream stream, int expectedSize)
Stream
into a new ImmutableList, potentially pre-allocated to handle the given size.
This method performs a terminal operation on the given Stream
Collector
is necessary because there is no
primitive Collector
equivalent in the Java API.public int getInt(int index)
IntList
public int indexOf(int k)
IntList
indexOf
in interface IntList
indexOf
in class AbstractIntList
List.indexOf(Object)
public int lastIndexOf(int k)
IntList
lastIndexOf
in interface IntList
lastIndexOf
in class AbstractIntList
List.lastIndexOf(Object)
public int size()
size
in interface java.util.Collection<java.lang.Integer>
size
in interface java.util.List<java.lang.Integer>
size
in class java.util.AbstractCollection<java.lang.Integer>
public boolean isEmpty()
Stack
isEmpty
in interface Stack<java.lang.Integer>
isEmpty
in interface java.util.Collection<java.lang.Integer>
isEmpty
in interface java.util.List<java.lang.Integer>
isEmpty
in class java.util.AbstractCollection<java.lang.Integer>
public void getElements(int from, int[] a, int offset, int length)
getElements
in interface IntList
getElements
in class AbstractIntList
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.IntConsumer action)
AbstractIntList
Iterable
until all elements have been processed or the action throws an
exception.forEach
in interface IntIterable
forEach
in class AbstractIntList
action
- the action to be performed for each element.Iterable.forEach(java.util.function.Consumer)
public int[] toIntArray()
IntCollection
toIntArray
in interface IntCollection
toIntArray
in class AbstractIntList
Collection.toArray()
public int[] toArray(int[] a)
IntCollection
Note that, contrarily to Collection.toArray(Object[])
, this
methods just writes all elements of this collection: no special
value will be added after the last one.
toArray
in interface IntCollection
toArray
in class AbstractIntList
a
- if this array is big enough, it will be used to store this collection.Collection.toArray(Object[])
public IntListIterator listIterator(int index)
AbstractIntList
listIterator
in interface IntList
listIterator
in interface java.util.List<java.lang.Integer>
listIterator
in class AbstractIntList
List.listIterator(int)
public IntSpliterator spliterator()
IntList
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 IntCollection
spliterator
in interface IntIterable
spliterator
in interface IntList
spliterator
in interface java.lang.Iterable<java.lang.Integer>
spliterator
in interface java.util.Collection<java.lang.Integer>
spliterator
in interface java.util.List<java.lang.Integer>
public IntList subList(int from, int to)
from
, inclusive, to the index to
, exclusive.subList
in interface IntList
subList
in interface java.util.List<java.lang.Integer>
subList
in class AbstractIntList
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 IntImmutableList clone()
clone
in class java.lang.Object
public boolean equals(IntImmutableList l)
l
- a type-specific immutable list.public boolean equals(java.lang.Object o)
equals
in interface java.util.Collection<java.lang.Integer>
equals
in interface java.util.List<java.lang.Integer>
equals
in class AbstractIntList
public int compareTo(IntImmutableList l)
l
- an immutable list.public int compareTo(java.util.List<? extends java.lang.Integer> l)
AbstractIntList
List
, this method performs a lexicographical comparison; otherwise,
it throws a ClassCastException
.compareTo
in interface java.lang.Comparable<java.util.List<? extends java.lang.Integer>>
compareTo
in class AbstractIntList
l
- a list.List
, a negative integer,
zero, or a positive integer as this list is lexicographically less than, equal
to, or greater than the argument.@Deprecated public final void add(int index, int k)
AbstractIntList
add
in interface IntList
add
in class AbstractIntList
List.add(int,Object)
UnsupportedOperationException
as this is an immutable type.@Deprecated public final boolean add(int k)
AbstractIntList
add
in interface IntCollection
add
in interface IntList
add
in class AbstractIntList
Collection.add(Object)
UnsupportedOperationException
as this is an immutable type.@Deprecated public final boolean addAll(java.util.Collection<? extends java.lang.Integer> c)
AbstractIntList
addAll
in interface java.util.Collection<java.lang.Integer>
addAll
in interface java.util.List<java.lang.Integer>
addAll
in class AbstractIntList
UnsupportedOperationException
as this is an immutable type.@Deprecated public final boolean addAll(int index, java.util.Collection<? extends java.lang.Integer> c)
AbstractIntList
addAll
in interface java.util.List<java.lang.Integer>
addAll
in class AbstractIntList
UnsupportedOperationException
as this is an immutable type.@Deprecated public final int removeInt(int index)
AbstractIntList
removeInt
in interface IntList
removeInt
in class AbstractIntList
List.remove(int)
UnsupportedOperationException
as this is an immutable type.@Deprecated public final boolean rem(int k)
AbstractIntList
rem
in interface IntCollection
rem
in class AbstractIntList
List.remove(Object)
UnsupportedOperationException
as this is an immutable type.@Deprecated public final boolean removeAll(java.util.Collection<?> c)
AbstractIntCollection
removeAll
in interface java.util.Collection<java.lang.Integer>
removeAll
in interface java.util.List<java.lang.Integer>
removeAll
in class AbstractIntCollection
UnsupportedOperationException
as this is an immutable type.@Deprecated public final boolean retainAll(java.util.Collection<?> c)
AbstractIntCollection
retainAll
in interface java.util.Collection<java.lang.Integer>
retainAll
in interface java.util.List<java.lang.Integer>
retainAll
in class AbstractIntCollection
UnsupportedOperationException
as this is an immutable type.@Deprecated public final boolean removeIf(java.util.function.Predicate<? super java.lang.Integer> c)
IntCollection
removeIf
in interface IntCollection
removeIf
in interface java.util.Collection<java.lang.Integer>
UnsupportedOperationException
as this is an immutable type.@Deprecated public final boolean removeIf(java.util.function.IntPredicate c)
IntCollection
removeIf
in interface IntCollection
c
- a predicate which returns true
for elements to be
removed.true
if any elements were removed.Collection.removeIf(java.util.function.Predicate)
UnsupportedOperationException
as this is an immutable type.@Deprecated public final void replaceAll(java.util.function.UnaryOperator<java.lang.Integer> operator)
IntList
replaceAll
in interface IntList
replaceAll
in interface java.util.List<java.lang.Integer>
UnsupportedOperationException
as this is an immutable type.@Deprecated public final void replaceAll(java.util.function.IntUnaryOperator operator)
IntList
replaceAll
in interface IntList
operator
- the operator to apply to each element.List.replaceAll(java.util.function.UnaryOperator<E>)
UnsupportedOperationException
as this is an immutable type.@Deprecated public final void add(int index, java.lang.Integer k)
IntList
@Deprecated public final boolean add(java.lang.Integer k)
AbstractIntCollection
add
in interface IntCollection
add
in interface IntList
add
in interface java.util.Collection<java.lang.Integer>
add
in interface java.util.List<java.lang.Integer>
add
in class AbstractIntCollection
UnsupportedOperationException
as this is an immutable type.@Deprecated public final java.lang.Integer remove(int index)
IntList
@Deprecated public final boolean remove(java.lang.Object k)
AbstractIntCollection
remove
in interface IntCollection
remove
in interface IntList
remove
in interface java.util.Collection<java.lang.Integer>
remove
in interface java.util.List<java.lang.Integer>
remove
in class AbstractIntCollection
UnsupportedOperationException
as this is an immutable type.@Deprecated public final java.lang.Integer set(int index, java.lang.Integer k)
IntList
@Deprecated public final boolean addAll(IntCollection c)
AbstractIntList
addAll
in interface IntCollection
addAll
in class AbstractIntList
c
- a type-specific collection.true
if this collection changed as a result of the call.Collection.addAll(Collection)
UnsupportedOperationException
as this is an immutable type.@Deprecated public final boolean addAll(IntList c)
IntList
@Deprecated public final boolean addAll(int index, IntCollection c)
IntList
addAll
in interface IntList
addAll
in class AbstractIntList
List.addAll(int,java.util.Collection)
UnsupportedOperationException
as this is an immutable type.@Deprecated public final boolean addAll(int index, IntList c)
IntList
@Deprecated public final boolean removeAll(IntCollection c)
IntCollection
removeAll
in interface IntCollection
removeAll
in class AbstractIntCollection
c
- a type-specific collection.true
if this collection changed as a result of the call.Collection.removeAll(Collection)
UnsupportedOperationException
as this is an immutable type.@Deprecated public final boolean retainAll(IntCollection c)
IntCollection
retainAll
in interface IntCollection
retainAll
in class AbstractIntCollection
c
- a type-specific collection.true
if this collection changed as a result of the call.Collection.retainAll(Collection)
UnsupportedOperationException
as this is an immutable type.@Deprecated public final int set(int index, int k)
AbstractIntList
set
in interface IntList
set
in class AbstractIntList
List.set(int,Object)
UnsupportedOperationException
as this is an immutable type.@Deprecated public final void clear()
AbstractIntList
clear
in interface java.util.Collection<java.lang.Integer>
clear
in interface java.util.List<java.lang.Integer>
clear
in class AbstractIntList
UnsupportedOperationException
as this is an immutable type.@Deprecated public final void size(int size)
IntList
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 IntList
size
in class AbstractIntList
size
- the new size.UnsupportedOperationException
as this is an immutable type.@Deprecated public final void removeElements(int from, int to)
AbstractIntList
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 IntList
removeElements
in class AbstractIntList
from
- the start index (inclusive).to
- the end index (exclusive).UnsupportedOperationException
as this is an immutable type.@Deprecated public final void addElements(int index, int[] a, int offset, int length)
AbstractIntList
This is a trivial iterator-based implementation. It is expected that implementations will override this method with a more optimized version.
addElements
in interface IntList
addElements
in class AbstractIntList
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, int[] a, int offset, int length)
IntList
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 IntList
setElements
in class AbstractIntList
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(IntComparator comp)
IntList
Pass null
to sort using natural ordering.
@Deprecated public final void unstableSort(IntComparator comp)
IntList
Pass null
to sort using natural ordering.
This differs from List.sort(java.util.Comparator)
in that the results are
not assured to be stable, but may be a bit faster.
Unless a subclass specifies otherwise, the results of the method if the list is concurrently modified during the sort are unspecified.
unstableSort
in interface IntList
UnsupportedOperationException
as this is an immutable type.@Deprecated public final void sort(java.util.Comparator<? super java.lang.Integer> comparator)
IntList
@Deprecated public final void unstableSort(java.util.Comparator<? super java.lang.Integer> comparator)
IntList
unstableSort
in interface IntList
UnsupportedOperationException
as this is an immutable type.