public class DoubleImmutableList extends AbstractDoubleList implements DoubleList, 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.
AbstractDoubleList.DoubleRandomAccessSubList, AbstractDoubleList.DoubleSubList
Constructor and Description |
---|
DoubleImmutableList(java.util.Collection<? extends java.lang.Double> c)
Creates a new immutable list and fills it with a given collection.
|
DoubleImmutableList(double[] a)
Creates a new immutable list using a given array.
|
DoubleImmutableList(double[] a,
int offset,
int length)
Creates a new immutable list and fills it with the elements of a given array.
|
DoubleImmutableList(DoubleCollection c)
Creates a new immutable list and fills it with a given type-specific collection.
|
DoubleImmutableList(DoubleIterator i)
Creates a new immutable list and fills it with the elements returned by a type-specific iterator..
|
DoubleImmutableList(DoubleList l)
Creates a new immutable list and fills it with a given type-specific list.
|
Modifier and Type | Method and Description |
---|---|
boolean |
add(double k)
Deprecated.
|
boolean |
add(java.lang.Double k)
Deprecated.
|
void |
add(int index,
double k)
Deprecated.
|
void |
add(int index,
java.lang.Double k)
Deprecated.
|
boolean |
addAll(java.util.Collection<? extends java.lang.Double> c)
Deprecated.
|
boolean |
addAll(DoubleCollection c)
Deprecated.
|
boolean |
addAll(DoubleList c)
Deprecated.
|
boolean |
addAll(int index,
java.util.Collection<? extends java.lang.Double> c)
Deprecated.
|
boolean |
addAll(int index,
DoubleCollection c)
Deprecated.
|
boolean |
addAll(int index,
DoubleList c)
Deprecated.
|
void |
addElements(int index,
double[] a,
int offset,
int length)
Deprecated.
|
void |
clear()
Deprecated.
|
DoubleImmutableList |
clone() |
int |
compareTo(DoubleImmutableList l)
Compares this immutable list to another immutable list.
|
int |
compareTo(java.util.List<? extends java.lang.Double> l)
Compares this list to another object.
|
boolean |
equals(DoubleImmutableList l)
Compares this type-specific immutable list to another one.
|
boolean |
equals(java.lang.Object o) |
void |
forEach(java.util.function.DoubleConsumer 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. |
double |
getDouble(int index)
Returns the element at the specified position in this list.
|
void |
getElements(int from,
double[] a,
int offset,
int length)
Copies element of this type-specific list into the given array using optimized system calls.
|
int |
indexOf(double 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(double 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.
|
DoubleListIterator |
listIterator(int index)
Returns a type-specific list iterator on the list starting at a given index.
|
static DoubleImmutableList |
of()
Returns an empty immutable list.
|
static DoubleImmutableList |
of(double... init)
Creates an immutable list using a list of elements.
|
boolean |
rem(double k)
Deprecated.
|
java.lang.Double |
remove(int index)
Deprecated.
|
boolean |
remove(java.lang.Object k)
Deprecated.
|
boolean |
removeAll(java.util.Collection<?> c)
Deprecated.
|
boolean |
removeAll(DoubleCollection c)
Deprecated.
|
double |
removeDouble(int index)
Deprecated.
|
void |
removeElements(int from,
int to)
Deprecated.
|
boolean |
removeIf(java.util.function.DoublePredicate c)
Deprecated.
|
boolean |
removeIf(java.util.function.Predicate<? super java.lang.Double> c)
Deprecated.
|
void |
replaceAll(java.util.function.DoubleUnaryOperator operator)
Deprecated.
|
void |
replaceAll(java.util.function.UnaryOperator<java.lang.Double> operator)
Deprecated.
|
boolean |
retainAll(java.util.Collection<?> c)
Deprecated.
|
boolean |
retainAll(DoubleCollection c)
Deprecated.
|
double |
set(int index,
double k)
Deprecated.
|
java.lang.Double |
set(int index,
java.lang.Double k)
Deprecated.
|
void |
setElements(int index,
double[] a,
int offset,
int length)
Deprecated.
|
int |
size() |
void |
size(int size)
Deprecated.
|
void |
sort(java.util.Comparator<? super java.lang.Double> comparator)
Deprecated.
|
void |
sort(DoubleComparator comp)
Deprecated.
|
DoubleSpliterator |
spliterator()
Returns a type-specific spliterator on the elements of this list.
|
DoubleList |
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. |
double[] |
toArray(double[] 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.
|
double[] |
toDoubleArray()
Returns a primitive type array containing the items of this collection.
|
static DoubleImmutableList |
toList(java.util.stream.DoubleStream stream)
Collects the result of a primitive
Stream into a new ImmutableList. |
static DoubleImmutableList |
toListWithExpectedSize(java.util.stream.DoubleStream stream,
int expectedSize)
Collects the result of a primitive
Stream into a new ImmutableList, potentially pre-allocated to handle the given size. |
void |
unstableSort(java.util.Comparator<? super java.lang.Double> comparator)
Deprecated.
|
void |
unstableSort(DoubleComparator comp)
Deprecated.
|
addElements, contains, hashCode, iterator, listIterator, peekDouble, popDouble, push, replaceAll, topDouble, toString
contains, containsAll, containsAll, forEach, removeIf, toDoubleArray
add, add, add, add, addAll, addAll, addAll, addElements, addElements, contains, get, indexOf, iterator, lastIndexOf, listIterator, of, of, of, remove, remove, removeDouble, 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, doubleIterator, doubleParallelStream, doubleSpliterator, doubleStream, parallelStream, rem, removeAll, removeIf, removeIf, removeIf, retainAll, stream, toDoubleArray
forEach, forEach
peek, pop, push, top
public DoubleImmutableList(double[] a)
Note that this constructor does not perform a defensive copy.
a
- the array that will be used to back this immutable list.public DoubleImmutableList(java.util.Collection<? extends java.lang.Double> c)
c
- a collection that will be used to fill the immutable list.public DoubleImmutableList(DoubleCollection c)
c
- a type-specific collection that will be used to fill the immutable list.public DoubleImmutableList(DoubleList l)
l
- a type-specific list that will be used to fill the immutable list.public DoubleImmutableList(double[] 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 DoubleImmutableList(DoubleIterator i)
i
- a type-specific iterator whose returned elements will fill the immutable list.public static DoubleImmutableList of()
of
in interface DoubleList
public static DoubleImmutableList of(double... init)
Note that this method does not perform a defensive copy.
of
in interface DoubleList
init
- a list of elements that will be used to initialize the list.public static DoubleImmutableList toList(java.util.stream.DoubleStream stream)
Stream
into a new ImmutableList.
This method performs a terminal operation on the given Stream
Collector
is necessary because there is no
primitive Collector
equivalent in the Java API.public static DoubleImmutableList toListWithExpectedSize(java.util.stream.DoubleStream stream, int expectedSize)
Stream
into a new ImmutableList, potentially pre-allocated to handle the given size.
This method performs a terminal operation on the given Stream
Collector
is necessary because there is no
primitive Collector
equivalent in the Java API.public double getDouble(int index)
DoubleList
getDouble
in interface DoubleList
List.get(int)
public int indexOf(double k)
DoubleList
indexOf
in interface DoubleList
indexOf
in class AbstractDoubleList
List.indexOf(Object)
public int lastIndexOf(double k)
DoubleList
lastIndexOf
in interface DoubleList
lastIndexOf
in class AbstractDoubleList
List.lastIndexOf(Object)
public int size()
size
in interface java.util.Collection<java.lang.Double>
size
in interface java.util.List<java.lang.Double>
size
in class java.util.AbstractCollection<java.lang.Double>
public boolean isEmpty()
Stack
isEmpty
in interface Stack<java.lang.Double>
isEmpty
in interface java.util.Collection<java.lang.Double>
isEmpty
in interface java.util.List<java.lang.Double>
isEmpty
in class java.util.AbstractCollection<java.lang.Double>
public void getElements(int from, double[] a, int offset, int length)
getElements
in interface DoubleList
getElements
in class AbstractDoubleList
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(java.util.function.DoubleConsumer action)
AbstractDoubleList
Iterable
until all elements have been processed or the action throws an
exception.forEach
in interface DoubleIterable
forEach
in class AbstractDoubleList
action
- the action to be performed for each element.Iterable.forEach(java.util.function.Consumer)
public double[] toDoubleArray()
DoubleCollection
toDoubleArray
in interface DoubleCollection
toDoubleArray
in class AbstractDoubleList
Collection.toArray()
public double[] toArray(double[] a)
DoubleCollection
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 DoubleCollection
toArray
in class AbstractDoubleList
a
- if this array is big enough, it will be used to store this collection.Collection.toArray(Object[])
public DoubleListIterator listIterator(int index)
AbstractDoubleList
listIterator
in interface DoubleList
listIterator
in interface java.util.List<java.lang.Double>
listIterator
in class AbstractDoubleList
List.listIterator(int)
public DoubleSpliterator spliterator()
DoubleList
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 DoubleCollection
spliterator
in interface DoubleIterable
spliterator
in interface DoubleList
spliterator
in interface java.lang.Iterable<java.lang.Double>
spliterator
in interface java.util.Collection<java.lang.Double>
spliterator
in interface java.util.List<java.lang.Double>
public DoubleList subList(int from, int to)
from
, inclusive, to the index to
, exclusive.subList
in interface DoubleList
subList
in interface java.util.List<java.lang.Double>
subList
in class AbstractDoubleList
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 DoubleImmutableList clone()
clone
in class java.lang.Object
public boolean equals(DoubleImmutableList l)
l
- a type-specific immutable list.public boolean equals(java.lang.Object o)
equals
in interface java.util.Collection<java.lang.Double>
equals
in interface java.util.List<java.lang.Double>
equals
in class AbstractDoubleList
public int compareTo(DoubleImmutableList l)
l
- an immutable list.public int compareTo(java.util.List<? extends java.lang.Double> l)
AbstractDoubleList
List
, this method performs a lexicographical comparison; otherwise,
it throws a ClassCastException
.compareTo
in interface java.lang.Comparable<java.util.List<? extends java.lang.Double>>
compareTo
in class AbstractDoubleList
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, double k)
AbstractDoubleList
add
in interface DoubleList
add
in class AbstractDoubleList
List.add(int,Object)
UnsupportedOperationException
as this is an immutable type.@Deprecated public final boolean add(double k)
AbstractDoubleList
add
in interface DoubleCollection
add
in interface DoubleList
add
in class AbstractDoubleList
Collection.add(Object)
UnsupportedOperationException
as this is an immutable type.@Deprecated public final boolean addAll(java.util.Collection<? extends java.lang.Double> c)
AbstractDoubleList
addAll
in interface java.util.Collection<java.lang.Double>
addAll
in interface java.util.List<java.lang.Double>
addAll
in class AbstractDoubleList
UnsupportedOperationException
as this is an immutable type.@Deprecated public final boolean addAll(int index, java.util.Collection<? extends java.lang.Double> c)
AbstractDoubleList
addAll
in interface java.util.List<java.lang.Double>
addAll
in class AbstractDoubleList
UnsupportedOperationException
as this is an immutable type.@Deprecated public final double removeDouble(int index)
AbstractDoubleList
removeDouble
in interface DoubleList
removeDouble
in class AbstractDoubleList
List.remove(int)
UnsupportedOperationException
as this is an immutable type.@Deprecated public final boolean rem(double k)
AbstractDoubleList
rem
in interface DoubleCollection
rem
in class AbstractDoubleList
List.remove(Object)
UnsupportedOperationException
as this is an immutable type.@Deprecated public final boolean removeAll(java.util.Collection<?> c)
AbstractDoubleCollection
removeAll
in interface java.util.Collection<java.lang.Double>
removeAll
in interface java.util.List<java.lang.Double>
removeAll
in class AbstractDoubleCollection
UnsupportedOperationException
as this is an immutable type.@Deprecated public final boolean retainAll(java.util.Collection<?> c)
AbstractDoubleCollection
retainAll
in interface java.util.Collection<java.lang.Double>
retainAll
in interface java.util.List<java.lang.Double>
retainAll
in class AbstractDoubleCollection
UnsupportedOperationException
as this is an immutable type.@Deprecated public final boolean removeIf(java.util.function.Predicate<? super java.lang.Double> c)
DoubleCollection
removeIf
in interface DoubleCollection
removeIf
in interface java.util.Collection<java.lang.Double>
UnsupportedOperationException
as this is an immutable type.@Deprecated public final boolean removeIf(java.util.function.DoublePredicate c)
DoubleCollection
removeIf
in interface DoubleCollection
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.Double> operator)
DoubleList
replaceAll
in interface DoubleList
replaceAll
in interface java.util.List<java.lang.Double>
UnsupportedOperationException
as this is an immutable type.@Deprecated public final void replaceAll(java.util.function.DoubleUnaryOperator operator)
DoubleList
replaceAll
in interface DoubleList
operator
- the operator to apply to each element.List.replaceAll(java.util.function.UnaryOperator<E>)
UnsupportedOperationException
as this is an immutable type.@Deprecated public final void add(int index, java.lang.Double k)
DoubleList
add
in interface DoubleList
add
in interface java.util.List<java.lang.Double>
UnsupportedOperationException
as this is an immutable type.@Deprecated public final boolean add(java.lang.Double k)
AbstractDoubleCollection
add
in interface DoubleCollection
add
in interface DoubleList
add
in interface java.util.Collection<java.lang.Double>
add
in interface java.util.List<java.lang.Double>
add
in class AbstractDoubleCollection
UnsupportedOperationException
as this is an immutable type.@Deprecated public final java.lang.Double remove(int index)
DoubleList
remove
in interface DoubleList
remove
in interface java.util.List<java.lang.Double>
UnsupportedOperationException
as this is an immutable type.@Deprecated public final boolean remove(java.lang.Object k)
AbstractDoubleCollection
remove
in interface DoubleCollection
remove
in interface DoubleList
remove
in interface java.util.Collection<java.lang.Double>
remove
in interface java.util.List<java.lang.Double>
remove
in class AbstractDoubleCollection
UnsupportedOperationException
as this is an immutable type.@Deprecated public final java.lang.Double set(int index, java.lang.Double k)
DoubleList
set
in interface DoubleList
set
in interface java.util.List<java.lang.Double>
UnsupportedOperationException
as this is an immutable type.@Deprecated public final boolean addAll(DoubleCollection c)
AbstractDoubleList
addAll
in interface DoubleCollection
addAll
in class AbstractDoubleList
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(DoubleList c)
DoubleList
addAll
in interface DoubleList
List.addAll(Collection)
UnsupportedOperationException
as this is an immutable type.@Deprecated public final boolean addAll(int index, DoubleCollection c)
DoubleList
addAll
in interface DoubleList
addAll
in class AbstractDoubleList
List.addAll(int,java.util.Collection)
UnsupportedOperationException
as this is an immutable type.@Deprecated public final boolean addAll(int index, DoubleList c)
DoubleList
addAll
in interface DoubleList
List.addAll(int,Collection)
UnsupportedOperationException
as this is an immutable type.@Deprecated public final boolean removeAll(DoubleCollection c)
DoubleCollection
removeAll
in interface DoubleCollection
removeAll
in class AbstractDoubleCollection
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(DoubleCollection c)
DoubleCollection
retainAll
in interface DoubleCollection
retainAll
in class AbstractDoubleCollection
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 double set(int index, double k)
AbstractDoubleList
set
in interface DoubleList
set
in class AbstractDoubleList
List.set(int,Object)
UnsupportedOperationException
as this is an immutable type.@Deprecated public final void clear()
AbstractDoubleList
clear
in interface java.util.Collection<java.lang.Double>
clear
in interface java.util.List<java.lang.Double>
clear
in class AbstractDoubleList
UnsupportedOperationException
as this is an immutable type.@Deprecated public final void size(int size)
DoubleList
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 DoubleList
size
in class AbstractDoubleList
size
- the new size.UnsupportedOperationException
as this is an immutable type.@Deprecated public final void removeElements(int from, int to)
AbstractDoubleList
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 DoubleList
removeElements
in class AbstractDoubleList
from
- the start index (inclusive).to
- the end index (exclusive).UnsupportedOperationException
as this is an immutable type.@Deprecated public final void addElements(int index, double[] a, int offset, int length)
AbstractDoubleList
This is a trivial iterator-based implementation. It is expected that implementations will override this method with a more optimized version.
addElements
in interface DoubleList
addElements
in class AbstractDoubleList
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, double[] a, int offset, int length)
DoubleList
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 DoubleList
setElements
in class AbstractDoubleList
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(DoubleComparator comp)
DoubleList
Pass null
to sort using natural ordering.
sort
in interface DoubleList
List.sort(java.util.Comparator)
UnsupportedOperationException
as this is an immutable type.@Deprecated public final void unstableSort(DoubleComparator comp)
DoubleList
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 DoubleList
UnsupportedOperationException
as this is an immutable type.@Deprecated public final void sort(java.util.Comparator<? super java.lang.Double> comparator)
DoubleList
sort
in interface DoubleList
sort
in interface java.util.List<java.lang.Double>
UnsupportedOperationException
as this is an immutable type.@Deprecated public final void unstableSort(java.util.Comparator<? super java.lang.Double> comparator)
DoubleList
unstableSort
in interface DoubleList
UnsupportedOperationException
as this is an immutable type.