Top Description Inners Fields Constructors Methods
com.google.common.primitives

public final Class ImmutableDoubleArray

extends Object
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Annotations
@GwtCompatible
@Immutable
@ElementTypesAreNonnullByDefault
Static Imports
com.google.common.base.Preconditions.checkArgument, .Preconditions.checkNotNull

An immutable array of double values, with an API resembling List.

Advantages compared to double[]:

Disadvantages compared to double[]:

Advantages compared to ImmutableList<Double>:

Disadvantages compared to ImmutableList<Double>:

Since
22.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
public static class

Field Summary

Modifier and TypeField and Description
private final double[]
private static final ImmutableDoubleArray
private final int
private final transient int

Constructor Summary

AccessConstructor and Description
private
ImmutableDoubleArray(double[] array)

private
ImmutableDoubleArray(double[] array, int start, int end)

Method Summary

Modifier and TypeMethod and Description
private static boolean
areEqual(double a, double b)

public List<Double>
asList()

Returns an immutable view of this array's values as a List; note that double values are boxed into Double instances on demand, which can be very expensive.

public static ImmutableDoubleArray.Builder
builder(int initialCapacity)

Returns a new, empty builder for ImmutableDoubleArray instances, sized to hold up to initialCapacity values without resizing.

public static ImmutableDoubleArray.Builder
builder()

Returns a new, empty builder for ImmutableDoubleArray instances, with a default initial capacity.

public boolean
contains(double target)

Returns true if target is present at any index in this array.

public static ImmutableDoubleArray
copyOf(double[] values)

Returns an immutable array containing the given values, in order.

public static ImmutableDoubleArray
copyOf(Collection<Double> values)

Returns an immutable array containing the given values, in order.

public static ImmutableDoubleArray
copyOf(Iterable<Double> values)

Returns an immutable array containing the given values, in order.

public static ImmutableDoubleArray
copyOf(DoubleStream stream)

Returns an immutable array containing all the values from stream, in order.

public boolean
equals(Object
the reference object with which to compare.
object
)

Overrides java.lang.Object.equals.

Returns true if object is an ImmutableDoubleArray containing the same values as this one, in the same order.
public void
forEach(DoubleConsumer consumer)

Invokes consumer for each value contained in this array, in order.

public double
get(int index)

Returns the double value present at the given index.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns an unspecified hash code for the contents of this immutable array.
public int
indexOf(double target)

Returns the smallest index for which get returns target, or -1 if no such index exists.

public boolean
isEmpty()

Returns true if there are no values in this array (length is zero).

private boolean
public int
lastIndexOf(double target)

Returns the largest index for which get returns target, or -1 if no such index exists.

public int
length()

Returns the number of values in this array.

public static ImmutableDoubleArray
of()

Returns the empty array.

public static ImmutableDoubleArray
of(double e0)

Returns an immutable array containing a single value.

public static ImmutableDoubleArray
of(double e0, double e1)

Returns an immutable array containing the given values, in order.

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
of(double first, double... rest)

Returns an immutable array containing the given values, in order.

pack-priv Object
private Spliterator.OfDouble
public DoubleStream
stream()

Returns a stream over the values in this array, in order.

public ImmutableDoubleArray
subArray(int startIndex, int endIndex)

Returns a new immutable array containing the values in the specified range.

public double[]
toArray()

Returns a new, mutable copy of this array's values, as a primitive double[].

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of this array in the same form as Arrays#toString(double[]), for example "[1, 2, 3]".
public ImmutableDoubleArray
trimmed()

Returns an immutable array containing the same values as this array.

pack-priv Object
Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

arrayback to summary
private final double[] array
Annotations
@SuppressWarnings:Immutable
EMPTYback to summary
private static final ImmutableDoubleArray EMPTY
endback to summary
private final int end
startback to summary
private final transient int start

Constructor Detail

