Class SimpleQuantityFormat

  • All Implemented Interfaces:
    Serializable, Cloneable, javax.measure.format.QuantityFormat, tech.uom.lib.common.function.Parser<CharSequence,​javax.measure.Quantity>

    public class SimpleQuantityFormat
    extends AbstractQuantityFormat
    A simple implementation of QuantityFormat

    The following pattern letters are defined:

    Chart shows pattern letters, date/time component, presentation, and examples.
    Letter Quantity Component Presentation Examples
    n Numeric value Number 27
    u Unit Text m
    ~ Mixed radix Text 1 m; 27 cm
    Pattern letters are usually repeated, as their number determines the exact presentation:
    • Text: For formatting, if the number of pattern letters is 4 or more, the full form is used; otherwise a short or abbreviated form is used if available. For parsing, both forms are accepted, independent of the number of pattern letters.

    • Number: For formatting, the number of pattern letters is the minimum number of digits, and shorter numbers are zero-padded to this amount. For parsing, the number of pattern letters is ignored unless it's needed to separate two adjacent fields.

    • Mixed Radix: The Mixed radix marker "~" is followed by a character sequence acting as mixed radix delimiter. This character sequence must not contain "~" itself or any numeric values.

    Since:
    2.0
    Version:
    1.4, $Date: 2019-04-14 $
    See Also:
    Serialized Form
    • Constructor Detail

      • SimpleQuantityFormat

        protected SimpleQuantityFormat()
        Constructs a SimpleQuantityFormat using the default pattern. For full coverage, use the factory methods.
    • Method Detail

      • 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 javax.measure.format.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 javax.measure.Quantity<?> parse​(CharSequence csq,
                                               ParsePosition cursor)
                                        throws javax.measure.format.MeasurementParseException
        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 javax.measure.format.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:
        javax.measure.format.MeasurementParseException
      • parse

        protected javax.measure.Quantity<?> parse​(CharSequence csq,
                                                  int index)
                                           throws javax.measure.format.MeasurementParseException
        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:
        javax.measure.format.MeasurementParseException
      • parse

        public javax.measure.Quantity<?> parse​(CharSequence csq)
                                        throws javax.measure.format.MeasurementParseException
        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,​javax.measure.Quantity>
        Specified by:
        parse in interface javax.measure.format.QuantityFormat
        Specified by:
        parse in class AbstractQuantityFormat
        Parameters:
        csq - the CharSequence to parse.
        Returns:
        the object parsed from the specified character sub-sequence.
        Throws:
        javax.measure.format.MeasurementParseException
      • getInstance

        public static SimpleQuantityFormat getInstance()
        Returns the quantity format for the default locale. The default format assumes the quantity is composed of a decimal number and a Unit separated by whitespace(s).
        Returns:
        a default SimpleQuantityFormat instance.
      • getInstance

        public static SimpleQuantityFormat getInstance​(String pattern)
        Returns a SimpleQuantityFormat using the given pattern.

        Parameters:
        pattern - the pattern describing the quantity and unit format
        Returns:
        SimpleQuantityFormat.getInstance(a pattern)