Class ReferenceImmutableList<K>
- All Implemented Interfaces:
ObjectIterable<K>
,ReferenceCollection<K>
,ReferenceList<K>
,Stack<K>
,Serializable
,Cloneable
,Iterable<K>
,Collection<K>
,List<K>
,RandomAccess
,SequencedCollection<K>
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.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class it.unimi.dsi.fastutil.objects.AbstractReferenceList
AbstractReferenceList.ReferenceRandomAccessSubList<K>, AbstractReferenceList.ReferenceSubList<K>
-
Constructor Summary
ConstructorDescriptionReferenceImmutableList
(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.ReferenceImmutableList
(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. -
Method Summary
Modifier and TypeMethodDescriptionfinal void
Deprecated.final boolean
Deprecated.final boolean
addAll
(int index, Collection<? extends K> c) Deprecated.final boolean
addAll
(Collection<? extends K> c) Deprecated.final void
addElements
(int index, K[] a, int offset, int length) Deprecated.final void
clear()
Deprecated.clone()
boolean
Compares this type-specific immutable list to another one.boolean
void
get
(int index) void
getElements
(int from, Object[] a, int offset, int length) Copies element of this type-specific list into the given array using optimized system calls.int
boolean
isEmpty()
Checks whether the stack is empty.int
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.final K
remove
(int index) Deprecated.final boolean
Deprecated.final boolean
removeAll
(Collection<?> c) Deprecated.final void
removeElements
(int from, int to) Deprecated.final boolean
Deprecated.final void
replaceAll
(UnaryOperator<K> operator) Deprecated.final boolean
retainAll
(Collection<?> c) Deprecated.final K
Deprecated.final void
setElements
(int index, K[] a, int offset, int length) Deprecated.int
size()
final void
size
(int size) Deprecated.final void
sort
(Comparator<? super K> comparator) Deprecated.Returns a type-specific spliterator on the elements of this list.subList
(int from, int to) Returns a type-specific view of the portion of this list from the indexfrom
, inclusive, to the indexto
, exclusive.Object[]
toArray()
<T> T[]
toArray
(T[] a) static <K> Collector
<K, ?, ReferenceImmutableList<K>> toList()
Returns aCollector
that collects aStream
's elements into a new ImmutableList.static <K> Collector
<K, ?, ReferenceImmutableList<K>> toListWithExpectedSize
(int expectedSize) Returns aCollector
that collects aStream
's elements into a new ImmutableList, potentially pre-allocated to handle the given size.final void
unstableSort
(Comparator<? super K> comparator) Deprecated.Methods inherited from class it.unimi.dsi.fastutil.objects.AbstractReferenceList
addElements, contains, hashCode, iterator, listIterator, peek, pop, push, top, toString
Methods inherited from class java.util.AbstractCollection
containsAll
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
Methods inherited from interface java.util.List
add, add, addAll, addAll, addFirst, addLast, clear, contains, containsAll, getFirst, getLast, hashCode, remove, remove, removeAll, removeFirst, removeLast, replaceAll, retainAll, reversed, set
Methods inherited from interface it.unimi.dsi.fastutil.objects.ReferenceList
addAll, addAll, addElements, addElements, iterator, listIterator, removeElements, setElements, setElements, setElements, size, sort, unstableSort
-
Constructor Details
-
ReferenceImmutableList
Creates a new immutable list using a given array.Note that this constructor does not perform a defensive copy.
- Parameters:
a
- the array that will be used to back this immutable list.
-
ReferenceImmutableList
Creates a new immutable list and fills it with a given collection.- Parameters:
c
- a collection that will be used to fill the immutable list.
-
ReferenceImmutableList
Creates a new immutable list and fills it with a given type-specific collection.- Parameters:
c
- a type-specific collection that will be used to fill the immutable list.
-
ReferenceImmutableList
Creates a new immutable list and fills it with a given type-specific list.- Parameters:
l
- a type-specific list that will be used to fill the immutable list.
-
ReferenceImmutableList
Creates a new immutable list and fills it with the elements of a given array.- Parameters:
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.
-
ReferenceImmutableList
Creates a new immutable list and fills it with the elements returned by a type-specific iterator..- Parameters:
i
- a type-specific iterator whose returned elements will fill the immutable list.
-
-
Method Details
-
of
Returns an empty immutable list.- Returns:
- an immutable list (possibly shared) that is empty.
-
of
Creates an immutable list using a list of elements.Note that this method does not perform a defensive copy.
- Parameters:
init
- a list of elements that will be used to initialize the list.- Returns:
- a new immutable list containing the given elements.
-
toList
Returns aCollector
that collects aStream
's elements into a new ImmutableList. -
toListWithExpectedSize
Returns aCollector
that collects aStream
's elements into a new ImmutableList, potentially pre-allocated to handle the given size. -
get
-
indexOf
-
lastIndexOf
- Specified by:
lastIndexOf
in interfaceList<K>
- Overrides:
lastIndexOf
in classAbstractReferenceList<K>
-
size
public int size()- Specified by:
size
in interfaceCollection<K>
- Specified by:
size
in interfaceList<K>
- Specified by:
size
in classAbstractCollection<K>
-
isEmpty
public boolean isEmpty()Description copied from interface:Stack
Checks whether the stack is empty. -
getElements
Copies element of this type-specific list into the given array using optimized system calls.- Specified by:
getElements
in interfaceReferenceList<K>
- Overrides:
getElements
in classAbstractReferenceList<K>
- Parameters:
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.
-
forEach
Description copied from class:AbstractReferenceList
-
toArray
- Specified by:
toArray
in interfaceCollection<K>
- Specified by:
toArray
in interfaceList<K>
- Overrides:
toArray
in classAbstractReferenceList<K>
-
toArray
public <T> T[] toArray(T[] a) - Specified by:
toArray
in interfaceCollection<K>
- Specified by:
toArray
in interfaceList<K>
- Overrides:
toArray
in classAbstractReferenceList<K>
-
listIterator
Description copied from class:AbstractReferenceList
Returns a type-specific list iterator on the list starting at a given index.- Specified by:
listIterator
in interfaceList<K>
- Specified by:
listIterator
in interfaceReferenceList<K>
- Overrides:
listIterator
in classAbstractReferenceList<K>
- See Also:
-
spliterator
Description copied from interface:ReferenceList
Returns a type-specific spliterator on the elements of this list.List spliterators must report at least
Spliterator.SIZED
andSpliterator.ORDERED
.See
List.spliterator()
for more documentation on the requirements of the returned spliterator.- Specified by:
spliterator
in interfaceCollection<K>
- Specified by:
spliterator
in interfaceIterable<K>
- Specified by:
spliterator
in interfaceList<K>
- Specified by:
spliterator
in interfaceObjectIterable<K>
- Specified by:
spliterator
in interfaceReferenceCollection<K>
- Specified by:
spliterator
in interfaceReferenceList<K>
- Returns:
- a type-specific spliterator on the elements of this collection.
-
subList
Returns a type-specific view of the portion of this list from the indexfrom
, inclusive, to the indexto
, exclusive.- Specified by:
subList
in interfaceList<K>
- Specified by:
subList
in interfaceReferenceList<K>
- Overrides:
subList
in classAbstractReferenceList<K>
- See Also:
- API Notes:
- The returned list will be immutable, but is currently not declared to return an instance
of
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 ofImmutableList
).
-
clone
-
equals
Compares this type-specific immutable list to another one.- Parameters:
l
- a type-specific immutable list.- Returns:
- true if the argument contains the same elements of this type-specific immutable list.
- API Notes:
- This method exists only for sake of efficiency. The implementation inherited from the abstract implementation would already work.
-
equals
- Specified by:
equals
in interfaceCollection<K>
- Specified by:
equals
in interfaceList<K>
- Overrides:
equals
in classAbstractReferenceList<K>
-
add
Deprecated.Description copied from class:AbstractReferenceList
- Specified by:
add
in interfaceList<K>
- Overrides:
add
in classAbstractReferenceList<K>
- Implementation Specification:
- Always throws
UnsupportedOperationException
as this is an immutable type.
-
add
Deprecated.Description copied from class:AbstractReferenceList
- Specified by:
add
in interfaceCollection<K>
- Specified by:
add
in interfaceList<K>
- Overrides:
add
in classAbstractReferenceList<K>
- Implementation Specification:
- Always throws
UnsupportedOperationException
as this is an immutable type.
-
addAll
Deprecated.Description copied from class:AbstractReferenceList
- Specified by:
addAll
in interfaceCollection<K>
- Specified by:
addAll
in interfaceList<K>
- Overrides:
addAll
in classAbstractReferenceList<K>
- Implementation Specification:
- Always throws
UnsupportedOperationException
as this is an immutable type.
-
addAll
Deprecated.Description copied from class:AbstractReferenceList
Adds all of the elements in the specified collection to this list (optional operation).- Specified by:
addAll
in interfaceList<K>
- Overrides:
addAll
in classAbstractReferenceList<K>
- Implementation Specification:
- Always throws
UnsupportedOperationException
as this is an immutable type.
-
remove
Deprecated.Description copied from class:AbstractReferenceList
- Specified by:
remove
in interfaceList<K>
- Overrides:
remove
in classAbstractReferenceList<K>
- Implementation Specification:
- Always throws
UnsupportedOperationException
as this is an immutable type.
-
remove
Deprecated.- Specified by:
remove
in interfaceCollection<K>
- Specified by:
remove
in interfaceList<K>
- Overrides:
remove
in classAbstractCollection<K>
- Implementation Specification:
- Always throws
UnsupportedOperationException
as this is an immutable type.
-
removeAll
Deprecated.- Specified by:
removeAll
in interfaceCollection<K>
- Specified by:
removeAll
in interfaceList<K>
- Overrides:
removeAll
in classAbstractCollection<K>
- Implementation Specification:
- Always throws
UnsupportedOperationException
as this is an immutable type.
-
retainAll
Deprecated.- Specified by:
retainAll
in interfaceCollection<K>
- Specified by:
retainAll
in interfaceList<K>
- Overrides:
retainAll
in classAbstractCollection<K>
- Implementation Specification:
- Always throws
UnsupportedOperationException
as this is an immutable type.
-
removeIf
Deprecated.- Specified by:
removeIf
in interfaceCollection<K>
- Implementation Specification:
- Always throws
UnsupportedOperationException
as this is an immutable type.
-
replaceAll
Deprecated.- Specified by:
replaceAll
in interfaceList<K>
- Implementation Specification:
- Always throws
UnsupportedOperationException
as this is an immutable type.
-
set
Deprecated.Description copied from class:AbstractReferenceList
- Specified by:
set
in interfaceList<K>
- Overrides:
set
in classAbstractReferenceList<K>
- Implementation Specification:
- Always throws
UnsupportedOperationException
as this is an immutable type.
-
clear
Deprecated.Description copied from class:AbstractReferenceList
- Specified by:
clear
in interfaceCollection<K>
- Specified by:
clear
in interfaceList<K>
- Overrides:
clear
in classAbstractReferenceList<K>
- Implementation Specification:
- Always throws
UnsupportedOperationException
as this is an immutable type.
-
size
Deprecated.Description copied from interface:ReferenceList
Sets the size of this list.If the specified size is smaller than the current size, the last elements are discarded. Otherwise, they are filled with 0/
null
/false
.- Specified by:
size
in interfaceReferenceList<K>
- Overrides:
size
in classAbstractReferenceList<K>
- Parameters:
size
- the new size.- Implementation Specification:
- Always throws
UnsupportedOperationException
as this is an immutable type.
-
removeElements
Deprecated.Description copied from class:AbstractReferenceList
Removes (hopefully quickly) elements of this type-specific list.This is a trivial iterator-based based implementation. It is expected that implementations will override this method with a more optimized version.
- Specified by:
removeElements
in interfaceReferenceList<K>
- Overrides:
removeElements
in classAbstractReferenceList<K>
- Parameters:
from
- the start index (inclusive).to
- the end index (exclusive).- Implementation Specification:
- Always throws
UnsupportedOperationException
as this is an immutable type.
-
addElements
Deprecated.Description copied from class:AbstractReferenceList
Add (hopefully quickly) elements to this type-specific list.This is a trivial iterator-based implementation. It is expected that implementations will override this method with a more optimized version.
- Specified by:
addElements
in interfaceReferenceList<K>
- Overrides:
addElements
in classAbstractReferenceList<K>
- Parameters:
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.- Implementation Specification:
- Always throws
UnsupportedOperationException
as this is an immutable type.
-
setElements
Deprecated.Description copied from interface:ReferenceList
Set (hopefully quickly) elements to match the array given. Sets each in this list to the corresponding elements in the array, as if byListIterator 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.- Specified by:
setElements
in interfaceReferenceList<K>
- Overrides:
setElements
in classAbstractReferenceList<K>
- Parameters:
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.- Implementation Specification:
- Always throws
UnsupportedOperationException
as this is an immutable type.
-
sort
Deprecated.Description copied from interface:ReferenceList
Sorts this list using a sort assured to be stable.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.
- Specified by:
sort
in interfaceList<K>
- Specified by:
sort
in interfaceReferenceList<K>
- Implementation Specification:
- Always throws
UnsupportedOperationException
as this is an immutable type.
-
unstableSort
Deprecated.Description copied from interface:ReferenceList
Sorts this list using a sort not assured to be stable. This differs fromList.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.
- Specified by:
unstableSort
in interfaceReferenceList<K>
- Implementation Specification:
- Always throws
UnsupportedOperationException
as this is an immutable type.
-