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