DoubleList
public sealed class DoubleList
MutableDoubleList |
|
DoubleList is a List-like collection for Double values. It allows retrieving the elements without boxing. DoubleList is always backed by a MutableDoubleList, its MutableList-like subclass. The purpose of this class is to avoid the performance overhead of auto-boxing due to generics since Collection classes all operate on objects.
This implementation is not thread-safe: if multiple threads access this container concurrently, and one or more threads modify the structure of the list (insertion or removal for instance), the calling code must provide the appropriate synchronization. It is also not safe to mutate during reentrancy -- in the middle of a forEach, for example. However, concurrent reads are safe.
Summary
Protected constructors |
|---|
DoubleList(int initialCapacity) |
Public methods |
|
|---|---|
final boolean |
any()Returns |
final boolean |
Returns |
final int |
binarySearch(int element, int fromIndex, int toIndex)Searches this list the specified element in the range defined by |
final boolean |
contains(double element)Returns |
final boolean |
containsAll(@NonNull DoubleList elements)Returns |
final int |
count()Returns the number of elements in this list. |
final int |
Counts the number of elements matching |
final double |
Returns the element at the given |
final double |
elementAtOrElse(Returns the element at the given |
boolean |
Returns |
final double |
first()Returns the first element in the |
final double |
Returns the first element in the |
final @NonNull R |
<R extends Object> fold(Accumulates values, starting with |
final @NonNull R |
<R extends Object> foldIndexed(Accumulates values, starting with |
final @NonNull R |
<R extends Object> foldRight(Accumulates values, starting with |
final @NonNull R |
<R extends Object> foldRightIndexed(Accumulates values, starting with |
final void |
Calls |
final void |
Calls |
final void |
forEachReversed(@NonNull Function1<@NonNull Double, Unit> block)Calls |
final void |
Calls |
final double |
Returns the element at the given |
final @NonNull IntRange |
Returns an |
final @IntRange(from = -1) int |
Returns the last valid index in the |
final @IntRange(from = 0) int |
getSize()The number of elements in the |
int |
hashCode()Returns a hash code based on the contents of the |
final int |
indexOf(double element)Returns the index of |
final int |
Returns the index if the first element in the |
final int |
Returns the index if the last element in the |
final boolean |
isEmpty()Returns |
final boolean |
Returns |
final @NonNull String |
joinToString(Creates a String from the elements separated by |
final @NonNull String |
joinToString(Creates a String from the elements separated by |
final double |
last()Returns the last element in the |
final double |
Returns the last element in the |
final int |
lastIndexOf(double element)Returns the index of the last element in the |
final boolean |
none()Returns |
final boolean |
Returns |
@NonNull String |
toString()Returns a String representation of the list, surrounded by "[]" and each element separated by ", ". |
Protected constructors
Public methods
any
public final boolean any()
Returns true if there's at least one element in the collection.
any
public final boolean any(@NonNull Function1<@NonNull Double, @NonNull Boolean> predicate)
Returns true if any of the elements give a true return value for predicate.
binarySearch
public final int binarySearch(int element, int fromIndex, int toIndex)
Searches this list the specified element in the range defined by fromIndex and toIndex. The list is expected to be sorted into ascending order according to the natural ordering of its elements, otherwise the result is undefined.
fromIndex must be >= 0 and <toIndex, and toIndex must be <= size, otherwise an an IndexOutOfBoundsException will be thrown.
| Returns | |
|---|---|
int |
the index of the element if it is contained in the list within the specified range. otherwise, the inverted insertion point |
contains
public final boolean contains(double element)
Returns true if the DoubleList contains element or false otherwise.
containsAll
public final boolean containsAll(@NonNull DoubleList elements)
Returns true if the DoubleList contains all elements in elements or false if one or more are missing.
count
public final int count(@NonNull Function1<@NonNull Double, @NonNull Boolean> predicate)
Counts the number of elements matching predicate.
| Returns | |
|---|---|
int |
The number of elements in this list for which |
elementAt
public final double elementAt(@IntRange(from = 0) int index)
Returns the element at the given index or throws IndexOutOfBoundsException if the index is out of bounds of this collection.
elementAtOrElse
public final double elementAtOrElse(
@IntRange(from = 0) int index,
@NonNull Function1<@NonNull Integer, @NonNull Double> defaultValue
)
Returns the element at the given index or defaultValue if index is out of bounds of the collection.
equals
public boolean equals(Object other)
Returns true if other is a DoubleList and the contents of this and other are the same.
first
public final double first()
Returns the first element in the DoubleList or throws a NoSuchElementException if it isEmpty.
first
public final double first(@NonNull Function1<@NonNull Double, @NonNull Boolean> predicate)
Returns the first element in the DoubleList for which predicate returns true or throws NoSuchElementException if nothing matches.
| See also | |
|---|---|
indexOfFirst |
fold
public final @NonNull R <R extends Object> fold(
@NonNull R initial,
@NonNull Function2<@NonNull acc, @NonNull Double, @NonNull R> operation
)
Accumulates values, starting with initial, and applying operation to each element in the DoubleList in order.
| Parameters | |
|---|---|
@NonNull R initial |
The value of |
@NonNull Function2<@NonNull acc, @NonNull Double, @NonNull R> operation |
function that takes current accumulator value and an element, and calculates the next accumulator value. |
foldIndexed
public final @NonNull R <R extends Object> foldIndexed(
@NonNull R initial,
@NonNull Function3<@NonNull Integer, @NonNull acc, @NonNull Double, @NonNull R> operation
)
Accumulates values, starting with initial, and applying operation to each element in the DoubleList in order.
foldRight
public final @NonNull R <R extends Object> foldRight(
@NonNull R initial,
@NonNull Function2<@NonNull Double, @NonNull acc, @NonNull R> operation
)
Accumulates values, starting with initial, and applying operation to each element in the DoubleList in reverse order.
| Parameters | |
|---|---|
@NonNull R initial |
The value of |
@NonNull Function2<@NonNull Double, @NonNull acc, @NonNull R> operation |
function that takes an element and the current accumulator value, and calculates the next accumulator value. |
foldRightIndexed
public final @NonNull R <R extends Object> foldRightIndexed(
@NonNull R initial,
@NonNull Function3<@NonNull Integer, @NonNull Double, @NonNull acc, @NonNull R> operation
)
Accumulates values, starting with initial, and applying operation to each element in the DoubleList in reverse order.
forEach
public final void forEach(@NonNull Function1<@NonNull Double, Unit> block)
Calls block for each element in the DoubleList, in order.
forEachIndexed
public final void forEachIndexed(
@NonNull Function2<@NonNull Integer, @NonNull Double, Unit> block
)
Calls block for each element in the DoubleList along with its index, in order.
forEachReversed
public final void forEachReversed(@NonNull Function1<@NonNull Double, Unit> block)
Calls block for each element in the DoubleList in reverse order.
forEachReversedIndexed
public final void forEachReversedIndexed(
@NonNull Function2<@NonNull Integer, @NonNull Double, Unit> block
)
Calls block for each element in the DoubleList along with its index, in reverse order.
get
public final double get(@IntRange(from = 0) int index)
Returns the element at the given index or throws IndexOutOfBoundsException if the index is out of bounds of this collection.
getIndices
public final @NonNull IntRange getIndices()
Returns an IntRange of the valid indices for this DoubleList.
getLastIndex
public final @IntRange(from = -1) int getLastIndex()
Returns the last valid index in the DoubleList. This can be -1 when the list is empty.
getSize
public final @IntRange(from = 0) int getSize()
The number of elements in the DoubleList.
indexOf
public final int indexOf(double element)
Returns the index of element in the DoubleList or -1 if element is not there.
indexOfFirst
public final int indexOfFirst(
@NonNull Function1<@NonNull Double, @NonNull Boolean> predicate
)
Returns the index if the first element in the DoubleList for which predicate returns true.
indexOfLast
public final int indexOfLast(@NonNull Function1<@NonNull Double, @NonNull Boolean> predicate)
Returns the index if the last element in the DoubleList for which predicate returns true.
isEmpty
public final boolean isEmpty()
Returns true if the DoubleList has no elements in it or false otherwise.
isNotEmpty
public final boolean isNotEmpty()
Returns true if there are elements in the DoubleList or false if it is empty.
joinToString
public final @NonNull String joinToString(
@NonNull CharSequence separator,
@NonNull CharSequence prefix,
@NonNull CharSequence postfix,
int limit,
@NonNull CharSequence truncated
)
Creates a String from the elements separated by separator and using prefix before and postfix after, if supplied.
When a non-negative value of limit is provided, a maximum of limit items are used to generate the string. If the collection holds more than limit items, the string is terminated with truncated.
joinToString
public final @NonNull String joinToString(
@NonNull CharSequence separator,
@NonNull CharSequence prefix,
@NonNull CharSequence postfix,
int limit,
@NonNull CharSequence truncated,
@NonNull Function1<@NonNull Double, @NonNull CharSequence> transform
)
Creates a String from the elements separated by separator and using prefix before and postfix after, if supplied. transform dictates how each element will be represented.
When a non-negative value of limit is provided, a maximum of limit items are used to generate the string. If the collection holds more than limit items, the string is terminated with truncated.
last
public final double last()
Returns the last element in the DoubleList or throws a NoSuchElementException if it isEmpty.
last
public final double last(@NonNull Function1<@NonNull Double, @NonNull Boolean> predicate)
Returns the last element in the DoubleList for which predicate returns true or throws NoSuchElementException if nothing matches.
| See also | |
|---|---|
indexOfLast |
lastIndexOf
public final int lastIndexOf(double element)
Returns the index of the last element in the DoubleList that is the same as element or -1 if no elements match.
none
public final boolean none()
Returns true if the collection has no elements in it.