ImmutableDoubleArrayback to summary
private ImmutableDoubleArray(double[] array)
ImmutableDoubleArrayback to summary
private ImmutableDoubleArray(double[] array, int start, int end)

Method Detail

areEqualback to summary
private static boolean areEqual(double a, double b)
asListback to summary
public List<Double> asList()

Returns an immutable view of this array's values as a List; note that double values are boxed into Double instances on demand, which can be very expensive. The returned list should be used once and discarded. For any usages beyond that, pass the returned list to ImmutableList.copyOf and use that list instead.

builderback to summary
public static ImmutableDoubleArray.Builder builder(int initialCapacity)

Returns a new, empty builder for ImmutableDoubleArray instances, sized to hold up to initialCapacity values without resizing. The returned builder is not thread-safe.

Performance note: When feasible, initialCapacity should be the exact number of values that will be added, if that knowledge is readily available. It is better to guess a value slightly too high than slightly too low. If the value is not exact, the ImmutableDoubleArray that is built will very likely occupy more memory than strictly necessary; to trim memory usage, build using builder.build().trimmed().

builderback to summary
public static ImmutableDoubleArray.Builder builder()

Returns a new, empty builder for ImmutableDoubleArray instances, with a default initial capacity. The returned builder is not thread-safe.

Performance note: The ImmutableDoubleArray that is built will very likely occupy more memory than necessary; to trim memory usage, build using builder.build().trimmed().

containsback to summary
public boolean contains(double target)

Returns true if target is present at any index in this array. Values are compared as if by Double#equals. Equivalent to asList().contains(target).

copyOfback to summary
public static ImmutableDoubleArray copyOf(double[] values)

Returns an immutable array containing the given values, in order.

copyOfback to summary
public static ImmutableDoubleArray copyOf(Collection<Double> values)

Returns an immutable array containing the given values, in order.

copyOfback 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(Collection) if values is a Collection. Otherwise it creates a builder and uses Builder#addAll(Iterable), with all the performance implications associated with that.

copyOfback to summary
public static ImmutableDoubleArray copyOf(DoubleStream stream)

Returns an immutable array containing all the values from stream, in order.

equalsback to summary
public boolean equals(Object object)

Overrides java.lang.Object.equals.

Returns true if object is an ImmutableDoubleArray containing the same values as this one, in the same order. Values are compared as if by Double#equals.

Parameters
object:Object

Doc from java.lang.Object.equals.

the reference object with which to compare.

Returns:boolean

Doc from java.lang.Object.equals.

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
forEachback to summary
public void forEach(DoubleConsumer consumer)

Invokes consumer for each value contained in this array, in order.

getback to summary
public double get(int index)

Returns the double value present at the given index.

Exceptions
IndexOutOfBoundsException:
if index is negative, or greater than or equal to length
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Returns an unspecified hash code for the contents of this immutable array.

Returns:int

Doc from java.lang.Object.hashCode.

a hash code value for this object.

Annotations
@Override
indexOfback to summary
public int indexOf(double target)

Returns the smallest index for which get returns target, or -1 if no such index exists. Values are compared as if by Double#equals. Equivalent to asList().indexOf(target).

isEmptyback to summary
public boolean isEmpty()

Returns true if there are no values in this array (length is zero).

isPartialViewback to summary
private boolean isPartialView()
lastIndexOfback to summary
public int lastIndexOf(double target)

Returns the largest index for which get returns target, or -1 if no such index exists. Values are compared as if by Double#equals. Equivalent to asList().lastIndexOf(target).

lengthback to summary
public int length()

Returns the number of values in this array.

ofback to summary
public static ImmutableDoubleArray of()

Returns the empty array.

ofback to summary
public static ImmutableDoubleArray of(double e0)

Returns an immutable array containing a single value.

ofback to summary
public static ImmutableDoubleArray of(double e0, double e1)

Returns an immutable array containing the given values, in order.

ofback to summary
public static ImmutableDoubleArray of(double e0, double e1, double e2)

