Class ValueUtil

java.lang.Object
org.yamcs.studio.data.vtype.ValueUtil

public class ValueUtil extends Object
Various utility methods for runtime handling of the types defined in this package.
  • Method Details

    • typeOf

      public static Class<?> typeOf(Object obj)
      Returns the type of the object by returning the class object of one of the VXxx interfaces. The getClass() methods returns the concrete implementation type, which is of little use. If no super-interface is found, Object.class is used.
      Parameters:
      obj - an object implementing a standard type
      Returns:
      the type is implementing
    • alarmOf

      public static Alarm alarmOf(Object obj)
      Extracts the alarm information if present.
      Parameters:
      obj - an object implementing a standard type
      Returns:
      the alarm information for the object
    • timeOf

      public static Time timeOf(Object obj)
      Extracts the time information if present.
      Parameters:
      obj - an object implementing a standard type
      Returns:
      the time information for the object
    • displayOf

      public static Display displayOf(Object obj)
      Extracts the display information if present.
      Parameters:
      obj - an object implementing a standard type
      Returns:
      the display information for the object
    • displayHasValidDisplayLimits

      public static boolean displayHasValidDisplayLimits(Display display)
      Checks whether the display limits are non-null and non-NaN.
      Parameters:
      display - a display
      Returns:
      true if the display limits have actual values
    • normalizedNumericValueOf

      public static Double normalizedNumericValueOf(Object obj)
      Extracts the numericValueOf the object and normalizes according to the display range.
      Parameters:
      obj - an object implementing a standard type
      Returns:
      the value normalized in its display range, or null if no value or display information is present
    • normalize

      public static Double normalize(Number value, Display display)
      Normalizes the given value according to the given display information.
      Parameters:
      value - a value
      display - the display information
      Returns:
      the normalized value, or null of either value or display is null
    • normalize

      public static Double normalize(Number value, Number lowValue, Number highValue)
      Normalizes the given value according to the given range;
      Parameters:
      value - a value
      lowValue - the lowest value in the range
      highValue - the highest value in the range
      Returns:
      the normalized value, or null if any value is null
    • numericValueOf

      public static Double numericValueOf(Object obj)
      Extracts a numeric value for the object. If it's a numeric scalar, the value is returned. If it's a numeric array, the first element is returned. If it's a numeric multi array, the value of the first element is returned.
      Parameters:
      obj - an object implementing a standard type
      Returns:
      the numeric value
    • toImage

      public static BufferedImage toImage(VImage vImage)
      Converts a VImage to an AWT BufferedImage, so that it can be displayed. The content of the vImage buffer is copied, so further changes to the VImage will not modify the BufferedImage.
      Parameters:
      vImage - the image to be converted
      Returns:
      a new BufferedImage
    • toVImage

      public static VImage toVImage(BufferedImage image)
      Converts an AWT BufferedImage to a VImage.

      Currently, only TYPE_3BYTE_BGR is supported

      Parameters:
      image - buffered image
      Returns:
      a new image
    • displayEquals

      public static boolean displayEquals(Display d1, Display d2)
      Returns true if the two displays contain the same information.
      Parameters:
      d1 - the first display
      d2 - the second display
      Returns:
      true if they match
    • setAlarmSeverityColorMap

      public static void setAlarmSeverityColorMap(Map<AlarmSeverity,Integer> map)
      Changes the color map for AlarmSeverity. The new color map must be complete and not null;
      Parameters:
      map - the new color map
    • colorFor

      public static int colorFor(AlarmSeverity severity)
      Returns the rgb value for the given severity.
      Parameters:
      severity - an alarm severity
      Returns:
      the rgb color
    • getDefaultTimestampFormat

      public static DateTimeFormatter getDefaultTimestampFormat()
      The default object to format and parse timestamps.
      Returns:
      the default timestamp format
    • setDefaultTimestampFormat

      public static void setDefaultTimestampFormat(DateTimeFormatter defaultTimestampFormat)
      Changes the default timestamp format.
      Parameters:
      defaultTimestampFormat - the new default timestamp format
    • getDefaultNumberFormat

      public static NumberFormat getDefaultNumberFormat()
      The default format for numbers.
      Returns:
      the default number format
    • setDefaultNumberFormat

      public static void setDefaultNumberFormat(NumberFormat defaultNumberFormat)
      Changes the default format for numbers.
      Parameters:
      defaultNumberFormat - the new default number format
    • getDefaultValueFormat

      public static ValueFormat getDefaultValueFormat()
      The default format for VTypes.
      Returns:
      the default format
    • setDefaultValueFormat

      public static void setDefaultValueFormat(ValueFormat defaultValueFormat)
      Changes the default format for VTypes.
      Parameters:
      defaultValueFormat - the new default format
    • numericColumnOf

      public static ListNumber numericColumnOf(VTable table, String columnName)
      Extracts the values of a column, making sure it contains numeric values.
      Parameters:
      table - a table
      columnName - the name of the column to extract
      Returns:
      the values; null if the columnName is null or is not found
      Throws:
      IllegalArgumentException - if the column is found but does not contain numeric values
    • stringColumnOf

      public static List<String> stringColumnOf(VTable table, String columnName)
      Extracts the values of a column, making sure it contains strings.
      Parameters:
      table - a table
      columnName - the name of the column to extract
      Returns:
      the values; null if the columnName is null or is not found
      Throws:
      IllegalArgumentException - if the column is found but does not contain string values
    • defaultArrayDisplay

      public static List<ArrayDimensionDisplay> defaultArrayDisplay(VNumberArray array)
      Returns the default array dimension display by looking at the size of the n dimensional array and creating cell boundaries based on index.
      Parameters:
      array - the array
      Returns:
      the array dimension display
    • defaultArrayDisplay

      public static List<ArrayDimensionDisplay> defaultArrayDisplay(ListInt sizes)
      Returns the default array dimension display given the size of the n dimensional array and creating cell boundaries based on index.
      Parameters:
      sizes - the shape of the array
      Returns:
      the array dimension display
    • subArray

      public static VNumberArray subArray(VNumberArray array, int index)
      Filters an element of a one-dimensional array.
      Parameters:
      array - a 1D array
      index - a valid index
      Returns:
      the trimmed array to that one index