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