Returns an immutable array containing the given values, in order.

ofback to summary
public static ImmutableDoubleArray of(double e0, double e1, double e2, double e3)

Returns an immutable array containing the given values, in order.

ofback 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.

ofback 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.

ofback to summary
public static ImmutableDoubleArray of(double first, double... rest)

Returns an immutable array containing the given values, in order.

The array rest must not be longer than Integer.MAX_VALUE - 1.

readResolveback to summary
pack-priv Object readResolve()
spliteratorback to summary
private Spliterator.OfDouble spliterator()
streamback to summary
public DoubleStream stream()

Returns a stream over the values in this array, in order.

subArrayback 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 subArray(start, end).trimmed().

toArrayback to summary
public double[] toArray()

Returns a new, mutable copy of this array's values, as a primitive double[].

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Returns a string representation of this array in the same form as Arrays#toString(double[]), for example "[1, 2, 3]".

Returns:String

Doc from java.lang.Object.toString.

a string representation of the object.

Annotations
@Override
trimmedback to summary
public ImmutableDoubleArray trimmed()

Returns an immutable array containing the same values as this array. This is logically a no-op, and in some circumstances this itself is returned. However, if this instance is a subArray view of a larger array, this method will copy only the appropriate range of values, resulting in an equivalent array with a smaller memory footprint.

writeReplaceback to summary
pack-priv Object writeReplace()
com.google.common.primitives back to summary

pack-priv Class ImmutableDoubleArray.AsList

extends AbstractList<Double>
implements RandomAccess, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, java.util.RandomAccess

Field Summary

Modifier and TypeField and Description
private final ImmutableDoubleArray
Inherited from java.util.AbstractList:
modCount

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public boolean
contains(Object
element whose presence in this list is to be tested
target
)

Overrides java.util.AbstractCollection.contains.

Implements java.util.List.contains, java.util.Collection.contains.

Returns 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.util.AbstractList.equals.

Implements java.util.List.equals, java.util.Collection.equals.

Compares the specified object with this list for equality.
public Double
get(int
index of the element to return
index
)

Implements abstract java.util.AbstractList.get.

Implements java.util.List.get.

Returns the element at the specified position in this list.
public int
hashCode()

Overrides java.util.AbstractList.hashCode.

Implements java.util.List.hashCode, java.util.Collection.hashCode.

Returns the hash code value for this list.
public int
indexOf(Object
element to search for
target
)

Overrides java.util.AbstractList.indexOf.

Implements java.util.List.indexOf.

Returns the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element.
public int
lastIndexOf(Object
element to search for
target
)

Overrides java.util.AbstractList.lastIndexOf.

Implements java.util.List.lastIndexOf.

Returns the index of the last occurrence of the specified element in this list, or -1 if this list does not contain the element.
public int
size()

Implements abstract java.util.AbstractCollection.size.

Implements java.util.List.size, java.util.Collection.size.

Returns the number of elements in this list.
public Spliterator<Double>
spliterator()

Overrides default java.util.List.spliterator, java.util.Collection.spliterator.

Creates a Spliterator over the elements in this list.
public List<Double>
subList(int
low endpoint (inclusive) of the subList
fromIndex
,
int
high endpoint (exclusive) of the subList
toIndex
)

Overrides java.util.AbstractList.subList.

Implements java.util.List.subList.

Returns a view of the portion of this list between the specified fromIndex, inclusive, and toIndex, exclusive.
public String
toString()

Overrides java.util.AbstractCollection.toString.

Returns a string representation of this collection.
Inherited from java.util.AbstractList:
addaddaddAllcleariteratorlistIteratorlistIteratorremoveremoveRangeset

Field Detail

parentback to summary
private final ImmutableDoubleArray parent

Constructor Detail

AsListback to summary
private AsList(ImmutableDoubleArray parent)

Method Detail

containsback to summary
public boolean contains(Object target)

