Package org.yamcs.parameter
Class ArrayValue
java.lang.Object
org.yamcs.parameter.Value
org.yamcs.parameter.ArrayValue
Multidimensional value array. All the elements of the array have to have the same type.
The number of dimensions and the size of each dimension are fixed in the constructor.
The array is internally stored into a flat java array. The flatIndex(int[])
can be used to convert from the
multi dimensional index to the flat index.
-
Constructor Summary
ConstructorDescriptionArrayValue
(int[] dim, Yamcs.Value.Type elementType) Create a new value array of size dim[0]*dim[1]*... -
Method Summary
Modifier and TypeMethodDescriptionboolean
int
flatIndex
(int[] idx) static int
flatIndex
(int[] dim, int[] idx) flatIndexToString
(int flatIndex) int
Return the length of the flat array This is the product of the size of the individual dimensions.static int
flatSize
(int[] dim) int[]
returns the dimensions of the arraygetElementValue
(int flatIdx) Get the element value using the flat index;getElementValue
(int[] idx) Get the value of the element at the given indexgetType()
boolean
hasElement
(int[] idx) Return true of the idx is the same dimensions with this array and if the element exists (i.e. idx is not out of bounds)int
hashCode()
void
setElementValue
(int[] idx, Value v) Sets the element at the given index.void
setElementValue
(int flatIdx, Value v) Set the value of an element using the flat indextoString()
int[]
unFlattenIndex
(int flatIndex) static void
unFlattenIndex
(int flatIndex, int[] dim, int[] idx) unflatten the flatIndex into the idx arrayMethods inherited from class org.yamcs.parameter.Value
getBinaryValue, getBooleanValue, getDoubleValue, getFloatValue, getSint32Value, getSint64Value, getStringValue, getTimestampValue, getUint32Value, getUint64Value, toDouble, toLong
-
Constructor Details
-
ArrayValue
Create a new value array of size dim[0]*dim[1]*...*dim[n]- Parameters:
dim
-elementType
-
-
-
Method Details
-
getType
-
getElementValue
Get the value of the element at the given index- Parameters:
idx
- - multidimensional index- Returns:
- - the value
- Throws:
ArrayIndexOutOfBoundsException
- if the index is outside of the array
-
hasElement
public boolean hasElement(int[] idx) Return true of the idx is the same dimensions with this array and if the element exists (i.e. idx is not out of bounds)- Parameters:
idx
-- Returns:
-
setElementValue
Sets the element at the given index.- Parameters:
idx
- - multidimensional indexv
- - the value to be set- Throws:
ArrayIndexOutOfBoundsException
- if the index is outside of the arrayIllegalArgumentException
- if the number of dimensions (idx.lenght) does not match with the array number of dimensions or if the element type does not match with the array element type
-
flatIndex
public static int flatIndex(int[] dim, int[] idx) -
flatIndex
public int flatIndex(int[] idx) -
flatSize
public static int flatSize(int[] dim) -
unFlattenIndex
public static void unFlattenIndex(int flatIndex, int[] dim, int[] idx) unflatten the flatIndex into the idx array -
unFlattenIndex
public int[] unFlattenIndex(int flatIndex) -
setElementValue
Set the value of an element using the flat index- Parameters:
flatIdx
- - flat index of the element to be setv
- - the value to be set- Throws:
ArrayIndexOutOfBoundsException
- if the index is outside of the array
-
getElementValue
Get the element value using the flat index;- Parameters:
flatIdx
- - flat index of the element to be set- Returns:
- the value
-
flatLength
public int flatLength()Return the length of the flat array This is the product of the size of the individual dimensions.- Returns:
-
getElementType
- Returns:
- the type of the array elements
-
getDimensions
public int[] getDimensions()returns the dimensions of the array- Returns:
-
flatIndexToString
-
hashCode
public int hashCode() -
equals
-
toString
-