Class SimpleTestUnitFormat

Object
SimpleTestUnitFormat
All Implemented Interfaces:
UnitFormat

public class SimpleTestUnitFormat extends Object
Provides a simple interface for formatting and parsing units.
Version:
1.0, February 13, 2021
Author:
Werner Keil
  • Method Details

    • geInstance

      public static UnitFormat geInstance()
      Returns the instance for formatting and parsing using case insensitive symbols
      Returns:
      the default instance
    • format

      public Appendable format(Unit<?> unit, Appendable appendable) throws IOException
      Formats the specified unit.
      Specified by:
      format in interface UnitFormat
      Parameters:
      unit - the unit to format.
      appendable - the appendable destination.
      Returns:
      The appendable destination passed in as appendable, with formatted text appended.
      Throws:
      IOException - if an error occurs.
    • label

      public void label(Unit<?> unit, String label)
    • getInstance

      public static UnitFormat getInstance()
      Returns the unit format for the default locale.
      Returns:
      the locale format.
    • parse

      protected Unit<?> parse(CharSequence csq, int index) throws MeasurementParseException
      Throws:
      MeasurementParseException
    • parse

      public final Unit<?> parse(CharSequence csq) throws MeasurementParseException
      Parses the specified character sequence to produce a unit (convenience method). If the specified sequence is empty, the unitary unit (dimensionless) is returned.
      Specified by:
      parse in interface UnitFormat
      Parameters:
      csq - the CharSequence to parse.
      Returns:
      the unit parsed from the specified character sub-sequence.
      Throws:
      MeasurementParseException - if any problem occurs while parsing the specified character sequence (e.g. illegal syntax).
    • parse

      public final Unit<?> parse(CharSequence csq, ParsePosition pos) throws MeasurementParseException
      Parses the specified character sequence to produce a unit (convenience method). If the specified sequence is empty, the unitary unit (dimensionless) is returned.
      Specified by:
      parse in interface UnitFormat
      Parameters:
      csq - the CharSequence to parse.
      pos - a ParsePosition object holding the current parsing index and error parsing index information as described above.
      Returns:
      the unit parsed from the specified character sub-sequence.
      Throws:
      MeasurementParseException - if any problem occurs while parsing the specified character sequence (e.g. illegal syntax).
    • format

      public final String format(Unit<?> unit)
      Formats an object to produce a string. This is equivalent to
      format(unit, new StringBuilder()).toString();
      Specified by:
      format in interface UnitFormat
      Parameters:
      unit - The unit to format
      Returns:
      Formatted string.
      Throws:
      IllegalArgumentException - if the Format cannot format the given object