Overrides java.util.AbstractCollection.contains.

Implements java.util.List.contains, java.util.Collection.contains.

Doc from java.util.List.contains.

Returns true if this list contains the specified element. More formally, returns true if and only if this list contains at least one element e such that Objects.equals(o, e).

Parameters
target:Object

element whose presence in this list is to be tested

Returns:boolean

true if this list contains the specified element

Annotations
@Override
equalsback to summary
public boolean equals(Object object)

Overrides java.util.AbstractList.equals.

Implements java.util.List.equals, java.util.Collection.equals.

Doc from java.util.AbstractList.equals.

Compares the specified object with this list for equality. Returns true if and only if the specified object is also a list, both lists have the same size, and all corresponding pairs of elements in the two lists are equal. (Two elements e1 and e2 are equal if (e1==null ? e2==null : e1.equals(e2)).) In other words, two lists are defined to be equal if they contain the same elements in the same order.

Parameters
object:Object

the object to be compared for equality with this list

Returns:boolean

true if the specified object is equal to this list

Annotations
@Override
getback to summary
public Double get(int index)

Implements abstract java.util.AbstractList.get.

Implements java.util.List.get.

Doc from java.util.AbstractList.get.

Returns the element at the specified position in this list.

Parameters
index:int

Doc from java.util.List.get.

index of the element to return

Returns:Double

Doc from java.util.List.get.

the element at the specified position in this list

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides java.util.AbstractList.hashCode.

Implements java.util.List.hashCode, java.util.Collection.hashCode.

Doc from java.util.AbstractList.hashCode.

Returns the hash code value for this list.

Returns:int

the hash code value for this list

Annotations
@Override
indexOfback to summary
public int indexOf(Object target)

Overrides java.util.AbstractList.indexOf.

Implements java.util.List.indexOf.

Doc from java.util.AbstractList.indexOf.

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 i such that Objects.equals(o, get(i)), or -1 if there is no such index.

Parameters
target:Object

Doc from java.util.List.indexOf.

element to search for

Returns:int

Doc from java.util.List.indexOf.

the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element

Annotations
@Override
lastIndexOfback to summary
public int lastIndexOf(Object target)

Overrides java.util.AbstractList.lastIndexOf.

Implements java.util.List.lastIndexOf.

Doc from java.util.AbstractList.lastIndexOf.

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 i such that Objects.equals(o, get(i)), or -1 if there is no such index.

Parameters
target:Object

Doc from java.util.List.lastIndexOf.

element to search for

Returns:int

Doc from java.util.List.lastIndexOf.

the index of the last occurrence of the specified element in this list, or -1 if this list does not contain the element

Annotations
@Override
sizeback to summary
public int size()

Implements abstract java.util.AbstractCollection.size.

Implements java.util.List.size, java.util.Collection.size.

Doc from java.util.List.size.

Returns the number of elements in this list. If this list contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.

Returns:int

the number of elements in this list

Annotations
@Override
spliteratorback to summary
public Spliterator<Double> spliterator()

Overrides default java.util.List.spliterator, java.util.Collection.spliterator.

Doc from java.util.List.spliterator.

Creates a Spliterator over the elements in this list.

The Spliterator reports Spliterator#SIZED and Spliterator#ORDERED. Implementations should document the reporting of additional characteristic values.

Returns:Spliterator<Double>

a Spliterator over the elements in this list

Annotations
@Override
subListback to summary
public List<Double> subList(int fromIndex, int toIndex)

Overrides java.util.AbstractList.subList.

Implements java.util.List.subList.

Doc from java.util.AbstractList.subList.

Returns a view of the portion of this list between the specified fromIndex, inclusive, and toIndex, exclusive. (If fromIndex and toIndex are equal, the returned list is empty.) The returned list is backed by this list, so non-structural changes in the returned list are reflected in this list, and vice-versa. The returned list supports all of the optional list operations supported by this list.

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:

