Class QuantityFormat

java.lang.Object
java.text.Format
org.apache.sis.measure.QuantityFormat
All Implemented Interfaces:
Serializable, Cloneable

public class QuantityFormat extends Format
Parses and formats numbers with units of measurement.
Since:
1.1
Version:
1.1
See Also:
  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      For cross-version compatibility.
      See Also:
    • SEPARATOR

      public static final char SEPARATOR
      The default separator used between numerical value and its unit of measurement. Current value is narrow no-break space (U+202F).
      See Also:
    • numberFormat

      protected final NumberFormat numberFormat
      The format for parsing and formatting the number part.
    • unitFormat

      protected final UnitFormat unitFormat
      The format for parsing and formatting the unit of measurement part.
  • Constructor Details

    • QuantityFormat

      public QuantityFormat(Locale locale)
      Creates a new instance for the given locale.
      Parameters:
      locale - the locale for the quantity format.
    • QuantityFormat

      public QuantityFormat(NumberFormat numberFormat, UnitFormat unitFormat)
      Creates a new instance using the given number and unit formats.
      Parameters:
      numberFormat - the format for parsing and formatting the number part.
      unitFormat - the format for parsing and formatting the unit of measurement part.
  • Method Details

    • format

      public StringBuffer format(Object quantity, StringBuffer toAppendTo, FieldPosition pos)
      Formats the specified quantity in the given buffer. The given object shall be a Quantity instance.
      Specified by:
      format in class Format
      Parameters:
      quantity - the quantity to format.
      toAppendTo - where to format the quantity.
      pos - where to store the position of a formatted field, or null if none.
      Returns:
      the given toAppendTo argument, for method calls chaining.
    • parseObject

      public Object parseObject(String source, ParsePosition pos)
      Parses text from a string to produce a quantity, or returns null if the parsing failed.
      Specified by:
      parseObject in class Format
      Parameters:
      source - the text, part of which should be parsed.
      pos - index and error index information.
      Returns:
      a quantity parsed from the string, or null in case of error.
    • clone

      public QuantityFormat clone()
      Returns a clone of this format.
      Overrides:
      clone in class Format
      Returns:
      a clone of this format.