public abstract class AbstractUnitFormat extends 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 |
|---|---|
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.
|
protected abstract SymbolMap |
getSymbols()
Returns the
SymbolMap for this unit format. |
void |
label(javax.measure.Unit<?> unit,
String label) |
protected abstract javax.measure.Unit<?> |
parse(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(CharSequence csq,
ParsePosition cursor)
Parses a portion of the specified
CharSequence from the specified position to produce a unit. |
public AbstractUnitFormat()
protected abstract SymbolMap getSymbols()
SymbolMap for this unit format.public abstract Appendable format(javax.measure.Unit<?> unit, Appendable appendable) throws IOException
format in interface javax.measure.format.UnitFormatunit - the unit to format.appendable - the appendable destination.appendable, with formatted text appended.IOException - if an error occurs.public final String format(javax.measure.Unit<?> unit)
format(unit, new StringBuilder()).toString();
format in interface javax.measure.format.UnitFormatobj - The object to formatIllegalArgumentException - if the Format cannot format the given objectpublic void label(javax.measure.Unit<?> unit, String label)
label in interface javax.measure.format.UnitFormatprotected abstract javax.measure.Unit<?> parse(CharSequence csq, ParsePosition cursor) throws 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.IllegalArgumentException - if any problem occurs while parsing the specified character sequence (e.g. illegal syntax).protected abstract javax.measure.Unit<?> parse(CharSequence csq, int index) throws 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.IllegalArgumentException - if any problem occurs while parsing the specified character sequence (e.g. illegal syntax).Copyright © 2005–2017 Units of Measurement project. All rights reserved.