Package tech.units.indriya.format
Class AbstractUnitFormat
- java.lang.Object
-
- tech.units.indriya.format.AbstractUnitFormat
-
- All Implemented Interfaces:
UnitFormat
- Direct Known Subclasses:
EBNFUnitFormat,LocalUnitFormat,SimpleUnitFormat
public abstract class AbstractUnitFormat extends Object implements 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.
As well as the 8 Binary prefixes.
For example:AbstractUnit.parse("m°C").equals(MetricPrefix.MILLI(Units.CELSIUS)) AbstractUnit.parse("kW").equals(MetricPrefix.KILO(Units.WATT))- Since:
- 1.0
- Version:
- 2.0, $Date: 2020-03-02 $
- Author:
- Jean-Marie Dautelle, Werner Keil
-
-
Constructor Summary
Constructors Constructor Description AbstractUnitFormat()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description Stringformat(Unit<?> unit)Formats an object to produce a string.abstract Appendableformat(Unit<?> unit, Appendable appendable)Formats the specified unit.voidlabel(Unit<?> unit, String label)protected abstract Unit<?>parse(CharSequence csq, int index)Parses a portion of the specifiedCharSequencefrom the specified position to produce a unit.abstract Unit<?>parse(CharSequence csq, ParsePosition cursor)Parses a portion of the specifiedCharSequencefrom 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 Detail
-
AbstractUnitFormat
public AbstractUnitFormat()
-
-
Method Detail
-
format
public abstract Appendable format(Unit<?> unit, Appendable appendable) throws IOException
Formats the specified unit.- Specified by:
formatin interfaceUnitFormat- 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
public final String format(Unit<?> unit)
Formats an object to produce a string. This is equivalent toformat(unit, new StringBuilder()).toString();- Specified by:
formatin interfaceUnitFormat- Parameters:
obj- The object to format- Returns:
- Formatted string.
- Throws:
IllegalArgumentException- if the Format cannot format the given object
-
label
public void label(Unit<?> unit, String label)
- Specified by:
labelin interfaceUnitFormat
-
parse
public abstract Unit<?> parse(CharSequence csq, ParsePosition cursor) throws IllegalArgumentException
Parses a portion of the specifiedCharSequencefrom the specified position to produce a unit. If there is no unit to parseAbstractUnit.ONEis returned.- Specified by:
parsein interfaceUnitFormat- Parameters:
csq- theCharSequenceto 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 Unit<?> parse(CharSequence csq, int index) throws IllegalArgumentException
Parses 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:
IllegalArgumentException- if any problem occurs while parsing the specified character sequence (e.g. illegal syntax).
-
-