Package javax.measure.unit
Class UnitFormat.DefaultFormat
- java.lang.Object
-
- java.text.Format
-
- javax.measure.unit.UnitFormat
-
- javax.measure.unit.UnitFormat.DefaultFormat
-
- All Implemented Interfaces:
Serializable
,Cloneable
- Direct Known Subclasses:
UnitFormat.ASCIIFormat
- Enclosing class:
- UnitFormat
protected static class UnitFormat.DefaultFormat extends UnitFormat
This class represents the standard format.- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class javax.measure.unit.UnitFormat
UnitFormat.ASCIIFormat, UnitFormat.DefaultFormat
-
Nested classes/interfaces inherited from class java.text.Format
Format.Field
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
DefaultFormat()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
alias(Unit<?> unit, String alias)
Attaches a system-wide alias to this unit.Appendable
format(Unit<?> unit, Appendable appendable)
Formats the specified unit.boolean
isValidIdentifier(String name)
Indicates if the specified name can be used as unit identifier.void
label(Unit<?> unit, String label)
Attaches a system-wide label to the specified unit.String
nameFor(Unit<?> unit)
Unit<? extends Quantity>
parseProductUnit(CharSequence csq, ParsePosition pos)
Parses a sequence of character to produce a unit or a rational product of unit.Unit<? extends Quantity>
parseSingleUnit(CharSequence csq, ParsePosition pos)
Parses a sequence of character to produce a single unit.Unit<?>
unitFor(String name)
-
Methods inherited from class javax.measure.unit.UnitFormat
format, getInstance, getInstance, getUCUMInstance, parseObject
-
Methods inherited from class java.text.Format
clone, format, formatToCharacterIterator, parseObject
-
-
-
-
Method Detail
-
label
public void label(Unit<?> unit, String label)
Description copied from class:UnitFormat
Attaches a system-wide label to the specified unit. For example: [code] UnitFormat.getInstance().label(DAY.multiply(365), "year"); UnitFormat.getInstance().label(METER.multiply(0.3048), "ft"); [/code] If the specified label is already associated to an unit the previous association is discarded or ignored.- Specified by:
label
in classUnitFormat
- Parameters:
unit
- the unit being labelled.label
- the new label for this unit.
-
alias
public void alias(Unit<?> unit, String alias)
Description copied from class:UnitFormat
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: [code] UnitFormat.getLocaleInstance().alias(METER.multiply(0.3048), "foot"); UnitFormat.getLocaleInstance().alias(METER.multiply(0.3048), "feet"); UnitFormat.getLocaleInstance().alias(METER, "meter"); UnitFormat.getLocaleInstance().alias(METER, "metre"); [/code] If the specified label is already associated to an unit the previous association is discarded or ignored.- Specified by:
alias
in classUnitFormat
- Parameters:
unit
- the unit being aliased.alias
- the alias attached to this unit.
-
isValidIdentifier
public boolean isValidIdentifier(String name)
Description copied from class:UnitFormat
Indicates if the specified name can be used as unit identifier.- Specified by:
isValidIdentifier
in classUnitFormat
- 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.
-
parseSingleUnit
public Unit<? extends Quantity> parseSingleUnit(CharSequence csq, ParsePosition pos) throws ParseException
Description copied from class:UnitFormat
Parses a sequence of character to produce a single unit.- Specified by:
parseSingleUnit
in classUnitFormat
- Parameters:
csq
- theCharSequence
to parse.pos
- an object holding the parsing index and error position.- Returns:
- an
Unit
parsed from the character sequence. - Throws:
ParseException
-
parseProductUnit
public Unit<? extends Quantity> parseProductUnit(CharSequence csq, ParsePosition pos) throws ParseException
Description copied from class:UnitFormat
Parses a sequence of character to produce a unit or a rational product of unit.- Specified by:
parseProductUnit
in classUnitFormat
- Parameters:
csq
- theCharSequence
to parse.pos
- an object holding the parsing index and error position.- Returns:
- an
Unit
parsed from the character sequence. - Throws:
ParseException
-
format
public Appendable format(Unit<?> unit, Appendable appendable) throws IOException
Description copied from class:UnitFormat
Formats the specified unit.- Specified by:
format
in classUnitFormat
- Parameters:
unit
- the unit to format.appendable
- the appendable destination.- Throws:
IOException
- if an error occurs.
-
-