list.subList(from, to).clear();
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.)

Parameters
fromIndex:int

Doc from java.util.List.subList.

low endpoint (inclusive) of the subList

toIndex:int

Doc from java.util.List.subList.

high endpoint (exclusive) of the subList

Returns:List<Double>

Doc from java.util.List.subList.

a view of the specified range within this list

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.util.AbstractCollection.toString.

Doc from java.util.AbstractCollection.toString.

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 ("[]"). Adjacent elements are separated by the characters ", " (comma and space). Elements are converted to strings as by String#valueOf(Object).

Returns:String

a string representation of this collection

Annotations
@Override
com.google.common.primitives back to summary

public final Class ImmutableDoubleArray.Builder

extends Object
Class Inheritance

A builder for ImmutableDoubleArray instances; obtained using ImmutableDoubleArray#builder.

Field Summary

Modifier and TypeField and Description
private double[]
private int

Constructor Summary

AccessConstructor and Description
pack-priv
Builder(int initialCapacity)

Method Summary

Modifier and TypeMethod and Description
public ImmutableDoubleArray.Builder
add(double value)

Appends value to the end of the values the built ImmutableDoubleArray will contain.

public ImmutableDoubleArray.Builder
addAll(double[] values)

Appends values, in order, to the end of the values the built ImmutableDoubleArray will contain.

public ImmutableDoubleArray.Builder
addAll(Iterable<Double> values)

Appends values, in order, to the end of the values the built ImmutableDoubleArray will contain.

public ImmutableDoubleArray.Builder
addAll(Collection<Double> values)

Appends values, in order, to the end of the values the built ImmutableDoubleArray will contain.

public ImmutableDoubleArray.Builder
addAll(DoubleStream stream)

Appends all values from stream, in order, to the end of the values the built ImmutableDoubleArray will contain.

public ImmutableDoubleArray.Builder
addAll(ImmutableDoubleArray values)

Appends values, in order, to the end of the values the built ImmutableDoubleArray will contain.

public ImmutableDoubleArray
build()

Returns a new immutable array.

private void
ensureRoomFor(int numberToAdd)

private static int
expandedCapacity(int oldCapacity, int minCapacity)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

arrayback to summary
private double[] array
countback to summary
private int count

Constructor Detail

Builderback to summary
pack-priv Builder(int initialCapacity)

Method Detail

addback to summary
public ImmutableDoubleArray.Builder add(double value)

Appends value to the end of the values the built ImmutableDoubleArray will contain.

Annotations
@CanIgnoreReturnValue
addAllback to summary
public ImmutableDoubleArray.Builder addAll(double[] values)

Appends values, in order, to the end of the values the built ImmutableDoubleArray will contain.

Annotations
@CanIgnoreReturnValue
addAllback to summary
public ImmutableDoubleArray.Builder addAll(Iterable<Double> values)

Appends values, in order, to the end of the values the built ImmutableDoubleArray will contain.

Annotations
@CanIgnoreReturnValue
addAllback to summary
public ImmutableDoubleArray.Builder addAll(Collection<Double> values)

Appends values, in order, to the end of the values the built ImmutableDoubleArray will contain.

Annotations
@CanIgnoreReturnValue
addAllback to summary
public ImmutableDoubleArray.Builder addAll(DoubleStream stream)

Appends all values from stream, in order, to the end of the values the built ImmutableDoubleArray will contain.

Annotations
@CanIgnoreReturnValue
addAllback to summary
public ImmutableDoubleArray.Builder addAll(ImmutableDoubleArray values)

Appends values, in order, to the end of the values the built ImmutableDoubleArray will contain.

Annotations
@CanIgnoreReturnValue
buildback 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 .build().trimmed().

ensureRoomForback to summary
private void ensureRoomFor(int numberToAdd)
expandedCapacityback to summary
private static int expandedCapacity(int oldCapacity, int minCapacity)