Class ValueFormat

java.lang.Object
java.text.Format
org.yamcs.studio.data.vtype.ValueFormat
All Implemented Interfaces:
Serializable, Cloneable
Direct Known Subclasses:
SimpleValueFormat

public abstract class ValueFormat extends Format
Formats a data type to a String representation. This class provide default implementations that can format scalars and arrays to an arbitrary precision and a maximum number of array elements.
See Also:
  • Constructor Details

    • ValueFormat

      public ValueFormat()
  • Method Details

    • format

      public StringBuffer format(Object data, StringBuffer toAppendTo, FieldPosition pos)
      Formats the given data object. For scalars and arrays redirects to the appropriate methods. For anything else uses Object.toString().
      Specified by:
      format in class Format
      Parameters:
      data - data object to format
      Returns:
      a String representation
    • format

      public String format(Scalar scalar)
      Formats an scalar.
      Parameters:
      scalar - data object to format
      Returns:
      a String representation
    • format

      public String format(Array array)
      Formats an array.
      Parameters:
      array - data object to format
      Returns:
      a String representation
    • format

      protected abstract StringBuffer format(Scalar scalar, StringBuffer toAppendTo, FieldPosition pos)
      Formats a scalar.
      Parameters:
      scalar - data object to format
      toAppendTo - output buffer
      pos - the field position
      Returns:
      the output buffer
    • format

      protected abstract StringBuffer format(Array array, StringBuffer toAppendTo, FieldPosition pos)
      Formats an array.
      Parameters:
      array - data object to format
      toAppendTo - output buffer
      pos - the field position
      Returns:
      the output buffer
    • getNumberFormat

      public NumberFormat getNumberFormat()
      Returns the NumberFormat used to format the numeric values. If null, it will use the NumberFormat from the value Display.
      Returns:
      a NumberFormat
    • setNumberFormat

      public void setNumberFormat(NumberFormat numberFormat)
      Changes the NumberFormat used to format the numeric values. If null, it will use the NumberFormat from the value Display.
      Parameters:
      numberFormat - a NumberFormat
    • parseObject

      public Object parseObject(String source, ParsePosition pos)
      Specified by:
      parseObject in class Format
    • parseObject

      public Object parseObject(String source, VType reference)
      Parses the string given the object as a reference.

      This function will parse the string based on the object provided as a reference (e.g. if reference is a VDouble, it will parse the string as a double). The data in the reference will also be used for the actual parsing (e.g. if reference is Enum, the labels will be used to match the string).

      Parameters:
      source - the text to parse
      reference - the vtype object to reference
      Returns:
      the parsed representation
    • parseDouble

      public double parseDouble(String source)
      Parses the string and returns a double representation.

      Default implementation uses Double.parseDouble(java.lang.String)

      Parameters:
      source - the text to parse
      Returns:
      the parsed representation
    • parseFloat

      public float parseFloat(String source)
      Parses the string and returns a float representation.

      Default implementation uses Float.parseFloat(java.lang.String)

      Parameters:
      source - the text to parse
      Returns:
      the parsed representation
    • parseInt

      public int parseInt(String source)
      Parses the string and returns an integer representation.

      Default implementation uses Integer.parseInt(java.lang.String)

      Parameters:
      source - the text to parse
      Returns:
      the parsed representation
    • parseShort

      public short parseShort(String source)
      Parses the string and returns a short representation.

      Default implementation uses Short.parseShort(java.lang.String)

      Parameters:
      source - the text to parse
      Returns:
      the parsed representation
    • parseByte

      public byte parseByte(String source)
      Parses the string and returns a byte representation.

      Default implementation uses Byte.parseByte(java.lang.String)

      Parameters:
      source - the text to parse
      Returns:
      the parsed representation
    • parseString

      public String parseString(String source)
      Parses the string and returns a string representation.

      Default implementation returns the string.

      Parameters:
      source - the text to parse
      Returns:
      the parsed representation
    • parseEnum

      public int parseEnum(String source, List<String> labels)
      Parses the string and returns the index in the enum.

      Default implementation matches the label and returns the index.

      Parameters:
      source - the text to parse
      labels - the labels for the enum
      Returns:
      the parsed representation
    • parseDoubleArray

      public ListDouble parseDoubleArray(String source)
      Parses the string and returns a double array representation.

      Default implementation expects a comma separated list, and parses each element with parseDouble(java.lang.String).

      Parameters:
      source - the text to parse
      Returns:
      the parsed representation
    • parseFloatArray

      public ListFloat parseFloatArray(String source)
      Parses the string and returns a float array representation.

      Default implementation expects a comma separated list, and parses each element with parseFloat(java.lang.String).

      Parameters:
      source - the text to parse
      Returns:
      the parsed representation
    • parseIntArray

      public ListInt parseIntArray(String source)
      Parses the string and returns an int array representation.

      Default implementation expects a comma separated list, and parses each element with parseInt(java.lang.String).

      Parameters:
      source - the text to parse
      Returns:
      the parsed representation
    • parseShortArray

      public ListShort parseShortArray(String source)
      Parses the string and returns a short array representation.

      Default implementation expects a comma separated list, and parses each element with parseShort(java.lang.String).

      Parameters:
      source - the text to parse
      Returns:
      the parsed representation
    • parseByteArray

      public ListByte parseByteArray(String source)
      Parses the string and returns a byte array representation.

      Default implementation expects a comma separated list, and parses each element with parseByte(java.lang.String).

      Parameters:
      source - the text to parse
      Returns:
      the parsed representation
    • parseStringArray

      public List<String> parseStringArray(String source)
      Parses the string and returns a string array representation.

      Default implementation expects a comma separated list, and parses each element with parseString(java.lang.String).

      Parameters:
      source - the text to parse
      Returns:
      the parsed representation
    • parseEnumArray

      public ListInt parseEnumArray(String source, List<String> labels)
      Parses the string and returns an array of indexes in the enum.

      Default implementation expects a comma separated list, and parses each element with parseEnum(java.lang.String, java.util.List).

      Parameters:
      source - the text to parse
      labels - the labels for the enum
      Returns:
      the parsed representation