Package tech.units.indriya.format
Class AbstractUnitFormat
java.lang.Object
tech.units.indriya.format.AbstractUnitFormat
- All Implemented Interfaces:
javax.measure.format.UnitFormat
- Direct Known Subclasses:
EBNFUnitFormat
,LocalUnitFormat
,SimpleUnitFormat
This class provides the interface for formatting and parsing units
.
For all metric units, the 20 SI prefixes used to form decimal multiples and sub-multiples of SI units are recognized. For example:
AbstractUnit.parse("m°C").equals(MetricPrefix.MILLI(Units.CELSIUS))
AbstractUnit.parse("kW").equals(MetricPrefix.KILO(Units.WATT))
- Since:
- 1.0
- Version:
- 1.0.3, $Date: 2018-01-28 $
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal String
format
(javax.measure.Unit<?> unit) Formats an object to produce a string.abstract Appendable
format
(javax.measure.Unit<?> unit, Appendable appendable) Formats the specified unit.(package private) final StringBuilder
format
(AbstractUnit<?> unit, StringBuilder dest) Convenience method equivalent toinvalid reference
#format(AbstractUnit, Appendable)
protected abstract SymbolMap
Returns theSymbolMap
for this unit format.void
protected abstract javax.measure.Unit
<?> parse
(CharSequence csq, int index) Parses a portion of the specifiedCharSequence
from the specified position to produce a unit.protected abstract javax.measure.Unit
<?> parse
(CharSequence csq, ParsePosition cursor) Parses a portion of the specifiedCharSequence
from the specified position to produce a unit.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface javax.measure.format.UnitFormat
isLocaleSensitive, parse
-
Constructor Details
-
AbstractUnitFormat
public AbstractUnitFormat()
-
-
Method Details
-
getSymbols
Returns theSymbolMap
for this unit format.- Returns:
- the symbol map used by this format.
-
format
public abstract Appendable format(javax.measure.Unit<?> unit, Appendable appendable) throws IOException Formats the specified unit.- Specified by:
format
in interfacejavax.measure.format.UnitFormat
- 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.
-
format
Formats an object to produce a string. This is equivalent toinvalid reference
format
(unit, new StringBuilder()).toString();
- Specified by:
format
in interfacejavax.measure.format.UnitFormat
- Parameters:
obj
- The object to format- Returns:
- Formatted string.
- Throws:
IllegalArgumentException
- if the Format cannot format the given object
-
label
- Specified by:
label
in interfacejavax.measure.format.UnitFormat
-
parse
protected abstract javax.measure.Unit<?> parse(CharSequence csq, ParsePosition cursor) throws IllegalArgumentException Parses a portion of the specifiedCharSequence
from the specified position to produce a unit. If there is no unit to parseAbstractUnit.ONE
is returned.- Parameters:
csq
- theCharSequence
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).
-
parse
protected abstract javax.measure.Unit<?> parse(CharSequence csq, int index) throws IllegalArgumentException Parses a portion of the specifiedCharSequence
from the specified position to produce a unit. If there is no unit to parseAbstractUnit.ONE
is returned.- Parameters:
csq
- theCharSequence
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).
-
format
Convenience method equivalent toinvalid reference
#format(AbstractUnit, Appendable)
- Parameters:
unit
- the unit to format.dest
- the appendable destination.- Returns:
- the specified
StringBuilder
.
-