public class ShortImmutableList extends AbstractShortList implements ShortList, 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.
AbstractShortList.ShortRandomAccessSubList, AbstractShortList.ShortSubList
Constructor and Description |
---|
ShortImmutableList(java.util.Collection<? extends java.lang.Short> c)
Creates a new immutable list and fills it with a given collection.
|
ShortImmutableList(short[] a)
Creates a new immutable list using a given array.
|
ShortImmutableList(short[] a,
int offset,
int length)
Creates a new immutable list and fills it with the elements of a given array.
|
ShortImmutableList(ShortCollection c)
Creates a new immutable list and fills it with a given type-specific collection.
|
ShortImmutableList(ShortIterator i)
Creates a new immutable list and fills it with the elements returned by a type-specific iterator..
|
ShortImmutableList(ShortList 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,
short k)
Deprecated.
|
void |
add(int index,
java.lang.Short k)
Deprecated.
|
boolean |
add(short k)
Deprecated.
|
boolean |
add(java.lang.Short k)
Deprecated.
|
boolean |
addAll(java.util.Collection<? extends java.lang.Short> c)
Deprecated.
|
boolean |
addAll(int index,
java.util.Collection<? extends java.lang.Short> c)
Deprecated.
|
boolean |
addAll(int index,
ShortCollection c)
Deprecated.
|
boolean |
addAll(int index,
ShortList c)
Deprecated.
|
boolean |
addAll(ShortCollection c)
Deprecated.
|
boolean |
addAll(ShortList c)
Deprecated.
|
void |
addElements(int index,
short[] a,
int offset,
int length)
Deprecated.
|
void |
clear()
Deprecated.
|
ShortImmutableList |
clone() |
int |
compareTo(java.util.List<? extends java.lang.Short> l)
Compares this list to another object.
|
int |
compareTo(ShortImmutableList l)
Compares this immutable list to another immutable list.
|
boolean |
equals(java.lang.Object o) |
boolean |
equals(ShortImmutableList l)
Compares this type-specific immutable list to another one.
|
void |
forEach(ShortConsumer 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,
short[] a,
int offset,
int length)
Copies element of this type-specific list into the given array using optimized system calls.
|
short |
getShort(int index)
Returns the element at the specified position in this list.
|
int |
indexOf(short 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(short 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.
|
ShortListIterator |
listIterator(int index)
Returns a type-specific list iterator on the list starting at a given index.
|
static ShortImmutableList |
of()
Returns an empty immutable list.
|
static ShortImmutableList |
of(short... init)
Creates an immutable list using a list of elements.
|
boolean |
rem(short k)
Deprecated.
|
java.lang.Short |
remove(int index)
Deprecated.
|
boolean |
remove(java.lang.Object k)
Deprecated.
|
boolean |
removeAll(java.util.Collection<?> c)
Deprecated.
|
boolean |
removeAll(ShortCollection c)
Deprecated.
|
void |
removeElements(int from,
int to)
Deprecated.
|
boolean |
removeIf(java.util.function.Predicate<? super java.lang.Short> c)
Deprecated.
|
boolean |
removeIf(ShortPredicate c)
Deprecated.
|
short |
removeShort(int index)
Deprecated.
|
void |
replaceAll(java.util.function.IntUnaryOperator operator)
Deprecated.
|
void |
replaceAll(java.util.function.UnaryOperator<java.lang.Short> operator)
Deprecated.
|
boolean |
retainAll(java.util.Collection<?> c)
Deprecated.
|
boolean |
retainAll(ShortCollection c)
Deprecated.
|
short |
set(int index,
short k)
Deprecated.
|
java.lang.Short |
set(int index,
java.lang.Short k)
Deprecated.
|
void |
setElements(int index,
short[] a,
int offset,
int length)
Deprecated.
|
int |
size() |
void |
size(int size)
Deprecated.
|
void |
sort(java.util.Comparator<? super java.lang.Short> comparator)
Deprecated.
|
void |
sort(ShortComparator comp)
Deprecated.
|
ShortSpliterator |
spliterator()
Returns a type-specific spliterator on the elements of this list.
|
ShortList |
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. |
short[] |
toArray(short[] 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.
|
short[] |
toShortArray()
Returns a primitive type array containing the items of this collection.
|
void |
unstableSort(java.util.Comparator<? super java.lang.Short> comparator)
Deprecated.
|
void |
unstableSort(ShortComparator comp)
Deprecated.
|
addElements, contains, hashCode, iterator, listIterator, peekShort, popShort, push, topShort, toString
contains, containsAll, containsAll, toShortArray
add, add, add, add, addAll, addAll, addAll, addElements, addElements, contains, get, indexOf, iterator, lastIndexOf, listIterator, of, of, of, remove, remove, removeElements, removeShort, 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, toShortArray
forEach, forEach
peek, pop, push, top
public ShortImmutableList(short[] a)
Note that this constructor does not perform a defensive copy.
a
- the array that will be used to back this immutable list.public ShortImmutableList(java.util.Collection<? extends java.lang.Short> c)
c
- a collection that will be used to fill the immutable list.public ShortImmutableList(ShortCollection c)
c
- a type-specific collection that will be used to fill the immutable list.public ShortImmutableList(ShortList l)
l
- a type-specific list that will be used to fill the immutable list.public ShortImmutableList(short[] 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 ShortImmutableList(ShortIterator i)
i
- a type-specific iterator whose returned elements will fill the immutable list.public static ShortImmutableList of()
public static ShortImmutableList of(short... init)
Note that this method does not perform a defensive copy.
public short getShort(int index)
ShortList
public int indexOf(short k)
ShortList
indexOf
in interface ShortList
indexOf
in class AbstractShortList
List.indexOf(Object)
public int lastIndexOf(short k)
ShortList
lastIndexOf
in interface ShortList
lastIndexOf
in class AbstractShortList
List.lastIndexOf(Object)
public int size()
size
in interface java.util.Collection<java.lang.Short>
size
in interface java.util.List<java.lang.Short>
size
in class java.util.AbstractCollection<java.lang.Short>
public boolean isEmpty()
Stack
isEmpty
in interface Stack<java.lang.Short>
isEmpty
in interface java.util.Collection<java.lang.Short>
isEmpty
in interface java.util.List<java.lang.Short>
isEmpty
in class java.util.AbstractCollection<java.lang.Short>
public void getElements(int from, short[] a, int offset, int length)
getElements
in interface ShortList
getElements
in class AbstractShortList
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(ShortConsumer action)
AbstractShortList
Iterable
until all elements have been processed or the action throws an
exception.forEach
in interface ShortIterable
forEach
in class AbstractShortList
action
- the action to be performed for each element.Iterable.forEach(java.util.function.Consumer)
public short[] toShortArray()
ShortCollection
toShortArray
in interface ShortCollection
toShortArray
in class AbstractShortList
Collection.toArray()
public short[] toArray(short[] a)
ShortCollection
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 ShortCollection
toArray
in class AbstractShortList
a
- if this array is big enough, it will be used to store this collection.Collection.toArray(Object[])
public ShortListIterator listIterator(int index)
AbstractShortList
listIterator
in interface ShortList
listIterator
in interface java.util.List<java.lang.Short>
listIterator
in class AbstractShortList
List.listIterator(int)
public ShortSpliterator spliterator()
ShortList
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 ShortCollection
spliterator
in interface ShortIterable
spliterator
in interface ShortList
spliterator
in interface java.lang.Iterable<java.lang.Short>
spliterator
in interface java.util.Collection<java.lang.Short>
spliterator
in interface java.util.List<java.lang.Short>
public ShortList subList(int from, int to)
from
, inclusive, to the index to
, exclusive.subList
in interface ShortList
subList
in interface java.util.List<java.lang.Short>
subList
in class AbstractShortList
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 ShortImmutableList clone()
clone
in class java.lang.Object
public boolean equals(ShortImmutableList l)
l
- a type-specific immutable list.public boolean equals(java.lang.Object o)
equals
in interface java.util.Collection<java.lang.Short>
equals
in interface java.util.List<java.lang.Short>
equals
in class AbstractShortList
public int compareTo(ShortImmutableList l)
l
- an immutable list.public int compareTo(java.util.List<? extends java.lang.Short> l)
AbstractShortList
List
, this method performs a lexicographical comparison; otherwise,
it throws a ClassCastException
.compareTo
in interface java.lang.Comparable<java.util.List<? extends java.lang.Short>>
compareTo
in class AbstractShortList
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, short k)
AbstractShortList
add
in interface ShortList
add
in class AbstractShortList
List.add(int,Object)
UnsupportedOperationException
as this is an immutable type.@Deprecated public final boolean add(short k)
AbstractShortList
add
in interface ShortCollection
add
in interface ShortList
add
in class AbstractShortList
Collection.add(Object)
UnsupportedOperationException
as this is an immutable type.@Deprecated public final boolean addAll(java.util.Collection<? extends java.lang.Short> c)
AbstractShortList
addAll
in interface java.util.Collection<java.lang.Short>
addAll
in interface java.util.List<java.lang.Short>
addAll
in class AbstractShortList
UnsupportedOperationException
as this is an immutable type.@Deprecated public final boolean addAll(int index, java.util.Collection<? extends java.lang.Short> c)
AbstractShortList
addAll
in interface java.util.List<java.lang.Short>
addAll
in class AbstractShortList
UnsupportedOperationException
as this is an immutable type.@Deprecated public final short removeShort(int index)
AbstractShortList
removeShort
in interface ShortList
removeShort
in class AbstractShortList
List.remove(int)
UnsupportedOperationException
as this is an immutable type.@Deprecated public final boolean rem(short k)
AbstractShortList
rem
in interface ShortCollection
rem
in class AbstractShortList
List.remove(Object)
UnsupportedOperationException
as this is an immutable type.@Deprecated public final boolean removeAll(java.util.Collection<?> c)
AbstractShortCollection
removeAll
in interface java.util.Collection<java.lang.Short>
removeAll
in interface java.util.List<java.lang.Short>
removeAll
in class AbstractShortCollection
UnsupportedOperationException
as this is an immutable type.@Deprecated public final boolean retainAll(java.util.Collection<?> c)
AbstractShortCollection
retainAll
in interface java.util.Collection<java.lang.Short>
retainAll
in interface java.util.List<java.lang.Short>
retainAll
in class AbstractShortCollection
UnsupportedOperationException
as this is an immutable type.@Deprecated public final boolean removeIf(java.util.function.Predicate<? super java.lang.Short> c)
ShortCollection
removeIf
in interface ShortCollection
removeIf
in interface java.util.Collection<java.lang.Short>
UnsupportedOperationException
as this is an immutable type.@Deprecated public final boolean removeIf(ShortPredicate c)
ShortCollection
removeIf
in interface ShortCollection
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.Short> operator)
ShortList
replaceAll
in interface ShortList
replaceAll
in interface java.util.List<java.lang.Short>
UnsupportedOperationException
as this is an immutable type.@Deprecated public final void replaceAll(java.util.function.IntUnaryOperator operator)
ShortList
replaceAll
in interface ShortList
operator
- the operator to apply to each elementList.replaceAll(java.util.function.UnaryOperator<E>)
UnsupportedOperationException
as this is an immutable type.@Deprecated public final void add(int index, java.lang.Short k)
ShortList
@Deprecated public final boolean add(java.lang.Short k)
AbstractShortCollection
add
in interface ShortCollection
add
in interface ShortList
add
in interface java.util.Collection<java.lang.Short>
add
in interface java.util.List<java.lang.Short>
add
in class AbstractShortCollection
UnsupportedOperationException
as this is an immutable type.@Deprecated public final java.lang.Short remove(int index)
ShortList
@Deprecated public final boolean remove(java.lang.Object k)
AbstractShortCollection
remove
in interface ShortCollection
remove
in interface ShortList
remove
in interface java.util.Collection<java.lang.Short>
remove
in interface java.util.List<java.lang.Short>
remove
in class AbstractShortCollection
UnsupportedOperationException
as this is an immutable type.@Deprecated public final java.lang.Short set(int index, java.lang.Short k)
ShortList
@Deprecated public final boolean addAll(ShortCollection c)
AbstractShortList
addAll
in interface ShortCollection
addAll
in class AbstractShortList
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(ShortList c)
ShortList
@Deprecated public final boolean addAll(int index, ShortCollection c)
ShortList
addAll
in interface ShortList
addAll
in class AbstractShortList
List.addAll(int,java.util.Collection)
UnsupportedOperationException
as this is an immutable type.@Deprecated public final boolean addAll(int index, ShortList c)
ShortList
@Deprecated public final boolean removeAll(ShortCollection c)
ShortCollection
removeAll
in interface ShortCollection
removeAll
in class AbstractShortCollection
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(ShortCollection c)
ShortCollection
retainAll
in interface ShortCollection
retainAll
in class AbstractShortCollection
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 short set(int index, short k)
AbstractShortList
set
in interface ShortList
set
in class AbstractShortList
List.set(int,Object)
UnsupportedOperationException
as this is an immutable type.@Deprecated public final void clear()
AbstractShortList
clear
in interface java.util.Collection<java.lang.Short>
clear
in interface java.util.List<java.lang.Short>
clear
in class AbstractShortList
UnsupportedOperationException
as this is an immutable type.@Deprecated public final void size(int size)
ShortList
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 ShortList
size
in class AbstractShortList
size
- the new size.UnsupportedOperationException
as this is an immutable type.@Deprecated public final void removeElements(int from, int to)
AbstractShortList
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 ShortList
removeElements
in class AbstractShortList
from
- the start index (inclusive).to
- the end index (exclusive).UnsupportedOperationException
as this is an immutable type.@Deprecated public final void addElements(int index, short[] a, int offset, int length)
AbstractShortList
This is a trivial iterator-based implementation. It is expected that implementations will override this method with a more optimized version.
addElements
in interface ShortList
addElements
in class AbstractShortList
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, short[] a, int offset, int length)
ShortList
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 ShortList
setElements
in class AbstractShortList
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(ShortComparator comp)
ShortList
Pass null
to sort using natural ordering.
@Deprecated public final void unstableSort(ShortComparator comp)
ShortList
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 ShortList
UnsupportedOperationException
as this is an immutable type.@Deprecated public final void sort(java.util.Comparator<? super java.lang.Short> comparator)
ShortList
@Deprecated public final void unstableSort(java.util.Comparator<? super java.lang.Short> comparator)
ShortList
unstableSort
in interface ShortList
UnsupportedOperationException
as this is an immutable type.