public class LSArray
extends java.lang.Object
LSExpression.getArrayValue() or LSSolution.getArrayValue(localsolver.LSExpression).
An array contains values of type lsint, lsdouble, LSArray
(for multi-dimensional arrays) or LSCollection (list or set).
Note that it's possible to mix integers
or doubles in the same array.
Arrays are not decisions and cannot be modified.LSSolution,
LSExpression| Modifier and Type | Method and Description |
|---|---|
void |
copyTo(double[] values)
Copy all the double values of this array to the given array.
|
void |
copyTo(long[] values)
Copy all the integer values of this array to the given array.
|
int |
count()
Returns the number of elements in the array.
|
boolean |
equals(java.lang.Object obj) |
LSArray |
getArrayValue(int pos)
Returns the array value at the given position.
|
double |
getDoubleValue(int pos)
Returns the double value at the given position.
|
long |
getIntValue(int pos)
Returns the integer value at the given position.
|
int |
hashCode() |
boolean |
isArray(int pos)
Returns true if the value at the given position is an array.
|
boolean |
isBool(int pos)
Returns true if the value at the given position is a boolean.
|
boolean |
isDouble(int pos)
Returns true if the value at the given position is a double.
|
boolean |
isInt(int pos)
Returns true if the value at the given position is an integer.
|
java.lang.String |
toString()
Returns a string representation of the values in the array in the format
"{ val0, val1, ..., valN }"
|
public int count()
public boolean isBool(int pos)
getIntValue(int).pos - Position of the value to query.public boolean isInt(int pos)
getIntValue(int).pos - Position of the value to query.public boolean isDouble(int pos)
getDoubleValue(int).pos - Position of the value to query.public boolean isArray(int pos)
getArrayValue(int).pos - Position of the value to query.public long getIntValue(int pos)
pos - Position of the value to query.public double getDoubleValue(int pos)
pos - Position of the value to query.public LSArray getArrayValue(int pos)
pos - Position of the value to query.public void copyTo(long[] values)
Copy all the integer values of this array to the given array. Only the integer values are copied to their corresponding position in the array. Cells of the array given in parameters that correspond to positions of non-integer values in this array remain unchanged.
The length of the array given in parameters can be different from the number of elements in this array. In that case, only the elements that fit in the array are copied.
This method is recommended if you need to access all the values of this array, instead of the roughly equivalent, but less performant, following code:
for(int i = 0; i < Math.min(values.length, array.count()); ++i) {
if(!array.isInt(i)) continue;
values[i] = array.getIntValue(i);
}
values - array that will receive the integer values of this array.public void copyTo(double[] values)
Copy all the double values of this array to the given array. Only the double values are copied to their corresponding position in the array. Cells of the array given in parameters that correspond to positions of non-double values in this array remain unchanged.
The length of the array given in parameters can be different from the number of elements in this array. In that case, only the elements that fit in the array are copied.
This method is recommended if you need to access all the values of this array, instead of the roughly equivalent, but less performant, following code:
for(int i = 0; i < Math.min(values.length, array.count()); ++i) {
if(!array.isDouble(i)) continue;
values[i] = array.getDouble(i);
}
values - array that will receive the double values of this array.public java.lang.String toString()
toString in class java.lang.Objectpublic int hashCode()
hashCode in class java.lang.Objectpublic boolean equals(java.lang.Object obj)
equals in class java.lang.Object