Package org.yamcs.parameter
Class ArrayValue
- java.lang.Object
-
- org.yamcs.parameter.Value
-
- org.yamcs.parameter.ArrayValue
-
public class ArrayValue extends Value
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. TheflatIndex(int[])
can be used to convert from the multi dimensional index to the flat index.
-
-
Constructor Summary
Constructors Constructor Description ArrayValue(int[] dim, org.yamcs.protobuf.Yamcs.Value.Type elementType)
Create a new value array of size dim[0]*dim[1]*...
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description int
flatIndex(int[] idx)
static int
flatIndex(int[] dim, int[] idx)
int
flatLength()
Return the length of the flat array This is the product of the size of the individual dimensions.static int
flatSize(int[] dim)
int[]
getDimensions()
returns the dimensions of the arrayorg.yamcs.protobuf.Yamcs.Value.Type
getElementType()
Value
getElementValue(int flatIdx)
Get the element value using the flat index;Value
getElementValue(int[] idx)
Get the value of the element at the given indexorg.yamcs.protobuf.Yamcs.Value.Type
getType()
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)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 indexString
toString()
void
unFlattenIndex(int flatIndex, int[] idx)
unflatten the flatIndex into the idx array-
Methods inherited from class org.yamcs.parameter.Value
getBinaryValue, getBooleanValue, getDoubleValue, getFloatValue, getSint32Value, getSint64Value, getStringValue, getTimestampValue, getUint32Value, getUint64Value
-
-
-
-
Method Detail
-
getElementValue
public Value getElementValue(int[] idx)
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
public void setElementValue(int[] idx, Value v)
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 void unFlattenIndex(int flatIndex, int[] idx)
unflatten the flatIndex into the idx array
-
setElementValue
public void setElementValue(int flatIdx, Value v)
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
public Value getElementValue(int flatIdx)
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
public org.yamcs.protobuf.Yamcs.Value.Type getElementType()
- Returns:
- the type of the array elements
-
getDimensions
public int[] getDimensions()
returns the dimensions of the array- Returns:
-
-