Class SimpleUnitFormat.DefaultFormat
java.lang.Object
tech.units.indriya.format.AbstractUnitFormat
tech.units.indriya.format.SimpleUnitFormat
tech.units.indriya.format.SimpleUnitFormat.DefaultFormat
- All Implemented Interfaces:
javax.measure.format.UnitFormat
- Direct Known Subclasses:
SimpleUnitFormat.ASCIIFormat
- Enclosing class:
SimpleUnitFormat
This class represents the standard format.
- Since:
- 1.0
- Version:
- 1.5, April 15, 2019
- Author:
- Jean-Marie Dautelle, Werner Keil, Eric Russell
-
Nested Class Summary
Nested classes/interfaces inherited from class SimpleUnitFormat
SimpleUnitFormat.ASCIIFormat, SimpleUnitFormat.DefaultFormat, SimpleUnitFormat.Flavor -
Field Summary
FieldsModifier and TypeFieldDescriptionHolds the name to unit mapping.Holds the unit to name mapping. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAttaches a system-wide alias to this unit.format(javax.measure.Unit<?> unit, Appendable appendable) Formats the specified unit.protected SymbolMapReturns theSymbolMapfor this unit format.booleanprotected static booleanisUnitIdentifierPart(char ch) booleanisValidIdentifier(String name) Indicates if the specified name can be used as unit identifier.voidAttaches a system-wide label to the specified unit.protected StringnameFor(javax.measure.Unit<?> unit) javax.measure.Unit<?> parse(CharSequence csq) protected javax.measure.Unit<?> parse(CharSequence csq, int index) Parses a portion of the specifiedCharSequencefrom the specified position to produce a unit.protected javax.measure.Unit<?> parse(CharSequence csq, ParsePosition cursor) Parses a portion of the specifiedCharSequencefrom the specified position to produce a unit.javax.measure.Unit<? extends javax.measure.Quantity> parseProductUnit(CharSequence csq, ParsePosition pos) Parses a sequence of character to produce a unit or a rational product of unit.javax.measure.Unit<? extends javax.measure.Quantity> parseSingleUnit(CharSequence csq, ParsePosition pos) Parses a sequence of character to produce a single unit.protected StringprefixFor(javax.measure.UnitConverter converter) protected javax.measure.Unit<?> Methods inherited from class SimpleUnitFormat
format, getInstance, getInstance, isAllASCII, parseObjectMethods inherited from class AbstractUnitFormat
format
-
Field Details
-
nameToUnit
Holds the name to unit mapping. -
unitToName
Holds the unit to name mapping.
-
-
Constructor Details
-
DefaultFormat
protected DefaultFormat()
-
-
Method Details
-
label
Description copied from class:SimpleUnitFormatAttaches 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:
labelin interfacejavax.measure.format.UnitFormat- Specified by:
labelin classSimpleUnitFormat- Parameters:
unit- the unit being labeled.label- the new label for this unit.
-
alias
Description copied from class:SimpleUnitFormatAttaches 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:
aliasin classSimpleUnitFormat- Parameters:
unit- the unit being aliased.alias- the alias attached to this unit.
-
isValidIdentifier
Description copied from class:SimpleUnitFormatIndicates if the specified name can be used as unit identifier.- Specified by:
isValidIdentifierin classSimpleUnitFormat- Parameters:
name- the identifier to be tested.- Returns:
trueif the name specified can be used as label or alias for this format;falseotherwise.
-
isUnitIdentifierPart
-
nameFor
-
prefixFor
-
unitFor
-
parseSingleUnit
public javax.measure.Unit<? extends javax.measure.Quantity> parseSingleUnit(CharSequence csq, ParsePosition pos) throws javax.measure.format.ParserException Description copied from class:SimpleUnitFormatParses a sequence of character to produce a single unit.- Specified by:
parseSingleUnitin classSimpleUnitFormat- Parameters:
csq- theCharSequenceto parse.pos- an object holding the parsing index and error position.- Returns:
- an
Unitparsed from the character sequence. - Throws:
javax.measure.format.ParserException
-
parseProductUnit
public javax.measure.Unit<? extends javax.measure.Quantity> parseProductUnit(CharSequence csq, ParsePosition pos) throws javax.measure.format.ParserException Description copied from class:SimpleUnitFormatParses a sequence of character to produce a unit or a rational product of unit.- Specified by:
parseProductUnitin classSimpleUnitFormat- Parameters:
csq- theCharSequenceto parse.pos- an object holding the parsing index and error position.- Returns:
- an
Unitparsed from the character sequence. - Throws:
javax.measure.format.ParserException
-
format
Description copied from class:SimpleUnitFormatFormats the specified unit.- Specified by:
formatin interfacejavax.measure.format.UnitFormat- Specified by:
formatin classSimpleUnitFormat- 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
- Throws:
javax.measure.format.ParserException
-
getSymbols
Description copied from class:AbstractUnitFormatReturns theSymbolMapfor this unit format.- Specified by:
getSymbolsin classAbstractUnitFormat- Returns:
- the symbol map used by this format.
-
parse
Description copied from class:AbstractUnitFormatParses a portion of the specifiedCharSequencefrom the specified position to produce a unit. If there is no unit to parseAbstractUnit.ONEis returned.- Specified by:
parsein classAbstractUnitFormat- Parameters:
csq- theCharSequenceto 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
protected javax.measure.Unit<?> parse(CharSequence csq, ParsePosition cursor) throws IllegalArgumentException Description copied from class:AbstractUnitFormatParses a portion of the specifiedCharSequencefrom the specified position to produce a unit. If there is no unit to parseAbstractUnit.ONEis returned.- Specified by:
parsein classAbstractUnitFormat- Parameters:
csq- theCharSequenceto 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).
-
isLocaleSensitive
-