Class SimpleUnitFormat.DefaultFormat

    • Field Detail

      • nameToUnit

        protected final Map<String,​javax.measure.Unit<?>> nameToUnit
        Holds the name to unit mapping.
      • unitToName

        protected final Map<javax.measure.Unit<?>,​String> unitToName
        Holds the unit to name mapping.
    • Method Detail

      • label

        public void label​(javax.measure.Unit<?> unit,
                          String label)
        Description copied from class: SimpleUnitFormat
        Attaches a system-wide label to the specified unit. For example: SimpleUnitFormat.getInstance().label(DAY.multiply(365), "year"); SimpleUnitFormat.getInstance().label(METER.multiply(0.3048), "ft"); If the specified label is already associated to an unit the previous association is discarded or ignored.
        Specified by:
        label in interface javax.measure.format.UnitFormat
        Specified by:
        label in class SimpleUnitFormat
        Parameters:
        unit - the unit being labeled.
        label - the new label for this unit.
      • alias

        public void alias​(javax.measure.Unit<?> unit,
                          String alias)
        Description copied from class: SimpleUnitFormat
        Attaches a system-wide alias to this unit. Multiple aliases may be attached to the same unit. Aliases are used during parsing to recognize different variants of the same unit. For example: SimpleUnitFormat.getInstance().alias(METER.multiply(0.3048), "foot"); SimpleUnitFormat.getInstance().alias(METER.multiply(0.3048), "feet"); SimpleUnitFormat.getInstance().alias(METER, "meter"); SimpleUnitFormat.getInstance().alias(METER, "metre"); If the specified label is already associated to an unit the previous association is discarded or ignored.
        Specified by:
        alias in class SimpleUnitFormat
        Parameters:
        unit - the unit being aliased.
        alias - the alias attached to this unit.
      • isValidIdentifier

        protected boolean isValidIdentifier​(String name)
        Description copied from class: SimpleUnitFormat
        Indicates if the specified name can be used as unit identifier.
        Specified by:
        isValidIdentifier in class SimpleUnitFormat
        Parameters:
        name - the identifier to be tested.
        Returns:
        true if the name specified can be used as label or alias for this format;false otherwise.
      • nameFor

        protected String nameFor​(javax.measure.Unit<?> unit)
      • prefixFor

        protected String prefixFor​(javax.measure.UnitConverter converter)
      • unitFor

        protected javax.measure.Unit<?> unitFor​(String name)
      • parseSingleUnit

        public javax.measure.Unit<? extends javax.measure.Quantity> parseSingleUnit​(CharSequence csq,
                                                                                    ParsePosition pos)
                                                                             throws javax.measure.format.MeasurementParseException
        Description copied from class: SimpleUnitFormat
        Parses a sequence of character to produce a single unit.
        Specified by:
        parseSingleUnit in class SimpleUnitFormat
        Parameters:
        csq - the CharSequence to parse.
        pos - an object holding the parsing index and error position.
        Returns:
        an Unit parsed from the character sequence.
        Throws:
        javax.measure.format.MeasurementParseException
      • parseProductUnit

        public javax.measure.Unit<? extends javax.measure.Quantity> parseProductUnit​(CharSequence csq,
                                                                                     ParsePosition pos)
                                                                              throws javax.measure.format.MeasurementParseException
        Description copied from class: SimpleUnitFormat
        Parses a sequence of character to produce a unit or a rational product of unit.
        Specified by:
        parseProductUnit in class SimpleUnitFormat
        Parameters:
        csq - the CharSequence to parse.
        pos - an object holding the parsing index and error position.
        Returns:
        an Unit parsed from the character sequence.
        Throws:
        javax.measure.format.MeasurementParseException
      • format

        public Appendable format​(javax.measure.Unit<?> unit,
                                 Appendable appendable)
                          throws IOException
        Description copied from class: SimpleUnitFormat
        Formats the specified unit.
        Specified by:
        format in interface javax.measure.format.UnitFormat
        Specified by:
        format in class SimpleUnitFormat
        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.
      • parse

        public javax.measure.Unit<?> parse​(CharSequence csq)
                                    throws javax.measure.format.MeasurementParseException
        Throws:
        javax.measure.format.MeasurementParseException
      • parse

        protected javax.measure.Unit<?> parse​(CharSequence csq,
                                              int index)
                                       throws IllegalArgumentException
        Description copied from class: AbstractUnitFormat
        Parses a portion of the specified CharSequence from the specified position to produce a unit. If there is no unit to parse AbstractUnit.ONE is returned.
        Specified by:
        parse in class AbstractUnitFormat
        Parameters:
        csq - the CharSequence to parse.
        index - the current parsing index.
        Returns:
        the unit parsed from the specified character sub-sequence.
        Throws:
        IllegalArgumentException - if any problem occurs while parsing the specified character sequence (e.g. illegal syntax).
      • parse

        public javax.measure.Unit<?> parse​(CharSequence csq,
                                           ParsePosition cursor)
                                    throws IllegalArgumentException
        Description copied from class: AbstractUnitFormat
        Parses a portion of the specified CharSequence from the specified position to produce a unit. If there is no unit to parse AbstractUnit.ONE is returned.
        Specified by:
        parse in interface javax.measure.format.UnitFormat
        Specified by:
        parse in class AbstractUnitFormat
        Parameters:
        csq - the CharSequence to parse.
        cursor - the cursor holding the current parsing index.
        Returns:
        the unit parsed from the specified character sub-sequence.
        Throws:
        IllegalArgumentException - if any problem occurs while parsing the specified character sequence (e.g. illegal syntax).