public abstract class AbstractUnitFormat
extends java.lang.Object
implements javax.measure.format.UnitFormat
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))
Constructor and Description |
---|
AbstractUnitFormat() |
Modifier and Type | Method and Description |
---|---|
(package private) java.lang.StringBuilder |
format(AbstractUnit<?> unit,
java.lang.StringBuilder dest)
Convenience method equivalent to
#format(AbstractUnit, Appendable) except it does not raise an IOException. |
java.lang.String |
format(javax.measure.Unit<?> unit)
Formats an object to produce a string.
|
abstract java.lang.Appendable |
format(javax.measure.Unit<?> unit,
java.lang.Appendable appendable)
Formats the specified unit.
|
protected abstract SymbolMap |
getSymbols()
Returns the
SymbolMap for this unit format. |
void |
label(javax.measure.Unit<?> unit,
java.lang.String label) |
protected abstract javax.measure.Unit<?> |
parse(java.lang.CharSequence csq,
int index)
Parses a portion of the specified
CharSequence from the specified position to produce a unit. |
protected abstract javax.measure.Unit<?> |
parse(java.lang.CharSequence csq,
java.text.ParsePosition cursor)
Parses a portion of the specified
CharSequence from the specified position to produce a unit. |
protected abstract SymbolMap getSymbols()
SymbolMap
for this unit format.public abstract java.lang.Appendable format(javax.measure.Unit<?> unit, java.lang.Appendable appendable) throws java.io.IOException
format
in interface javax.measure.format.UnitFormat
unit
- the unit to format.appendable
- the appendable destination.appendable
, with formatted text appended.java.io.IOException
- if an error occurs.public final java.lang.String format(javax.measure.Unit<?> unit)
format
(unit, new StringBuilder()).toString();
format
in interface javax.measure.format.UnitFormat
obj
- The object to formatjava.lang.IllegalArgumentException
- if the Format cannot format the given objectpublic void label(javax.measure.Unit<?> unit, java.lang.String label)
label
in interface javax.measure.format.UnitFormat
protected abstract javax.measure.Unit<?> parse(java.lang.CharSequence csq, java.text.ParsePosition cursor) throws java.lang.IllegalArgumentException
CharSequence
from the specified position to produce a unit. If there is no unit to parse
AbstractUnit.ONE
is returned.csq
- the CharSequence
to parse.cursor
- the cursor holding the current parsing index.java.lang.IllegalArgumentException
- if any problem occurs while parsing the specified character sequence (e.g. illegal syntax).protected abstract javax.measure.Unit<?> parse(java.lang.CharSequence csq, int index) throws java.lang.IllegalArgumentException
CharSequence
from the specified position to produce a unit. If there is no unit to parse
AbstractUnit.ONE
is returned.csq
- the CharSequence
to parse.index
- the current parsing index.java.lang.IllegalArgumentException
- if any problem occurs while parsing the specified character sequence (e.g. illegal syntax).final java.lang.StringBuilder format(AbstractUnit<?> unit, java.lang.StringBuilder dest)
#format(AbstractUnit, Appendable)
except it does not raise an IOException.unit
- the unit to format.dest
- the appendable destination.StringBuilder
.