public class ByteImmutableList extends AbstractByteList implements ByteList, 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.
AbstractByteList.ByteRandomAccessSubList, AbstractByteList.ByteSubList
Constructor and Description |
---|
ByteImmutableList(byte[] a)
Creates a new immutable list using a given array.
|
ByteImmutableList(byte[] a,
int offset,
int length)
Creates a new immutable list and fills it with the elements of a given array.
|
ByteImmutableList(ByteCollection c)
Creates a new immutable list and fills it with a given type-specific collection.
|
ByteImmutableList(ByteIterator i)
Creates a new immutable list and fills it with the elements returned by a type-specific iterator..
|
ByteImmutableList(ByteList l)
Creates a new immutable list and fills it with a given type-specific list.
|
ByteImmutableList(java.util.Collection<? extends java.lang.Byte> c)
Creates a new immutable list and fills it with a given collection.
|
Modifier and Type | Method and Description |
---|---|
boolean |
add(byte k)
Deprecated.
|
boolean |
add(java.lang.Byte k)
Deprecated.
|
void |
add(int index,
byte k)
Deprecated.
|
void |
add(int index,
java.lang.Byte k)
Deprecated.
|
boolean |
addAll(ByteCollection c)
Deprecated.
|
boolean |
addAll(ByteList c)
Deprecated.
|
boolean |
addAll(java.util.Collection<? extends java.lang.Byte> c)
Deprecated.
|
boolean |
addAll(int index,
ByteCollection c)
Deprecated.
|
boolean |
addAll(int index,
ByteList c)
Deprecated.
|
boolean |
addAll(int index,
java.util.Collection<? extends java.lang.Byte> c)
Deprecated.
|
void |
addElements(int index,
byte[] a,
int offset,
int length)
Deprecated.
|
void |
clear()
Deprecated.
|
ByteImmutableList |
clone() |
int |
compareTo(ByteImmutableList l)
Compares this immutable list to another immutable list.
|
int |
compareTo(java.util.List<? extends java.lang.Byte> l)
Compares this list to another object.
|
boolean |
equals(ByteImmutableList l)
Compares this type-specific immutable list to another one.
|
boolean |
equals(java.lang.Object o) |
void |
forEach(ByteConsumer 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. |
byte |
getByte(int index)
Returns the element at the specified position in this list.
|
void |
getElements(int from,
byte[] a,
int offset,
int length)
Copies element of this type-specific list into the given array using optimized system calls.
|
int |
indexOf(byte 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(byte 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.
|
ByteListIterator |
listIterator(int index)
Returns a type-specific list iterator on the list starting at a given index.
|
static ByteImmutableList |
of()
Returns an empty immutable list.
|
static ByteImmutableList |
of(byte... init)
Creates an immutable list using a list of elements.
|
boolean |
rem(byte k)
Deprecated.
|
java.lang.Byte |
remove(int index)
Deprecated.
|
boolean |
remove(java.lang.Object k)
Deprecated.
|
boolean |
removeAll(ByteCollection c)
Deprecated.
|
boolean |
removeAll(java.util.Collection<?> c)
Deprecated.
|
byte |
removeByte(int index)
Deprecated.
|
void |
removeElements(int from,
int to)
Deprecated.
|
boolean |
removeIf(BytePredicate c)
Deprecated.
|
boolean |
removeIf(java.util.function.Predicate<? super java.lang.Byte> c)
Deprecated.
|
void |
replaceAll(java.util.function.IntUnaryOperator operator)
Deprecated.
|
void |
replaceAll(java.util.function.UnaryOperator<java.lang.Byte> operator)
Deprecated.
|
boolean |
retainAll(ByteCollection c)
Deprecated.
|
boolean |
retainAll(java.util.Collection<?> c)
Deprecated.
|
byte |
set(int index,
byte k)
Deprecated.
|
java.lang.Byte |
set(int index,
java.lang.Byte k)
Deprecated.
|
void |
setElements(int index,
byte[] a,
int offset,
int length)
Deprecated.
|
int |
size() |
void |
size(int size)
Deprecated.
|
void |
sort(ByteComparator comp)
Deprecated.
|
void |
sort(java.util.Comparator<? super java.lang.Byte> comparator)
Deprecated.
|
ByteSpliterator |
spliterator()
Returns a type-specific spliterator on the elements of this list.
|
ByteList |
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. |
byte[] |
toArray(byte[] 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.
|
byte[] |
toByteArray()
Returns a primitive type array containing the items of this collection.
|
void |
unstableSort(ByteComparator comp)
Deprecated.
|
void |
unstableSort(java.util.Comparator<? super java.lang.Byte> comparator)
Deprecated.
|
addElements, contains, hashCode, iterator, listIterator, peekByte, popByte, push, topByte, toString
contains, containsAll, containsAll, toByteArray
add, add, add, add, addAll, addAll, addAll, addElements, addElements, contains, get, indexOf, iterator, lastIndexOf, listIterator, of, of, of, remove, remove, removeByte, removeElements, 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, toByteArray
forEach, forEach
public ByteImmutableList(byte[] a)
Note that this constructor does not perform a defensive copy.
a
- the array that will be used to back this immutable list.public ByteImmutableList(java.util.Collection<? extends java.lang.Byte> c)
c
- a collection that will be used to fill the immutable list.public ByteImmutableList(ByteCollection c)
c
- a type-specific collection that will be used to fill the immutable list.public ByteImmutableList(ByteList l)
l
- a type-specific list that will be used to fill the immutable list.public ByteImmutableList(byte[] 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 ByteImmutableList(ByteIterator i)
i
- a type-specific iterator whose returned elements will fill the immutable list.public static ByteImmutableList of()
public static ByteImmutableList of(byte... init)
Note that this method does not perform a defensive copy.
public byte getByte(int index)
ByteList
public int indexOf(byte k)
ByteList
indexOf
in interface ByteList
indexOf
in class AbstractByteList
List.indexOf(Object)
public int lastIndexOf(byte k)
ByteList
lastIndexOf
in interface ByteList
lastIndexOf
in class AbstractByteList
List.lastIndexOf(Object)
public int size()
size
in interface java.util.Collection<java.lang.Byte>
size
in interface java.util.List<java.lang.Byte>
size
in class java.util.AbstractCollection<java.lang.Byte>
public boolean isEmpty()
Stack
isEmpty
in interface Stack<java.lang.Byte>
isEmpty
in interface java.util.Collection<java.lang.Byte>
isEmpty
in interface java.util.List<java.lang.Byte>
isEmpty
in class java.util.AbstractCollection<java.lang.Byte>
public void getElements(int from, byte[] a, int offset, int length)
getElements
in interface ByteList
getElements
in class AbstractByteList
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(ByteConsumer action)
AbstractByteList
Iterable
until all elements have been processed or the action throws an
exception.forEach
in interface ByteIterable
forEach
in class AbstractByteList
action
- the action to be performed for each element.Iterable.forEach(java.util.function.Consumer)
public byte[] toByteArray()
ByteCollection
toByteArray
in interface ByteCollection
toByteArray
in class AbstractByteList
Collection.toArray()
public byte[] toArray(byte[] a)
ByteCollection
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 ByteCollection
toArray
in class AbstractByteList
a
- if this array is big enough, it will be used to store this collection.Collection.toArray(Object[])
public ByteListIterator listIterator(int index)
AbstractByteList
listIterator
in interface ByteList
listIterator
in interface java.util.List<java.lang.Byte>
listIterator
in class AbstractByteList
List.listIterator(int)
public ByteSpliterator spliterator()
ByteList
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 ByteCollection
spliterator
in interface ByteIterable
spliterator
in interface ByteList
spliterator
in interface java.lang.Iterable<java.lang.Byte>
spliterator
in interface java.util.Collection<java.lang.Byte>
spliterator
in interface java.util.List<java.lang.Byte>
public ByteList subList(int from, int to)
from
, inclusive, to the index to
, exclusive.subList
in interface ByteList
subList
in interface java.util.List<java.lang.Byte>
subList
in class AbstractByteList
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 ByteImmutableList clone()
clone
in class java.lang.Object
public boolean equals(ByteImmutableList l)
l
- a type-specific immutable list.public boolean equals(java.lang.Object o)
equals
in interface java.util.Collection<java.lang.Byte>
equals
in interface java.util.List<java.lang.Byte>
equals
in class AbstractByteList
public int compareTo(ByteImmutableList l)
l
- an immutable list.public int compareTo(java.util.List<? extends java.lang.Byte> l)
AbstractByteList
List
, this method performs a lexicographical comparison; otherwise,
it throws a ClassCastException
.compareTo
in interface java.lang.Comparable<java.util.List<? extends java.lang.Byte>>
compareTo
in class AbstractByteList
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, byte k)
AbstractByteList
add
in interface ByteList
add
in class AbstractByteList
List.add(int,Object)
UnsupportedOperationException
as this is an immutable type.@Deprecated public final boolean add(byte k)
AbstractByteList
add
in interface ByteCollection
add
in interface ByteList
add
in class AbstractByteList
Collection.add(Object)
UnsupportedOperationException
as this is an immutable type.@Deprecated public final boolean addAll(java.util.Collection<? extends java.lang.Byte> c)
AbstractByteList
addAll
in interface java.util.Collection<java.lang.Byte>
addAll
in interface java.util.List<java.lang.Byte>
addAll
in class AbstractByteList
UnsupportedOperationException
as this is an immutable type.@Deprecated public final boolean addAll(int index, java.util.Collection<? extends java.lang.Byte> c)
AbstractByteList
addAll
in interface java.util.List<java.lang.Byte>
addAll
in class AbstractByteList
UnsupportedOperationException
as this is an immutable type.@Deprecated public final byte removeByte(int index)
AbstractByteList
removeByte
in interface ByteList
removeByte
in class AbstractByteList
List.remove(int)
UnsupportedOperationException
as this is an immutable type.@Deprecated public final boolean rem(byte k)
AbstractByteList
rem
in interface ByteCollection
rem
in class AbstractByteList
List.remove(Object)
UnsupportedOperationException
as this is an immutable type.@Deprecated public final boolean removeAll(java.util.Collection<?> c)
AbstractByteCollection
removeAll
in interface java.util.Collection<java.lang.Byte>
removeAll
in interface java.util.List<java.lang.Byte>
removeAll
in class AbstractByteCollection
UnsupportedOperationException
as this is an immutable type.@Deprecated public final boolean retainAll(java.util.Collection<?> c)
AbstractByteCollection
retainAll
in interface java.util.Collection<java.lang.Byte>
retainAll
in interface java.util.List<java.lang.Byte>
retainAll
in class AbstractByteCollection
UnsupportedOperationException
as this is an immutable type.@Deprecated public final boolean removeIf(java.util.function.Predicate<? super java.lang.Byte> c)
ByteCollection
removeIf
in interface ByteCollection
removeIf
in interface java.util.Collection<java.lang.Byte>
UnsupportedOperationException
as this is an immutable type.@Deprecated public final boolean removeIf(BytePredicate c)
ByteCollection
removeIf
in interface ByteCollection
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.Byte> operator)
ByteList
replaceAll
in interface ByteList
replaceAll
in interface java.util.List<java.lang.Byte>
UnsupportedOperationException
as this is an immutable type.@Deprecated public final void replaceAll(java.util.function.IntUnaryOperator operator)
ByteList
replaceAll
in interface ByteList
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.Byte k)
ByteList
@Deprecated public final boolean add(java.lang.Byte k)
AbstractByteCollection
add
in interface ByteCollection
add
in interface ByteList
add
in interface java.util.Collection<java.lang.Byte>
add
in interface java.util.List<java.lang.Byte>
add
in class AbstractByteCollection
UnsupportedOperationException
as this is an immutable type.@Deprecated public final java.lang.Byte remove(int index)
ByteList
@Deprecated public final boolean remove(java.lang.Object k)
AbstractByteCollection
remove
in interface ByteCollection
remove
in interface ByteList
remove
in interface java.util.Collection<java.lang.Byte>
remove
in interface java.util.List<java.lang.Byte>
remove
in class AbstractByteCollection
UnsupportedOperationException
as this is an immutable type.@Deprecated public final java.lang.Byte set(int index, java.lang.Byte k)
ByteList
@Deprecated public final boolean addAll(ByteCollection c)
AbstractByteList
addAll
in interface ByteCollection
addAll
in class AbstractByteList
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(ByteList c)
ByteList
@Deprecated public final boolean addAll(int index, ByteCollection c)
ByteList
addAll
in interface ByteList
addAll
in class AbstractByteList
List.addAll(int,java.util.Collection)
UnsupportedOperationException
as this is an immutable type.@Deprecated public final boolean addAll(int index, ByteList c)
ByteList
@Deprecated public final boolean removeAll(ByteCollection c)
ByteCollection
removeAll
in interface ByteCollection
removeAll
in class AbstractByteCollection
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(ByteCollection c)
ByteCollection
retainAll
in interface ByteCollection
retainAll
in class AbstractByteCollection
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 byte set(int index, byte k)
AbstractByteList
set
in interface ByteList
set
in class AbstractByteList
List.set(int,Object)
UnsupportedOperationException
as this is an immutable type.@Deprecated public final void clear()
AbstractByteList
clear
in interface java.util.Collection<java.lang.Byte>
clear
in interface java.util.List<java.lang.Byte>
clear
in class AbstractByteList
UnsupportedOperationException
as this is an immutable type.@Deprecated public final void size(int size)
ByteList
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 ByteList
size
in class AbstractByteList
size
- the new size.UnsupportedOperationException
as this is an immutable type.@Deprecated public final void removeElements(int from, int to)
AbstractByteList
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 ByteList
removeElements
in class AbstractByteList
from
- the start index (inclusive).to
- the end index (exclusive).UnsupportedOperationException
as this is an immutable type.@Deprecated public final void addElements(int index, byte[] a, int offset, int length)
AbstractByteList
This is a trivial iterator-based implementation. It is expected that implementations will override this method with a more optimized version.
addElements
in interface ByteList
addElements
in class AbstractByteList
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, byte[] a, int offset, int length)
ByteList
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 ByteList
setElements
in class AbstractByteList
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(ByteComparator comp)
ByteList
Pass null
to sort using natural ordering.
@Deprecated public final void unstableSort(ByteComparator comp)
ByteList
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 ByteList
UnsupportedOperationException
as this is an immutable type.@Deprecated public final void sort(java.util.Comparator<? super java.lang.Byte> comparator)
ByteList
@Deprecated public final void unstableSort(java.util.Comparator<? super java.lang.Byte> comparator)
ByteList
unstableSort
in interface ByteList
UnsupportedOperationException
as this is an immutable type.