double values, with an API resembling List.
Advantages compared to double[]:
equals, hashCode, and toString behavior you expect.
get and length, so you don't have to
hunt through classes like Arrays and Doubles for them.
subArray view, so methods that accept this type don't need to
add overloads that accept start and end indexes.
foo.getBarDoubles().stream()....
asList (though at the cost of
allocating garbage).
Disadvantages compared to double[]:
double[] (though the most common
utilities do have replacements here).
com.google.common / Guava.
Advantages compared to ImmutableList<Double>:
DoubleStream features (like DoubleStream#sum) using stream() instead of the awkward stream().mapToDouble(v -> v).
Disadvantages compared to ImmutableList<Double>:
Iterable, Collection, or
List (though the most common utilities do have replacements here, and there is a
lazy asList view).
| Modifier and Type | Class and Description |
|---|---|
| pack-priv static class | |
| public static class | ImmutableDoubleArray.Builder
A builder for |
| Modifier and Type | Field and Description |
|---|---|
| private final double[] | |
| private static final ImmutableDoubleArray | |
| private final int | |
| private final transient int |
| Access | Constructor and Description |
|---|---|
| private | |
| private |
| Modifier and Type | Method and Description |
|---|---|
| private static boolean | |
| public List | |
| public static ImmutableDoubleArray. | builder(int initialCapacity)
Returns a new, empty builder for |
| public static ImmutableDoubleArray. | builder()
Returns a new, empty builder for |
| public boolean | |
| public static ImmutableDoubleArray | |
| public static ImmutableDoubleArray | |
| public static ImmutableDoubleArray | |
| public static ImmutableDoubleArray | copyOf(DoubleStream stream)
Returns an immutable array containing all the values from |
| public boolean | equals(Object
the reference object with which to compare. object)Overrides java. true if object is an ImmutableDoubleArray containing the same
values as this one, in the same order.
|
| public void | |
| public double | |
| public int | hashCode()
Overrides java. |
| public int | |
| public boolean | |
| private boolean | |
| public int | lastIndexOf(double target)
Returns the largest index for which |
| public int | |
| public static ImmutableDoubleArray | |
| public static ImmutableDoubleArray | |
| public static ImmutableDoubleArray | |
| public static ImmutableDoubleArray | of(double e0, double e1, double e2)
Returns an immutable array containing the given values, in order. |
| public static ImmutableDoubleArray | of(double e0, double e1, double e2, double e3)
Returns an immutable array containing the given values, in order. |
| public static ImmutableDoubleArray | of(double e0, double e1, double e2, double e3, double e4)
Returns an immutable array containing the given values, in order. |
| public static ImmutableDoubleArray | of(double e0, double e1, double e2, double e3, double e4, double e5)
Returns an immutable array containing the given values, in order. |
| public static ImmutableDoubleArray | |
| pack-priv Object | |
| private Spliterator. | |
| public DoubleStream | |
| public ImmutableDoubleArray | subArray(int startIndex, int endIndex)
Returns a new immutable array containing the values in the specified range. |
| public double[] | |
| public String | toString()
Overrides java. Arrays#toString(double[]), for example "[1, 2, 3]".
|
| public ImmutableDoubleArray | |
| pack-priv Object |
| array | back to summary |
|---|---|
private final double[] array
| |
| EMPTY | back to summary |
|---|---|
| private static final ImmutableDoubleArray EMPTY | |
| end | back to summary |
|---|---|
| private final int end | |
| start | back to summary |
|---|---|
| private final transient int start | |
| ImmutableDoubleArray | back to summary |
|---|---|
| private ImmutableDoubleArray(double[] array) | |
| ImmutableDoubleArray | back to summary |
|---|---|
| private ImmutableDoubleArray(double[] array, int start, int end) | |
| areEqual | back to summary |
|---|---|
| private static boolean areEqual(double a, double b) | |
| asList | back to summary |
|---|---|
| public List Returns an immutable view of this array's values as a | |
| builder | back to summary |
|---|---|
| public static ImmutableDoubleArray. Returns a new, empty builder for Performance note: When feasible, | |
| builder | back to summary |
|---|---|
| public static ImmutableDoubleArray. Returns a new, empty builder for Performance note: The | |
| contains | back to summary |
|---|---|
| public boolean contains(double target) Returns | |
| copyOf | back to summary |
|---|---|
| public static ImmutableDoubleArray copyOf(double[] values) Returns an immutable array containing the given values, in order. | |
| copyOf | back to summary |
|---|---|
| public static ImmutableDoubleArray copyOf(Collection<Double> values) Returns an immutable array containing the given values, in order. | |
| copyOf | back to summary |
|---|---|
| public static ImmutableDoubleArray copyOf(Iterable<Double> values) Returns an immutable array containing the given values, in order. Performance note: this method delegates to | |
| copyOf | back to summary |
|---|---|
| public static ImmutableDoubleArray copyOf(DoubleStream stream) Returns an immutable array containing all the values from | |
| equals | back to summary |
|---|---|
| public boolean equals(Object object) Overrides java. Returns
| |
| forEach | back to summary |
|---|---|
| public void forEach(DoubleConsumer consumer) Invokes | |
| get | back to summary |
|---|---|
| public double get(int index) Returns the
| |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides java. Returns an unspecified hash code for the contents of this immutable array.
| |
| indexOf | back to summary |
|---|---|
| public int indexOf(double target) Returns the smallest index for which | |
| isEmpty | back to summary |
|---|---|
| public boolean isEmpty() Returns | |
| isPartialView | back to summary |
|---|---|
| private boolean isPartialView() | |
| lastIndexOf | back to summary |
|---|---|
| public int lastIndexOf(double target) Returns the largest index for which | |
| length | back to summary |
|---|---|
| public int length() Returns the number of values in this array. | |
| of | back to summary |
|---|---|
| public static ImmutableDoubleArray of() Returns the empty array. | |
| of | back to summary |
|---|---|
| public static ImmutableDoubleArray of(double e0) Returns an immutable array containing a single value. | |
| of | back to summary |
|---|---|
| public static ImmutableDoubleArray of(double e0, double e1) Returns an immutable array containing the given values, in order. | |
| of | back to summary |
|---|---|
| public static ImmutableDoubleArray of(double e0, double e1, double e2) Returns an immutable array containing the given values, in order. | |
| of | back to summary |
|---|---|
| public static ImmutableDoubleArray of(double e0, double e1, double e2, double e3) Returns an immutable array containing the given values, in order. | |
| of | back to summary |
|---|---|
| public static ImmutableDoubleArray of(double e0, double e1, double e2, double e3, double e4) Returns an immutable array containing the given values, in order. | |
| of | back to summary |
|---|---|
| public static ImmutableDoubleArray of(double e0, double e1, double e2, double e3, double e4, double e5) Returns an immutable array containing the given values, in order. | |
| of | back to summary |
|---|---|
| public static ImmutableDoubleArray of(double first, double... rest) Returns an immutable array containing the given values, in order. The array | |
| readResolve | back to summary |
|---|---|
| pack-priv Object readResolve() | |
| spliterator | back to summary |
|---|---|
| private Spliterator. | |
| stream | back to summary |
|---|---|
| public DoubleStream stream() Returns a stream over the values in this array, in order. | |
| subArray | back to summary |
|---|---|
| public ImmutableDoubleArray subArray(int startIndex, int endIndex) Returns a new immutable array containing the values in the specified range. Performance note: The returned array has the same full memory footprint as this one
does (no actual copying is performed). To reduce memory usage, use | |
| toArray | back to summary |
|---|---|
| public double[] toArray() Returns a new, mutable copy of this array's values, as a primitive | |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Returns a string representation of this array in the same form as
| |
| trimmed | back to summary |
|---|---|
| public ImmutableDoubleArray trimmed() Returns an immutable array containing the same values as | |
| writeReplace | back to summary |
|---|---|
| pack-priv Object writeReplace() | |
| Modifier and Type | Field and Description |
|---|---|
| private final ImmutableDoubleArray |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | contains(Object
element whose presence in this list is to be tested target)Overrides java. Implements java. true if this list contains the specified element.
|
| public boolean | equals(Object
the object to be compared for equality with this list object)Overrides java. Implements java. |
| public Double | get(int
index of the element to return index)Implements abstract java. Implements java. |
| public int | hashCode()
Overrides java. Implements java. |
| public int | indexOf(Object
element to search for target)Overrides java. Implements java. |
| public int | lastIndexOf(Object
element to search for target)Overrides java. Implements java. |
| public int | size()
Implements abstract java. Implements java. |
| public Spliterator | spliterator()
Overrides default java. Spliterator over the elements in this list.
|
| public List | subList(int
low endpoint (inclusive) of the subList fromIndex, int high endpoint (exclusive) of the subList toIndex)Overrides java. Implements java. fromIndex, inclusive, and toIndex, exclusive.
|
| public String | toString()
Overrides java. |
| parent | back to summary |
|---|---|
| private final ImmutableDoubleArray parent | |
| AsList | back to summary |
|---|---|
| private AsList(ImmutableDoubleArray parent) | |
| contains | back to summary |
|---|---|
| public boolean contains(Object target) Overrides java. Implements java. Doc from java. Returns | |
| equals | back to summary |
|---|---|
| public boolean equals(Object object) Overrides java. Implements java. Doc from java. Compares the specified object with this list for equality. Returns
| |
| get | back to summary |
|---|---|
| public Double get(int index) Implements abstract java. Implements java. Doc from java. Returns the element at the specified position in this list.
| |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides java. Implements java. Doc from java. Returns the hash code value for this list.
| |
| indexOf | back to summary |
|---|---|
| public int indexOf(Object target) Overrides java. Implements java. Doc from java. Returns the index of the first occurrence of the specified element
in this list, or -1 if this list does not contain the element.
More formally, returns the lowest index
| |
| lastIndexOf | back to summary |
|---|---|
| public int lastIndexOf(Object target) Overrides java. Implements java. Doc from java. Returns the index of the last occurrence of the specified element
in this list, or -1 if this list does not contain the element.
More formally, returns the highest index
| |
| size | back to summary |
|---|---|
| public int size() Implements abstract java. Implements java. Doc from java. Returns the number of elements in this list. If this list contains
more than
| |
| spliterator | back to summary |
|---|---|
| public Spliterator Overrides default java. Doc from java. Creates a The
| |
| subList | back to summary |
|---|---|
| public List Overrides java. Implements java. Doc from java. Returns a view of the portion of this list between the specified
This method eliminates the need for explicit range operations (of the sort that commonly exist for arrays). Any operation that expects a list can be used as a range operation by passing a subList view instead of a whole list. For example, the following idiom removes a range of elements from a list:
Similar idioms may be constructed for indexOf and
lastIndexOf, and all of the algorithms in the
Collections class can be applied to a subList.The semantics of the list returned by this method become undefined if the backing list (i.e., this list) is structurally modified in any way other than via the returned list. (Structural modifications are those that change the size of this list, or otherwise perturb it in such a fashion that iterations in progress may yield incorrect results.)
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of this collection. The string
representation consists of a list of the collection's elements in the
order they are returned by its iterator, enclosed in square brackets
( | |
ImmutableDoubleArray instances; obtained using ImmutableDoubleArray#builder.
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public ImmutableDoubleArray. | add(double value)
Appends |
| public ImmutableDoubleArray. | addAll(double[] values)
Appends |
| public ImmutableDoubleArray. | addAll(Iterable<Double> values)
Appends |
| public ImmutableDoubleArray. | addAll(Collection<Double> values)
Appends |
| public ImmutableDoubleArray. | addAll(DoubleStream stream)
Appends all values from |
| public ImmutableDoubleArray. | addAll(ImmutableDoubleArray values)
Appends |
| public ImmutableDoubleArray | |
| private void | |
| private static int |
| Builder | back to summary |
|---|---|
| pack-priv Builder(int initialCapacity) | |
| add | back to summary |
|---|---|
| public ImmutableDoubleArray. Appends
| |
| addAll | back to summary |
|---|---|
| public ImmutableDoubleArray. Appends
| |
| addAll | back to summary |
|---|---|
| public ImmutableDoubleArray. Appends
| |
| addAll | back to summary |
|---|---|
| public ImmutableDoubleArray. Appends
| |
| addAll | back to summary |
|---|---|
| public ImmutableDoubleArray. Appends all values from
| |
| addAll | back to summary |
|---|---|
| public ImmutableDoubleArray. Appends
| |
| build | back to summary |
|---|---|
| public ImmutableDoubleArray build() Returns a new immutable array. The builder can continue to be used after this call, to append more values and build again. Performance note: the returned array is backed by the same array as the builder, so
no data is copied as part of this step, but this may occupy more memory than strictly
necessary. To copy the data to a right-sized backing array, use | |
| ensureRoomFor | back to summary |
|---|---|
| private void ensureRoomFor(int numberToAdd) | |
| expandedCapacity | back to summary |
|---|---|
| private static int expandedCapacity(int oldCapacity, int minCapacity) | |