public class LongImmutableList extends AbstractLongList implements LongList, 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.
AbstractLongList.LongRandomAccessSubList, AbstractLongList.LongSubList| Constructor and Description |
|---|
LongImmutableList(java.util.Collection<? extends java.lang.Long> c)
Creates a new immutable list and fills it with a given collection.
|
LongImmutableList(long[] a)
Creates a new immutable list using a given array.
|
LongImmutableList(long[] a,
int offset,
int length)
Creates a new immutable list and fills it with the elements of a given array.
|
LongImmutableList(LongCollection c)
Creates a new immutable list and fills it with a given type-specific collection.
|
LongImmutableList(it.unimi.dsi.fastutil.longs.LongIterator i)
Creates a new immutable list and fills it with the elements returned by a type-specific iterator..
|
LongImmutableList(LongList 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,
long k)
Deprecated.
|
void |
add(int index,
java.lang.Long k)
Deprecated.
|
boolean |
add(long k)
Deprecated.
|
boolean |
add(java.lang.Long k)
Deprecated.
|
boolean |
addAll(java.util.Collection<? extends java.lang.Long> c)
Deprecated.
|
boolean |
addAll(int index,
java.util.Collection<? extends java.lang.Long> c)
Deprecated.
|
boolean |
addAll(int index,
LongCollection c)
Deprecated.
|
boolean |
addAll(int index,
LongList c)
Deprecated.
|
boolean |
addAll(LongCollection c)
Deprecated.
|
boolean |
addAll(LongList c)
Deprecated.
|
void |
addElements(int index,
long[] a,
int offset,
int length)
Deprecated.
|
void |
clear()
Deprecated.
|
LongImmutableList |
clone() |
int |
compareTo(java.util.List<? extends java.lang.Long> l)
Compares this list to another object.
|
int |
compareTo(LongImmutableList l)
Compares this immutable list to another immutable list.
|
boolean |
equals(LongImmutableList l)
Compares this type-specific immutable list to another one.
|
boolean |
equals(java.lang.Object o) |
void |
forEach(java.util.function.LongConsumer 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,
long[] a,
int offset,
int length)
Copies element of this type-specific list into the given array using optimized system calls.
|
long |
getLong(int index)
Returns the element at the specified position in this list.
|
int |
indexOf(long 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(long 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.
|
LongListIterator |
listIterator(int index)
Returns a type-specific list iterator on the list starting at a given index.
|
static LongImmutableList |
of()
Returns an empty immutable list.
|
static LongImmutableList |
of(long... init)
Creates an immutable list using a list of elements.
|
boolean |
rem(long k)
Deprecated.
|
java.lang.Long |
remove(int index)
Deprecated.
|
boolean |
remove(java.lang.Object k)
Deprecated.
|
boolean |
removeAll(java.util.Collection<?> c)
Deprecated.
|
boolean |
removeAll(LongCollection c)
Deprecated.
|
void |
removeElements(int from,
int to)
Deprecated.
|
boolean |
removeIf(java.util.function.LongPredicate c)
Deprecated.
|
boolean |
removeIf(java.util.function.Predicate<? super java.lang.Long> c)
Deprecated.
|
long |
removeLong(int index)
Deprecated.
|
void |
replaceAll(java.util.function.LongUnaryOperator operator)
Deprecated.
|
void |
replaceAll(java.util.function.UnaryOperator<java.lang.Long> operator)
Deprecated.
|
boolean |
retainAll(java.util.Collection<?> c)
Deprecated.
|
boolean |
retainAll(LongCollection c)
Deprecated.
|
long |
set(int index,
long k)
Deprecated.
|
java.lang.Long |
set(int index,
java.lang.Long k)
Deprecated.
|
void |
setElements(int index,
long[] a,
int offset,
int length)
Deprecated.
|
int |
size() |
void |
size(int size)
Deprecated.
|
void |
sort(java.util.Comparator<? super java.lang.Long> comparator)
Deprecated.
|
void |
sort(it.unimi.dsi.fastutil.longs.LongComparator comp)
Deprecated.
|
it.unimi.dsi.fastutil.longs.LongSpliterator |
spliterator()
Returns a type-specific spliterator on the elements of this list.
|
LongList |
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. |
long[] |
toArray(long[] 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.
|
static LongImmutableList |
toList(java.util.stream.LongStream stream)
Collects the result of a primitive
Stream into a new ImmutableList. |
static LongImmutableList |
toListWithExpectedSize(java.util.stream.LongStream stream,
int expectedSize)
Collects the result of a primitive
Stream into a new ImmutableList, potentially pre-allocated to handle the given size. |
long[] |
toLongArray()
Returns a primitive type array containing the items of this collection.
|
void |
unstableSort(java.util.Comparator<? super java.lang.Long> comparator)
Deprecated.
|
void |
unstableSort(it.unimi.dsi.fastutil.longs.LongComparator comp)
Deprecated.
|
addElements, contains, ensureIndex, ensureRestrictedIndex, hashCode, iterator, listIterator, peekLong, popLong, push, replaceAll, topLong, toStringcontains, containsAll, containsAll, forEach, removeIf, toLongArrayfinalize, 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, removeLong, replaceAll, replaceAll, replaceAll, set, set, setElements, setElements, setElements, size, sort, sort, unstableSort, unstableSortaddAll, addAll, clear, containsAll, hashCode, removeAll, retainAll, toArray, toArrayaddAll, contains, containsAll, longIterator, longParallelStream, longSpliterator, longStream, parallelStream, rem, removeAll, removeIf, removeIf, removeIf, retainAll, stream, toLongArrayforEach, forEachpublic LongImmutableList(long[] a)
Note that this constructor does not perform a defensive copy.
a - the array that will be used to back this immutable list.public LongImmutableList(java.util.Collection<? extends java.lang.Long> c)
c - a collection that will be used to fill the immutable list.public LongImmutableList(LongCollection c)
c - a type-specific collection that will be used to fill the immutable list.public LongImmutableList(LongList l)
l - a type-specific list that will be used to fill the immutable list.public LongImmutableList(long[] 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 LongImmutableList(it.unimi.dsi.fastutil.longs.LongIterator i)
i - a type-specific iterator whose returned elements will fill the immutable list.public static LongImmutableList of()
public static LongImmutableList of(long... init)
Note that this method does not perform a defensive copy.
public static LongImmutableList toList(java.util.stream.LongStream stream)
Stream into a new ImmutableList.
This method performs a terminal operation on the given Stream
public static LongImmutableList toListWithExpectedSize(java.util.stream.LongStream 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 long getLong(int index)
LongListpublic int indexOf(long k)
LongListindexOf in interface LongListindexOf in class AbstractLongListList.indexOf(Object)public int lastIndexOf(long k)
LongListlastIndexOf in interface LongListlastIndexOf in class AbstractLongListList.lastIndexOf(Object)public int size()
size in interface java.util.Collection<java.lang.Long>size in interface java.util.List<java.lang.Long>size in class java.util.AbstractCollection<java.lang.Long>public boolean isEmpty()
isEmpty in interface it.unimi.dsi.fastutil.Stack<java.lang.Long>isEmpty in interface java.util.Collection<java.lang.Long>isEmpty in interface java.util.List<java.lang.Long>isEmpty in class java.util.AbstractCollection<java.lang.Long>public void getElements(int from,
long[] a,
int offset,
int length)
getElements in interface LongListgetElements in class AbstractLongListfrom - 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.LongConsumer action)
AbstractLongListIterable
until all elements have been processed or the action throws an
exception.forEach in interface LongIterableforEach in class AbstractLongListaction - the action to be performed for each element.Iterable.forEach(java.util.function.Consumer)public long[] toLongArray()
LongCollectiontoLongArray in interface LongCollectiontoLongArray in class AbstractLongListCollection.toArray()public long[] toArray(long[] a)
LongCollectionNote 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 LongCollectiontoArray in class AbstractLongLista - if this array is big enough, it will be used to store this collection.Collection.toArray(Object[])public LongListIterator listIterator(int index)
AbstractLongListlistIterator in interface LongListlistIterator in interface java.util.List<java.lang.Long>listIterator in class AbstractLongListList.listIterator(int)public it.unimi.dsi.fastutil.longs.LongSpliterator spliterator()
LongListList 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 LongCollectionspliterator in interface LongIterablespliterator in interface LongListspliterator in interface java.lang.Iterable<java.lang.Long>spliterator in interface java.util.Collection<java.lang.Long>spliterator in interface java.util.List<java.lang.Long>public LongList subList(int from, int to)
from, inclusive, to the index to, exclusive.subList in interface LongListsubList in interface java.util.List<java.lang.Long>subList in class AbstractLongListList.subList(int,int)public LongImmutableList clone()
clone in class java.lang.Objectpublic boolean equals(LongImmutableList l)
l - a type-specific immutable list.public boolean equals(java.lang.Object o)
equals in interface java.util.Collection<java.lang.Long>equals in interface java.util.List<java.lang.Long>equals in class AbstractLongListpublic int compareTo(LongImmutableList l)
l - an immutable list.public int compareTo(java.util.List<? extends java.lang.Long> l)
AbstractLongListList, this method performs a lexicographical comparison; otherwise,
it throws a ClassCastException.compareTo in interface java.lang.Comparable<java.util.List<? extends java.lang.Long>>compareTo in class AbstractLongListl - 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,
long k)
AbstractLongListadd in interface LongListadd in class AbstractLongListList.add(int,Object)@Deprecated public final boolean add(long k)
AbstractLongListadd in interface LongCollectionadd in interface LongListadd in class AbstractLongListCollection.add(Object)@Deprecated public final boolean addAll(java.util.Collection<? extends java.lang.Long> c)
AbstractLongListaddAll in interface java.util.Collection<java.lang.Long>addAll in interface java.util.List<java.lang.Long>addAll in class AbstractLongList@Deprecated
public final boolean addAll(int index,
java.util.Collection<? extends java.lang.Long> c)
AbstractLongListaddAll in interface java.util.List<java.lang.Long>addAll in class AbstractLongList@Deprecated public final long removeLong(int index)
AbstractLongListremoveLong in interface LongListremoveLong in class AbstractLongListList.remove(int)@Deprecated public final boolean rem(long k)
AbstractLongListrem in interface LongCollectionrem in class AbstractLongListList.remove(Object)@Deprecated public final boolean removeAll(java.util.Collection<?> c)
AbstractLongCollectionremoveAll in interface java.util.Collection<java.lang.Long>removeAll in interface java.util.List<java.lang.Long>removeAll in class AbstractLongCollection@Deprecated public final boolean retainAll(java.util.Collection<?> c)
AbstractLongCollectionretainAll in interface java.util.Collection<java.lang.Long>retainAll in interface java.util.List<java.lang.Long>retainAll in class AbstractLongCollection@Deprecated public final boolean removeIf(java.util.function.Predicate<? super java.lang.Long> c)
LongCollectionremoveIf in interface LongCollectionremoveIf in interface java.util.Collection<java.lang.Long>@Deprecated public final boolean removeIf(java.util.function.LongPredicate c)
LongCollectionremoveIf in interface LongCollectionc - 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.Long> operator)
LongListreplaceAll in interface LongListreplaceAll in interface java.util.List<java.lang.Long>@Deprecated public final void replaceAll(java.util.function.LongUnaryOperator operator)
LongListreplaceAll in interface LongListoperator - the operator to apply to each element.List.replaceAll(java.util.function.UnaryOperator<E>)@Deprecated
public final void add(int index,
java.lang.Long k)
LongList@Deprecated public final boolean add(java.lang.Long k)
AbstractLongCollectionadd in interface LongCollectionadd in interface LongListadd in interface java.util.Collection<java.lang.Long>add in interface java.util.List<java.lang.Long>add in class AbstractLongCollection@Deprecated public final java.lang.Long remove(int index)
LongList@Deprecated public final boolean remove(java.lang.Object k)
AbstractLongCollectionremove in interface LongCollectionremove in interface LongListremove in interface java.util.Collection<java.lang.Long>remove in interface java.util.List<java.lang.Long>remove in class AbstractLongCollection@Deprecated
public final java.lang.Long set(int index,
java.lang.Long k)
LongList@Deprecated public final boolean addAll(LongCollection c)
AbstractLongListaddAll in interface LongCollectionaddAll in class AbstractLongListc - a type-specific collection.true if this collection changed as a result of the call.Collection.addAll(Collection)@Deprecated public final boolean addAll(LongList c)
LongList@Deprecated
public final boolean addAll(int index,
LongCollection c)
LongListaddAll in interface LongListaddAll in class AbstractLongListList.addAll(int,java.util.Collection)@Deprecated
public final boolean addAll(int index,
LongList c)
LongList@Deprecated public final boolean removeAll(LongCollection c)
LongCollectionremoveAll in interface LongCollectionremoveAll in class AbstractLongCollectionc - a type-specific collection.true if this collection changed as a result of the call.Collection.removeAll(Collection)@Deprecated public final boolean retainAll(LongCollection c)
LongCollectionretainAll in interface LongCollectionretainAll in class AbstractLongCollectionc - a type-specific collection.true if this collection changed as a result of the call.Collection.retainAll(Collection)@Deprecated
public final long set(int index,
long k)
AbstractLongListset in interface LongListset in class AbstractLongListList.set(int,Object)@Deprecated public final void clear()
AbstractLongListclear in interface java.util.Collection<java.lang.Long>clear in interface java.util.List<java.lang.Long>clear in class AbstractLongList@Deprecated public final void size(int size)
LongListIf 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 LongListsize in class AbstractLongListsize - the new size.@Deprecated
public final void removeElements(int from,
int to)
AbstractLongListThis is a trivial iterator-based based implementation. It is expected that implementations will override this method with a more optimized version.
removeElements in interface LongListremoveElements in class AbstractLongListfrom - the start index (inclusive).to - the end index (exclusive).@Deprecated
public final void addElements(int index,
long[] a,
int offset,
int length)
AbstractLongListThis is a trivial iterator-based implementation. It is expected that implementations will override this method with a more optimized version.
addElements in interface LongListaddElements in class AbstractLongListindex - 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,
long[] a,
int offset,
int length)
LongList
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 LongListsetElements in class AbstractLongListindex - 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.longs.LongComparator comp)
LongListPass null to sort using natural ordering.
@Deprecated public final void unstableSort(it.unimi.dsi.fastutil.longs.LongComparator comp)
LongListPass 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 LongList@Deprecated public final void sort(java.util.Comparator<? super java.lang.Long> comparator)
LongList@Deprecated public final void unstableSort(java.util.Comparator<? super java.lang.Long> comparator)
LongListunstableSort in interface LongList