Class AbstractQuantityFormat

java.lang.Object
java.text.Format
tech.units.indriya.format.AbstractQuantityFormat
All Implemented Interfaces:
Serializable, Cloneable, QuantityFormat, tech.uom.lib.common.function.Parser<CharSequence,ComparableQuantity>
Direct Known Subclasses:
NumberSpaceQuantityFormat, SimpleQuantityFormat

public abstract class AbstractQuantityFormat extends Format implements QuantityFormat, tech.uom.lib.common.function.Parser<CharSequence,ComparableQuantity>

This class provides the interface for formatting and parsing quantities.

Since:
1.0
Version:
1.1, $Date: 2018-04-06 $
See Also:
  • Field Details

  • Constructor Details

    • AbstractQuantityFormat

      public AbstractQuantityFormat()
  • Method Details

    • format

      public abstract Appendable format(javax.measure.Quantity<?> quantity, Appendable dest) throws IOException
      Formats the specified quantity into an Appendable.
      Specified by:
      format in interface QuantityFormat
      Parameters:
      quantity - the quantity to format.
      dest - the appendable destination.
      Returns:
      the specified Appendable.
      Throws:
      IOException - if an I/O exception occurs.
    • parse

      public abstract ComparableQuantity<?> parse(CharSequence csq, ParsePosition cursor) throws IllegalArgumentException, javax.measure.format.ParserException
      Parses a portion of the specified CharSequence from the specified position to produce an object. If parsing succeeds, then the index of the cursor argument is updated to the index after the last character used.
      Specified by:
      parse in interface QuantityFormat
      Parameters:
      csq - the CharSequence to parse.
      cursor - the cursor holding the current parsing index.
      Returns:
      the object parsed from the specified character sub-sequence.
      Throws:
      IllegalArgumentException - if any problem occurs while parsing the specified character sequence (e.g. illegal syntax).
      javax.measure.format.ParserException
    • parse

      public abstract ComparableQuantity<?> parse(CharSequence csq) throws javax.measure.format.ParserException
      Parses a portion of the specified CharSequence from the specified position to produce an object. If parsing succeeds, then the index of the cursor argument is updated to the index after the last character used.
      Specified by:
      parse in interface tech.uom.lib.common.function.Parser<CharSequence,ComparableQuantity>
      Specified by:
      parse in interface QuantityFormat
      Parameters:
      csq - the CharSequence to parse.
      cursor - the cursor holding the current parsing index.
      Returns:
      the object parsed from the specified character sub-sequence.
      Throws:
      IllegalArgumentException - if any problem occurs while parsing the specified character sequence (e.g. illegal syntax).
      javax.measure.format.ParserException
    • parse

      abstract ComparableQuantity<?> parse(CharSequence csq, int index) throws IllegalArgumentException, javax.measure.format.ParserException
      Parses a portion of the specified CharSequence from the specified position to produce an object. If parsing succeeds, then the index of the cursor argument is updated to the index after the last character used.
      Parameters:
      csq - the CharSequence to parse.
      index - the current parsing index.
      Returns:
      the object parsed from the specified character sub-sequence.
      Throws:
      IllegalArgumentException - if any problem occurs while parsing the specified character sequence (e.g. illegal syntax).
      javax.measure.format.ParserException
    • format

      public final StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos)
      Specified by:
      format in class Format
    • parseObject

      public final javax.measure.Quantity<?> parseObject(String source, ParsePosition pos)
      Specified by:
      parseObject in class Format
    • format

      public final StringBuilder format(AbstractQuantity<?> quantity, StringBuilder dest)
      Convenience method equivalent to #format(AbstractQuantity, Appendable) except it does not raise an IOException.
      Parameters:
      quantity - the quantity to format.
      dest - the appendable destination.
      Returns:
      the specified StringBuilder.