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
public abstract class AbstractUnitFormat extends java.lang.Object implements javax.measure.format.UnitFormatThis 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 Constructor Description AbstractUnitFormat()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description java.lang.Stringformat(javax.measure.Unit<?> unit)Formats an object to produce a string.abstract java.lang.Appendableformat(javax.measure.Unit<?> unit, java.lang.Appendable appendable)Formats the specified unit.(package private) java.lang.StringBuilderformat(AbstractUnit<?> unit, java.lang.StringBuilder dest)Convenience method equivalent to#format(AbstractUnit, Appendable)except it does not raise an IOException.protected abstract SymbolMapgetSymbols()Returns theSymbolMapfor this unit format.voidlabel(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 specifiedCharSequencefrom 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 specifiedCharSequencefrom the specified position to produce a unit.
-
-
-
Method Detail
-
getSymbols
protected abstract SymbolMap getSymbols()
Returns theSymbolMapfor this unit format.- Returns:
- the symbol map used by this format.
-
format
public abstract java.lang.Appendable format(javax.measure.Unit<?> unit, java.lang.Appendable appendable) throws java.io.IOExceptionFormats the specified unit.- Specified by:
formatin 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:
java.io.IOException- if an error occurs.
-
format
public final java.lang.String format(javax.measure.Unit<?> unit)
Formats an object to produce a string. This is equivalent toformat(unit, new StringBuilder()).toString();- Specified by:
formatin interfacejavax.measure.format.UnitFormat- Parameters:
obj- The object to format- Returns:
- Formatted string.
- Throws:
java.lang.IllegalArgumentException- if the Format cannot format the given object
-
label
public void label(javax.measure.Unit<?> unit, java.lang.String label)- Specified by:
labelin interfacejavax.measure.format.UnitFormat
-
parse
protected abstract javax.measure.Unit<?> parse(java.lang.CharSequence csq, java.text.ParsePosition cursor) throws java.lang.IllegalArgumentExceptionParses a portion of the specifiedCharSequencefrom the specified position to produce a unit. If there is no unit to parseAbstractUnit.ONEis returned.- Parameters:
csq- theCharSequenceto parse.cursor- the cursor holding the current parsing index.- Returns:
- the unit parsed from the specified character sub-sequence.
- Throws:
java.lang.IllegalArgumentException- if any problem occurs while parsing the specified character sequence (e.g. illegal syntax).
-
parse
protected abstract javax.measure.Unit<?> parse(java.lang.CharSequence csq, int index) throws java.lang.IllegalArgumentExceptionParses a portion of the specifiedCharSequencefrom the specified position to produce a unit. If there is no unit to parseAbstractUnit.ONEis returned.- Parameters:
csq- theCharSequenceto parse.index- the current parsing index.- Returns:
- the unit parsed from the specified character sub-sequence.
- Throws:
java.lang.IllegalArgumentException- if any problem occurs while parsing the specified character sequence (e.g. illegal syntax).
-
format
final java.lang.StringBuilder format(AbstractUnit<?> unit, java.lang.StringBuilder dest)
Convenience method equivalent to#format(AbstractUnit, Appendable)except it does not raise an IOException.- Parameters:
unit- the unit to format.dest- the appendable destination.- Returns:
- the specified
StringBuilder.
-
-