Class NumberSpaceQuantityFormat

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

public class NumberSpaceQuantityFormat extends AbstractQuantityFormat
See Also:
  • Field Details

    • DEFAULT

      private static final NumberSpaceQuantityFormat DEFAULT
      Holds the default format instance.
    • LOCAL

      private static final NumberSpaceQuantityFormat LOCAL
      Holds the localized format instance.
    • serialVersionUID

      private static final long serialVersionUID
      See Also:
    • numberFormat

      private final NumberFormat numberFormat
    • unitFormat

      private final javax.measure.format.UnitFormat unitFormat
  • Constructor Details

    • NumberSpaceQuantityFormat

      NumberSpaceQuantityFormat(NumberFormat numberFormat, javax.measure.format.UnitFormat unitFormat)
  • Method Details

    • getFractionDigitsCount

      static int getFractionDigitsCount(double d)
    • format

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

      public ComparableQuantity<?> parse(CharSequence csq, ParsePosition cursor) throws IllegalArgumentException, javax.measure.format.ParserException
      Description copied from class: AbstractQuantityFormat
      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
      Specified by:
      parse in class AbstractQuantityFormat
      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

      ComparableQuantity<?> parse(CharSequence csq, int index) throws IllegalArgumentException, javax.measure.format.ParserException
      Description copied from class: AbstractQuantityFormat
      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 class AbstractQuantityFormat
      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
    • parse

      public ComparableQuantity<?> parse(CharSequence csq) throws IllegalArgumentException, javax.measure.format.ParserException
      Description copied from class: AbstractQuantityFormat
      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
      Specified by:
      parse in class AbstractQuantityFormat
      Parameters:
      csq - the CharSequence to parse.
      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
    • getInstance

      public static NumberSpaceQuantityFormat getInstance(FormatBehavior style)
      Returns the culture invariant format based upon BigDecimal canonical format and the standard unit format. This format is not locale-sensitive and can be used for unambiguous electronic communication of quantities together with their units without loss of information. For example: "1.23456789 kg.m/s2" returns Quantities.getQuantity(new BigDecimal("1.23456789"), AbstractUnit.parse("kg.m/s2")));
      Parameters:
      style - the format style to apply.
      Returns:
      the desired format.
    • getInstance

      public static NumberSpaceQuantityFormat getInstance()
      Returns the default format.
      Returns:
      the desired format.
    • getInstance

      public static NumberSpaceQuantityFormat getInstance(NumberFormat numberFormat, javax.measure.format.UnitFormat unitFormat)
      Returns the quantity format using the specified number format and unit format (the number and unit are separated by one space).
      Parameters:
      numberFormat - the number format.
      unitFormat - the unit format.
      Returns:
      the corresponding format.