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(it.unimi.dsi.fastutil.ints.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() |
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(it.unimi.dsi.fastutil.ints.IntComparator comp)
Deprecated.
|
it.unimi.dsi.fastutil.ints.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(it.unimi.dsi.fastutil.ints.IntComparator comp)
Deprecated.
|
addElements, contains, ensureIndex, ensureRestrictedIndex, hashCode, iterator, listIterator, peekInt, popInt, push, replaceAll, topInt, toStringcontains, containsAll, containsAll, forEach, removeIf, toIntArrayfinalize, getClass, notify, notifyAll, wait, wait, waitadd, 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, unstableSortaddAll, addAll, clear, containsAll, hashCode, removeAll, retainAll, toArray, toArrayaddAll, contains, containsAll, intIterator, intParallelStream, intSpliterator, intStream, parallelStream, rem, removeAll, removeIf, removeIf, removeIf, retainAll, stream, toIntArrayforEach, forEachpublic 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(it.unimi.dsi.fastutil.ints.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
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
public int getInt(int index)
IntListpublic int indexOf(int k)
IntListindexOf in interface IntListindexOf in class AbstractIntListList.indexOf(Object)public int lastIndexOf(int k)
IntListlastIndexOf in interface IntListlastIndexOf in class AbstractIntListList.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()
isEmpty in interface it.unimi.dsi.fastutil.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 IntListgetElements in class AbstractIntListfrom - 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)
AbstractIntListIterable
until all elements have been processed or the action throws an
exception.forEach in interface IntIterableforEach in class AbstractIntListaction - the action to be performed for each element.Iterable.forEach(java.util.function.Consumer)public int[] toIntArray()
IntCollectiontoIntArray in interface IntCollectiontoIntArray in class AbstractIntListCollection.toArray()public int[] toArray(int[] a)
IntCollectionNote 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 IntCollectiontoArray in class AbstractIntLista - if this array is big enough, it will be used to store this collection.Collection.toArray(Object[])public IntListIterator listIterator(int index)
AbstractIntListlistIterator in interface IntListlistIterator in interface java.util.List<java.lang.Integer>listIterator in class AbstractIntListList.listIterator(int)public it.unimi.dsi.fastutil.ints.IntSpliterator spliterator()
IntListList 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 IntCollectionspliterator in interface IntIterablespliterator in interface IntListspliterator 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 IntListsubList in interface java.util.List<java.lang.Integer>subList in class AbstractIntListList.subList(int,int)public IntImmutableList clone()
clone in class java.lang.Objectpublic 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 AbstractIntListpublic int compareTo(IntImmutableList l)
l - an immutable list.public int compareTo(java.util.List<? extends java.lang.Integer> l)
AbstractIntListList, 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 AbstractIntListl - 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)
AbstractIntListadd in interface IntListadd in class AbstractIntListList.add(int,Object)@Deprecated public final boolean add(int k)
AbstractIntListadd in interface IntCollectionadd in interface IntListadd in class AbstractIntListCollection.add(Object)@Deprecated public final boolean addAll(java.util.Collection<? extends java.lang.Integer> c)
AbstractIntListaddAll in interface java.util.Collection<java.lang.Integer>addAll in interface java.util.List<java.lang.Integer>addAll in class AbstractIntList@Deprecated
public final boolean addAll(int index,
java.util.Collection<? extends java.lang.Integer> c)
AbstractIntListaddAll in interface java.util.List<java.lang.Integer>addAll in class AbstractIntList@Deprecated public final int removeInt(int index)
AbstractIntListremoveInt in interface IntListremoveInt in class AbstractIntListList.remove(int)@Deprecated public final boolean rem(int k)
AbstractIntListrem in interface IntCollectionrem in class AbstractIntListList.remove(Object)@Deprecated public final boolean removeAll(java.util.Collection<?> c)
AbstractIntCollectionremoveAll in interface java.util.Collection<java.lang.Integer>removeAll in interface java.util.List<java.lang.Integer>removeAll in class AbstractIntCollection@Deprecated public final boolean retainAll(java.util.Collection<?> c)
AbstractIntCollectionretainAll in interface java.util.Collection<java.lang.Integer>retainAll in interface java.util.List<java.lang.Integer>retainAll in class AbstractIntCollection@Deprecated public final boolean removeIf(java.util.function.Predicate<? super java.lang.Integer> c)
IntCollectionremoveIf in interface IntCollectionremoveIf in interface java.util.Collection<java.lang.Integer>@Deprecated public final boolean removeIf(java.util.function.IntPredicate c)
IntCollectionremoveIf in interface IntCollectionc - a predicate which returns true for elements to be
removed.true if any elements were removed.Collection.removeIf(java.util.function.Predicate)@Deprecated public final void replaceAll(java.util.function.UnaryOperator<java.lang.Integer> operator)
IntListreplaceAll in interface IntListreplaceAll in interface java.util.List<java.lang.Integer>@Deprecated public final void replaceAll(java.util.function.IntUnaryOperator operator)
IntListreplaceAll in interface IntListoperator - the operator to apply to each element.List.replaceAll(java.util.function.UnaryOperator<E>)@Deprecated
public final void add(int index,
java.lang.Integer k)
IntList@Deprecated public final boolean add(java.lang.Integer k)
AbstractIntCollectionadd in interface IntCollectionadd in interface IntListadd in interface java.util.Collection<java.lang.Integer>add in interface java.util.List<java.lang.Integer>add in class AbstractIntCollection@Deprecated public final java.lang.Integer remove(int index)
IntList@Deprecated public final boolean remove(java.lang.Object k)
AbstractIntCollectionremove in interface IntCollectionremove in interface IntListremove in interface java.util.Collection<java.lang.Integer>remove in interface java.util.List<java.lang.Integer>remove in class AbstractIntCollection@Deprecated
public final java.lang.Integer set(int index,
java.lang.Integer k)
IntList@Deprecated public final boolean addAll(IntCollection c)
AbstractIntListaddAll in interface IntCollectionaddAll in class AbstractIntListc - a type-specific collection.true if this collection changed as a result of the call.Collection.addAll(Collection)@Deprecated public final boolean addAll(IntList c)
IntList@Deprecated
public final boolean addAll(int index,
IntCollection c)
IntListaddAll in interface IntListaddAll in class AbstractIntListList.addAll(int,java.util.Collection)@Deprecated
public final boolean addAll(int index,
IntList c)
IntList@Deprecated public final boolean removeAll(IntCollection c)
IntCollectionremoveAll in interface IntCollectionremoveAll in class AbstractIntCollectionc - a type-specific collection.true if this collection changed as a result of the call.Collection.removeAll(Collection)@Deprecated public final boolean retainAll(IntCollection c)
IntCollectionretainAll in interface IntCollectionretainAll in class AbstractIntCollectionc - a type-specific collection.true if this collection changed as a result of the call.Collection.retainAll(Collection)@Deprecated
public final int set(int index,
int k)
AbstractIntListset in interface IntListset in class AbstractIntListList.set(int,Object)@Deprecated public final void clear()
AbstractIntListclear in interface java.util.Collection<java.lang.Integer>clear in interface java.util.List<java.lang.Integer>clear in class AbstractIntList@Deprecated public final void size(int size)
IntListIf 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 IntListsize in class AbstractIntListsize - the new size.@Deprecated
public final void removeElements(int from,
int to)
AbstractIntListThis is a trivial iterator-based based implementation. It is expected that implementations will override this method with a more optimized version.
removeElements in interface IntListremoveElements in class AbstractIntListfrom - the start index (inclusive).to - the end index (exclusive).@Deprecated
public final void addElements(int index,
int[] a,
int offset,
int length)
AbstractIntListThis is a trivial iterator-based implementation. It is expected that implementations will override this method with a more optimized version.
addElements in interface IntListaddElements in class AbstractIntListindex - 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.@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 IntListsetElements in class AbstractIntListindex - 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.@Deprecated public final void sort(it.unimi.dsi.fastutil.ints.IntComparator comp)
IntListPass null to sort using natural ordering.
@Deprecated public final void unstableSort(it.unimi.dsi.fastutil.ints.IntComparator comp)
IntListPass 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@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)
IntListunstableSort in interface IntList