public final class LongArray extends Object implements Matrix, org.joda.beans.ImmutableBean, Serializable
long values.
This provides functionality similar to List but for long[].
In mathematical terms, this is a vector, or one-dimensional matrix.
| Modifier and Type | Method and Description |
|---|---|
LongArray |
combine(LongArray other,
LongBinaryOperator operator)
Returns an instance where each element is formed by some combination of the matching
values in this array and the other array.
|
long |
combineReduce(LongArray other,
LongTernaryOperator operator)
Combines this array and the other array returning a reduced value.
|
LongArray |
concat(long... arrayToConcat)
Returns an array that combines this array and the specified array.
|
LongArray |
concat(LongArray arrayToConcat)
Returns an array that combines this array and the specified array.
|
boolean |
contains(long value)
Checks if this array contains the specified value.
|
void |
copyInto(long[] destination,
int offset)
Copies this array into the specified array.
|
static LongArray |
copyOf(Collection<Long> collection)
Obtains an instance from a collection of
Long. |
static LongArray |
copyOf(long[] array)
Obtains an instance from an array of
long. |
static LongArray |
copyOf(long[] array,
int fromIndex)
Obtains an instance by copying part of an array.
|
static LongArray |
copyOf(long[] array,
int fromIndexInclusive,
int toIndexExclusive)
Obtains an instance by copying part of an array.
|
int |
dimensions()
Gets the number of dimensions of this array.
|
LongArray |
dividedBy(long divisor)
Returns an instance with each value divided by the specified divisor.
|
LongArray |
dividedBy(LongArray other)
Returns an instance where each element is calculated by dividing values in this array by values in the other array.
|
boolean |
equals(Object obj) |
static LongArray |
filled(int size)
Obtains an instance with all entries equal to the zero.
|
static LongArray |
filled(int size,
long value)
Obtains an instance with all entries equal to the same value.
|
void |
forEach(IntLongConsumer action)
Applies an action to each value in the array.
|
long |
get(int index)
Gets the value at the specified index in this array.
|
int |
hashCode() |
int |
indexOf(long value)
Find the index of the first occurrence of the specified value.
|
boolean |
isEmpty()
Checks if this array is empty.
|
int |
lastIndexOf(long value)
Find the index of the first occurrence of the specified value.
|
LongArray |
map(LongUnaryOperator operator)
Returns an instance with an operation applied to each value in the array.
|
LongArray |
mapWithIndex(IntLongToLongFunction function)
Returns an instance with an operation applied to each indexed value in the array.
|
long |
max()
Returns the minimum value held in the array.
|
org.joda.beans.MetaBean |
metaBean() |
long |
min()
Returns the minimum value held in the array.
|
LongArray |
minus(long amount)
Returns an instance with the specified amount subtracted from each value.
|
LongArray |
minus(LongArray other)
Returns an instance where each element is equal to the difference between the
matching values in this array and the other array.
|
LongArray |
multipliedBy(long factor)
Returns an instance with each value multiplied by the specified factor.
|
LongArray |
multipliedBy(LongArray other)
Returns an instance where each element is equal to the product of the
matching values in this array and the other array.
|
static LongArray |
of()
Obtains an empty immutable array.
|
static LongArray |
of(int size,
IntToLongFunction valueFunction)
Obtains an instance with entries filled using a function.
|
static LongArray |
of(long value)
Obtains an immutable array with a single value.
|
static LongArray |
of(long value1,
long value2)
Obtains an immutable array with two values.
|
static LongArray |
of(long value1,
long value2,
long value3)
Obtains an immutable array with three values.
|
static LongArray |
of(long value1,
long value2,
long value3,
long value4)
Obtains an immutable array with four values.
|
static LongArray |
of(long value1,
long value2,
long value3,
long value4,
long value5)
Obtains an immutable array with five values.
|
static LongArray |
of(long value1,
long value2,
long value3,
long value4,
long value5,
long value6)
Obtains an immutable array with six values.
|
static LongArray |
of(long value1,
long value2,
long value3,
long value4,
long value5,
long value6,
long value7)
Obtains an immutable array with seven values.
|
static LongArray |
of(long value1,
long value2,
long value3,
long value4,
long value5,
long value6,
long value7,
long value8)
Obtains an immutable array with eight values.
|
static LongArray |
of(long value1,
long value2,
long value3,
long value4,
long value5,
long value6,
long value7,
long value8,
long... otherValues)
Obtains an immutable array with more than eight values.
|
static LongArray |
of(LongStream stream)
Obtains an instance with entries filled from a stream.
|
static LongArray |
ofUnsafe(long[] array)
Obtains an instance by wrapping an array.
|
LongArray |
plus(long amount)
Returns an instance with the specified amount added to each value.
|
LongArray |
plus(LongArray other)
Returns an instance where each element is the sum of the matching values
in this array and the other array.
|
long |
reduce(long identity,
LongBinaryOperator operator)
Reduces this array returning a single value.
|
int |
size()
Gets the size of this array.
|
LongArray |
sorted()
Returns a sorted copy of this array.
|
LongStream |
stream()
Returns a stream over the array values.
|
LongArray |
subArray(int fromIndexInclusive)
Returns an array holding the values from the specified index onwards.
|
LongArray |
subArray(int fromIndexInclusive,
int toIndexExclusive)
Returns an array holding the values between the specified from and to indices.
|
long |
sum()
Returns the sum of all the values in the array.
|
long[] |
toArray()
Converts this instance to an independent
long[]. |
long[] |
toArrayUnsafe()
Returns the underlying array.
|
List<Long> |
toList()
Returns a list equivalent to this array.
|
String |
toString() |
LongArray |
with(int index,
long newValue)
Returns an instance with the value at the specified index changed.
|
public static final LongArray EMPTY
public static LongArray of()
public static LongArray of(long value)
value - the single valuepublic static LongArray of(long value1, long value2)
value1 - the first valuevalue2 - the second valuepublic static LongArray of(long value1, long value2, long value3)
value1 - the first valuevalue2 - the second valuevalue3 - the third valuepublic static LongArray of(long value1, long value2, long value3, long value4)
value1 - the first valuevalue2 - the second valuevalue3 - the third valuevalue4 - the fourth valuepublic static LongArray of(long value1, long value2, long value3, long value4, long value5)
value1 - the first valuevalue2 - the second valuevalue3 - the third valuevalue4 - the fourth valuevalue5 - the fifth valuepublic static LongArray of(long value1, long value2, long value3, long value4, long value5, long value6)
value1 - the first valuevalue2 - the second valuevalue3 - the third valuevalue4 - the fourth valuevalue5 - the fifth valuevalue6 - the sixth valuepublic static LongArray of(long value1, long value2, long value3, long value4, long value5, long value6, long value7)
value1 - the first valuevalue2 - the second valuevalue3 - the third valuevalue4 - the fourth valuevalue5 - the fifth valuevalue6 - the sixth valuevalue7 - the seventh valuepublic static LongArray of(long value1, long value2, long value3, long value4, long value5, long value6, long value7, long value8)
value1 - the first valuevalue2 - the second valuevalue3 - the third valuevalue4 - the fourth valuevalue5 - the fifth valuevalue6 - the sixth valuevalue7 - the seventh valuevalue8 - the eighth valuepublic static LongArray of(long value1, long value2, long value3, long value4, long value5, long value6, long value7, long value8, long... otherValues)
value1 - the first valuevalue2 - the second valuevalue3 - the third valuevalue4 - the fourth valuevalue5 - the fifth valuevalue6 - the sixth valuevalue7 - the seventh valuevalue8 - the eighth valueotherValues - the other valuespublic static LongArray of(int size, IntToLongFunction valueFunction)
The function is passed the array index and returns the value for that index.
size - the number of elementsvalueFunction - the function used to populate the valuepublic static LongArray of(LongStream stream)
The stream is converted to an array using LongStream.toArray().
stream - the stream of elementspublic static LongArray ofUnsafe(long[] array)
This method is inherently unsafe as it relies on good behavior by callers. Callers must never make any changes to the passed in array after calling this method. Doing so would violate the immutability of this class.
array - the array to assignpublic static LongArray copyOf(Collection<Long> collection)
Long.
The order of the values in the returned array is the order in which elements are returned from the iterator of the collection.
collection - the collection to initialize frompublic static LongArray copyOf(long[] array)
long.
The input array is copied and not mutated.
array - the array to copy, clonedpublic static LongArray copyOf(long[] array, int fromIndex)
The input array is copied and not mutated.
array - the array to copyfromIndex - the offset from the start of the arrayIndexOutOfBoundsException - if the index is invalidpublic static LongArray copyOf(long[] array, int fromIndexInclusive, int toIndexExclusive)
The input array is copied and not mutated.
array - the array to copyfromIndexInclusive - the start index of the input array to copy fromtoIndexExclusive - the end index of the input array to copy toIndexOutOfBoundsException - if the index is invalidpublic static LongArray filled(int size)
size - the number of elementspublic static LongArray filled(int size, long value)
size - the number of elementsvalue - the value of all the elementspublic int dimensions()
dimensions in interface Matrixpublic int size()
public boolean isEmpty()
public long get(int index)
index - the zero-based index to retrieveIndexOutOfBoundsException - if the index is invalidpublic boolean contains(long value)
value - the value to findpublic int indexOf(long value)
value - the value to findpublic int lastIndexOf(long value)
value - the value to findpublic void copyInto(long[] destination,
int offset)
The specified array must be at least as large as this array. If it is larger, then the remainder of the array will be untouched.
destination - the array to copy intooffset - the offset in the destination array to start fromIndexOutOfBoundsException - if the destination array is not large enough
or the offset is negativepublic LongArray subArray(int fromIndexInclusive)
fromIndexInclusive - the start index of the array to copy fromIndexOutOfBoundsException - if the index is invalidpublic LongArray subArray(int fromIndexInclusive, int toIndexExclusive)
fromIndexInclusive - the start index of the array to copy fromtoIndexExclusive - the end index of the array to copy toIndexOutOfBoundsException - if the index is invalidpublic long[] toArray()
long[].public long[] toArrayUnsafe()
This method is inherently unsafe as it relies on good behavior by callers. Callers must never make any changes to the array returned by this method. Doing so would violate the immutability of this class.
public List<Long> toList()
public LongStream stream()
public void forEach(IntLongConsumer action)
This is used to perform an action on the contents of this array. The action receives both the index and the value. For example, the action could print out the array.
base.forEach((index, value) -> System.out.println(index + ": " + value));
This instance is immutable and unaffected by this method.
action - the action to be appliedpublic LongArray with(int index, long newValue)
This instance is immutable and unaffected by this method.
index - the zero-based index to setnewValue - the new value to storeIndexOutOfBoundsException - if the index is invalidpublic LongArray plus(long amount)
This is used to add to the contents of this array, returning a new array.
This is a special case of map(LongUnaryOperator).
This instance is immutable and unaffected by this method.
amount - the amount to add, may be negativepublic LongArray minus(long amount)
This is used to subtract from the contents of this array, returning a new array.
This is a special case of map(LongUnaryOperator).
This instance is immutable and unaffected by this method.
amount - the amount to subtract, may be negativepublic LongArray multipliedBy(long factor)
This is used to multiply the contents of this array, returning a new array.
This is a special case of map(LongUnaryOperator).
This instance is immutable and unaffected by this method.
factor - the multiplicative factorpublic LongArray dividedBy(long divisor)
This is used to divide the contents of this array, returning a new array.
This is a special case of map(LongUnaryOperator).
This instance is immutable and unaffected by this method.
divisor - the value by which the array values are dividedpublic LongArray map(LongUnaryOperator operator)
This is used to perform an operation on the contents of this array, returning a new array. The operator only receives the value. For example, the operator could multiply and add each element.
result = base.map(value -> value * 3 + 4);
This instance is immutable and unaffected by this method.
operator - the operator to be appliedpublic LongArray mapWithIndex(IntLongToLongFunction function)
This is used to perform an operation on the contents of this array, returning a new array. The function receives both the index and the value. For example, the operator could multiply the value by the index.
result = base.mapWithIndex((index, value) -> index * value);
This instance is immutable and unaffected by this method.
function - the function to be appliedpublic LongArray plus(LongArray other)
This is used to add two arrays, returning a new array.
Element n in the resulting array is equal to element n in this array
plus element n in the other array.
The arrays must be of the same size.
This is a special case of combine(LongArray, LongBinaryOperator).
This instance is immutable and unaffected by this method.
other - the other arrayIllegalArgumentException - if the arrays have different sizespublic LongArray minus(LongArray other)
This is used to subtract the second array from the first, returning a new array.
Element n in the resulting array is equal to element n in this array
minus element n in the other array.
The arrays must be of the same size.
This is a special case of combine(LongArray, LongBinaryOperator).
This instance is immutable and unaffected by this method.
other - the other arrayIllegalArgumentException - if the arrays have different sizespublic LongArray multipliedBy(LongArray other)
This is used to multiply each value in this array by the corresponding value in the other array, returning a new array.
Element n in the resulting array is equal to element n in this array
multiplied by element n in the other array.
The arrays must be of the same size.
This is a special case of combine(LongArray, LongBinaryOperator).
This instance is immutable and unaffected by this method.
other - the other arrayIllegalArgumentException - if the arrays have different sizespublic LongArray dividedBy(LongArray other)
This is used to divide each value in this array by the corresponding value in the other array, returning a new array.
Element n in the resulting array is equal to element n in this array
divided by element n in the other array.
The arrays must be of the same size.
This is a special case of combine(LongArray, LongBinaryOperator).
This instance is immutable and unaffected by this method.
other - the other arrayIllegalArgumentException - if the arrays have different sizespublic LongArray combine(LongArray other, LongBinaryOperator operator)
This is used to combine two arrays, returning a new array.
Element n in the resulting array is equal to the result of the operator
when applied to element n in this array and element n in the other array.
The arrays must be of the same size.
This instance is immutable and unaffected by this method.
other - the other arrayoperator - the operator used to combine each pair of valuesIllegalArgumentException - if the arrays have different sizespublic long combineReduce(LongArray other, LongTernaryOperator operator)
This is used to combine two arrays, returning a single reduced value. The operator is called once for each element in the arrays. The arrays must be of the same size.
The first argument to the operator is the running total of the reduction, starting from zero. The second argument to the operator is the element from this array. The third argument to the operator is the element from the other array.
This instance is immutable and unaffected by this method.
other - the other arrayoperator - the operator used to combine each pair of values with the current totalIllegalArgumentException - if the arrays have different sizespublic LongArray concat(long... arrayToConcat)
The result will have a length equal to this.size() + arrayToConcat.length.
This instance is immutable and unaffected by this method.
arrayToConcat - the array to add to the end of this arrayIndexOutOfBoundsException - if the index is invalidpublic LongArray concat(LongArray arrayToConcat)
The result will have a length equal to this.size() + newArray.length.
This instance is immutable and unaffected by this method.
arrayToConcat - the new array to add to the end of this arrayIndexOutOfBoundsException - if the index is invalidpublic LongArray sorted()
This uses Arrays.sort(long[]).
This instance is immutable and unaffected by this method.
public long min()
If the array is empty, then an exception is thrown. If the array contains NaN, then the result is NaN.
IllegalStateException - if the array is emptypublic long max()
If the array is empty, then an exception is thrown. If the array contains NaN, then the result is NaN.
IllegalStateException - if the array is emptypublic long sum()
This is a special case of reduce(long, LongBinaryOperator).
public long reduce(long identity,
LongBinaryOperator operator)
This is used to reduce the values in this array to a single value. The operator is called once for each element in the arrays. The first argument to the operator is the running total of the reduction, starting from zero. The second argument to the operator is the element.
This instance is immutable and unaffected by this method.
identity - the identity value to start fromoperator - the operator used to combine the value with the current totalpublic org.joda.beans.MetaBean metaBean()
metaBean in interface org.joda.beans.BeanCopyright 2009-Present by OpenGamma Inc. and individual contributors
Apache v2 licensed
Additional documentation can be found at strata.opengamma.io.