Class 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. The flatIndex(int[]) can be used to convert from the multi dimensional index to the flat index.
    • Constructor Detail

      • ArrayValue

        public ArrayValue​(int[] dim,
                          org.yamcs.protobuf.Yamcs.Value.Type elementType)
        Create a new value array of size dim[0]*dim[1]*...*dim[n]
        Parameters:
        dim -
        elementType -
    • Method Detail

      • getType

        public org.yamcs.protobuf.Yamcs.Value.Type getType()
        Specified by:
        getType in class Value
      • 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 index
        v - - the value to be set
        Throws:
        ArrayIndexOutOfBoundsException - if the index is outside of the array
        IllegalArgumentException - 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 set
        v - - 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: