Class ValueUtil


  • public class ValueUtil
    extends java.lang.Object
    Utility for handling Values of PVs in scripts.
    • Constructor Summary

      Constructors 
      Constructor Description
      ValueUtil()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static org.epics.vtype.VTable createStringTableFromColumns​(java.util.List<java.lang.String> headers, java.util.List<java.util.List<java.lang.String>> columns)
      Create a VTable for Strings
      static org.epics.vtype.VTable createStringTableFromRows​(java.util.List<java.lang.String> headers, java.util.List<java.util.List<java.lang.String>> rows)
      Create a VTable for Strings
      static double getDouble​(org.epics.vtype.VType value)
      Try to get a 'double' type number from a value.
      static double[] getDoubleArray​(org.epics.vtype.VType value)
      Try to get a 'double' type array from a value.
      static int getInt​(org.epics.vtype.VType value)
      Try to get an integer from a value.
      static java.lang.String[] getLabels​(org.epics.vtype.VType value)
      Get labels for a VEnum value, or headers for a VTable.
      static long getLong​(org.epics.vtype.VType value)
      Try to get a long integer from a value.
      static long[] getLongArray​(org.epics.vtype.VType value)
      Try to get a 'long' type array from a value.
      static java.lang.String getString​(org.epics.vtype.VType value)
      Get value of PV as string.
      static java.lang.String getString​(org.epics.vtype.VType value, boolean byte_array_as_string)
      Get value of PV as string.
      static java.lang.String[] getStringArray​(org.epics.vtype.VType value)
      Get string array from pv.
      static java.util.List<java.util.List<java.lang.Object>> getStructure​(org.epics.vtype.VType value, java.lang.String name)
      Get data from a structured value by name.
      static java.util.List<java.lang.Object> getStructureElement​(org.epics.vtype.VType value, java.lang.String name)
      Get a structure element from a PV by field name.
      static java.lang.Object getStructureElement​(org.epics.vtype.VType value, java.lang.String name, int index)
      Get an element from a PV structure by field name and array index.
      static java.util.List<java.util.List<java.lang.Object>> getTable​(org.epics.vtype.VType value)
      Get a table from PV
      static java.lang.Object getTableCell​(org.epics.vtype.VType value, int row, int column)
      Get a table cell from PV
      static java.time.Instant getTimestamp​(org.epics.vtype.VType value)
      Get time stamp of a value.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ValueUtil

        public ValueUtil()
    • Method Detail

      • getDouble

        public static double getDouble​(org.epics.vtype.VType value)
        Try to get a 'double' type number from a value.
        Parameters:
        value - Value of a PV
        Returns:
        Current value. Double.NaN in case the value type does not decode into a number.
      • getInt

        public static int getInt​(org.epics.vtype.VType value)
        Try to get an integer from a value.
        Parameters:
        value - Value of a PV
        Returns:
        Current value as int
      • getLong

        public static long getLong​(org.epics.vtype.VType value)
        Try to get a long integer from a value.
        Parameters:
        value - Value of a PV
        Returns:
        Current value as long
      • getString

        public static java.lang.String getString​(org.epics.vtype.VType value)
        Get value of PV as string.
        Parameters:
        value - Value of a PV
        Returns:
        Current value as string
      • getString

        public static java.lang.String getString​(org.epics.vtype.VType value,
                                                 boolean byte_array_as_string)
                                          throws java.lang.NullPointerException
        Get value of PV as string.

        Optionally, byte arrays can be requested as a (long) string, instead of "[ 1, 2, 3, .. ]"

        Parameters:
        value - Value of a PV
        byte_array_as_string - Decode byte arrays as string?
        Returns:
        Current value as string
        Throws:
        java.lang.NullPointerException
      • getLabels

        public static java.lang.String[] getLabels​(org.epics.vtype.VType value)
        Get labels for a VEnum value, or headers for a VTable.
        Parameters:
        value - Value of a PV
        Returns:
        Enum labels or empty array if not enum nor table
      • getDoubleArray

        public static double[] getDoubleArray​(org.epics.vtype.VType value)
        Try to get a 'double' type array from a value.
        Parameters:
        value - Value of a PV
        Returns:
        Current value as double[]. Will return single-element array for scalar value, including { Double.NaN } in case the value type does not decode into a number.
      • getLongArray

        public static long[] getLongArray​(org.epics.vtype.VType value)
        Try to get a 'long' type array from a value.
        Parameters:
        value - Value of a PV
        Returns:
        Current value as long[]. Will return single-element array for scalar value.
      • getStringArray

        public static final java.lang.String[] getStringArray​(org.epics.vtype.VType value)
        Get string array from pv.
        Parameters:
        value - Value of a PV
        Returns:
        String array. For string array, it's the actual strings. For numeric arrays, the numbers are formatted as strings. For enum array, the labels are returned. For scalar PVs, an array with a single string is returned.
      • getTimestamp

        public static java.time.Instant getTimestamp​(org.epics.vtype.VType value)
        Get time stamp of a value.
        Parameters:
        value - Value of a PV
        Returns:
        Instant or null
      • getTable

        public static java.util.List<java.util.List<java.lang.Object>> getTable​(org.epics.vtype.VType value)
        Get a table from PV

        Ideally, the PV holds a VTable, and the returned data is then the table's data.

        If the PV is a scalar, a table with a single cell is returned.

        If the PV is an array, a table with one column is returned.

        Parameters:
        value - Value of a PV
        Returns:
        List of rows, where each row contains either String or Number cells
      • getStructure

        public static java.util.List<java.util.List<java.lang.Object>> getStructure​(org.epics.vtype.VType value,
                                                                                    java.lang.String name)
        Get data from a structured value by name.

        As with other structure-related get methods, full and partial names may be used. However, the name must designate a structured field, rather than a scalar data field. For example, the structure

          structure value
                structure Foo
                    scalar_t[] a
                   structure Bar
                       scalar_t[] a
                       scalar_t[] x
          
        can match "Foo" (which returns data for Foo/a, Bar/a, and x) or "Foo/Bar" (which returns data for Bar/a and x), but not "Foo/a" or "Bar/x". For those, use getStructureElement(VType, String, int). Ambiguous names will find the first structure with a matching name.
        Parameters:
        value - Value of a structured PV; should be VTable
        name - Name of the substructure to get; if blank (empty String, ""), the entire structure is returned
        Returns:
        A List of "rows", where rows are lists of scalar data (Strings or Numbers) belonging to scalar fields of the matching sub-structure; if there is no matching sub-structure, the list is empty.
      • getTableCell

        public static java.lang.Object getTableCell​(org.epics.vtype.VType value,
                                                    int row,
                                                    int column)
        Get a table cell from PV

        PV must hold a VTable

        Parameters:
        value - Value of a PV
        row - Row index, 0..
        column - Column index, 0..
        Returns:
        Either String or Number for the cell's value, null if invalid row/column
      • getStructureElement

        public static java.util.List<java.lang.Object> getStructureElement​(org.epics.vtype.VType value,
                                                                           java.lang.String name)
        Get a structure element from a PV by field name.

        Value should hold a VTable which represents the structure.

        For nested structure elements represented with slash-separated names, full and partial field names are accepted. For instance, a structure "value" with the definition

          structure value
              structure Foo
                  scalar_t[] a
                  structure Bar
                      scalar_t[] a
                      scalar_t[] x
          
        has the field "x" with full name "Foo/Bar/x", which can be found with "Foo/Bar/x", "Bar/x", or "x". Ambiguous names (like "a" in the example above) will find the first field with a matching name.
        Parameters:
        value - Value of a PV (should be a VTable)
        name - Structure element name
        Returns:
        If the value has an elements with a matching name, a List<String> or List<Number> is returned, depending on the element's data type. If not, and the value is a VTable, an empty list is returned. Otherwise, a List containing one element, a String representation of the value.
      • getStructureElement

        public static java.lang.Object getStructureElement​(org.epics.vtype.VType value,
                                                           java.lang.String name,
                                                           int index)
        Get an element from a PV structure by field name and array index.

        If index is valid, this method is equivalent to getStructureElement(value, name).get(index).

        Parameters:
        value - Value of a PV (should be a VTable)
        name - Structure element name
        index - Element index in range [0, n-1], where n is the length of the structure element
        Returns:
        Either String or Number for the cell's value, null if invalid name/index
      • createStringTableFromColumns

        public static org.epics.vtype.VTable createStringTableFromColumns​(java.util.List<java.lang.String> headers,
                                                                          java.util.List<java.util.List<java.lang.String>> columns)
        Create a VTable for Strings
        Parameters:
        headers - Table headers
        columns - List of columns, i.e. columns.get(N) is the Nth column
        Returns:
        VTable
      • createStringTableFromRows

        public static org.epics.vtype.VTable createStringTableFromRows​(java.util.List<java.lang.String> headers,
                                                                       java.util.List<java.util.List<java.lang.String>> rows)
        Create a VTable for Strings
        Parameters:
        headers - Table headers
        rows - List of rows, i.e. rows.get(N) is the Nth row
        Returns:
        VTable