Package tech.units.indriya.format
Class AbstractQuantityFormat
- java.lang.Object
-
- java.text.Format
-
- tech.units.indriya.format.AbstractQuantityFormat
-
- All Implemented Interfaces:
Serializable,Cloneable,QuantityFormat,tech.uom.lib.common.function.Parser<CharSequence,Quantity>
- Direct Known Subclasses:
NumberDelimiterQuantityFormat,SimpleQuantityFormat
public abstract class AbstractQuantityFormat extends Format implements QuantityFormat, tech.uom.lib.common.function.Parser<CharSequence,Quantity>
This class provides the interface for formatting and parsing
quantities.- Since:
- 1.0
- Version:
- 2.1, $Date: 2023-06-05 $
- Author:
- Jean-Marie Dautelle, Werner Keil
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class java.text.Format
Format.Field
-
-
Field Summary
Fields Modifier and Type Field Description protected static StringDEFAULT_DELIMITERThe default delimiter.
-
Constructor Summary
Constructors Constructor Description AbstractQuantityFormat()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description StringBufferformat(Object obj, StringBuffer toAppendTo, FieldPosition pos)Stringformat(Quantity<?> quantity)Formats an object to produce a string.abstract Appendableformat(Quantity<?> quantity, Appendable dest)Formats the specified quantity into anAppendable.protected StringBufferformat(ComparableQuantity<?> quantity, StringBuffer dest)Convenience method equivalent to#format(ComparableQuantity, Appendable)except it does not raise an IOException.protected abstract StringBufferformatMixed(MixedQuantity<?> mixed, StringBuffer dest)Convenience method equivalent to#format(MixedQuantity, Appendable)except it does not raise an IOException.abstract Quantity<?>parse(CharSequence csq)Parses a portion of the specifiedCharSequencefrom the specified position to produce an object.protected abstract Quantity<?>parse(CharSequence csq, int index)Parses a portion of the specifiedCharSequencefrom the specified position to produce an object.abstract Quantity<?>parse(CharSequence csq, ParsePosition cursor)Parses a portion of the specifiedCharSequencefrom the specified position to produce an object.Quantity<?>parseObject(String source, ParsePosition pos)-
Methods inherited from class java.text.Format
clone, format, formatToCharacterIterator, parseObject
-
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface javax.measure.format.QuantityFormat
isLocaleSensitive
-
-
-
-
Field Detail
-
DEFAULT_DELIMITER
protected static final String DEFAULT_DELIMITER
The default delimiter.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
AbstractQuantityFormat
public AbstractQuantityFormat()
-
-
Method Detail
-
format
public abstract Appendable format(Quantity<?> quantity, Appendable dest) throws IOException
Formats the specified quantity into anAppendable.- Specified by:
formatin interfaceQuantityFormat- Parameters:
quantity- the quantity to format.dest- the appendable destination.- Returns:
- the specified
Appendable. - Throws:
IOException- if an I/O exception occurs.
-
parse
public abstract Quantity<?> parse(CharSequence csq, ParsePosition cursor) throws IllegalArgumentException, MeasurementParseException
Parses a portion of the specifiedCharSequencefrom the specified position to produce an object. If parsing succeeds, then the index of thecursorargument is updated to the index after the last character used.- Specified by:
parsein interfaceQuantityFormat- Parameters:
csq- theCharSequenceto parse.cursor- the cursor holding the current parsing index.- Returns:
- the object parsed from the specified character sub-sequence.
- Throws:
IllegalArgumentException- if any problem occurs while parsing the specified character sequence (e.g. illegal syntax).MeasurementParseException
-
parse
public abstract Quantity<?> parse(CharSequence csq) throws MeasurementParseException
Parses a portion of the specifiedCharSequencefrom the specified position to produce an object. If parsing succeeds, then the index of thecursorargument is updated to the index after the last character used.- Specified by:
parsein interfacetech.uom.lib.common.function.Parser<CharSequence,Quantity>- Specified by:
parsein interfaceQuantityFormat- Parameters:
csq- theCharSequenceto parse.- Returns:
- the object parsed from the specified character sub-sequence.
- Throws:
IllegalArgumentException- if any problem occurs while parsing the specified character sequence (e.g. illegal syntax).MeasurementParseException
-
parse
protected abstract Quantity<?> parse(CharSequence csq, int index) throws IllegalArgumentException, MeasurementParseException
Parses a portion of the specifiedCharSequencefrom the specified position to produce an object. If parsing succeeds, then the index of thecursorargument is updated to the index after the last character used.- Parameters:
csq- theCharSequenceto parse.index- the current parsing index.- Returns:
- the object parsed from the specified character sub-sequence.
- Throws:
IllegalArgumentException- if any problem occurs while parsing the specified character sequence (e.g. illegal syntax).MeasurementParseException
-
format
public final StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos)
-
parseObject
public final Quantity<?> parseObject(String source, ParsePosition pos)
- Specified by:
parseObjectin classFormat
-
format
public final String format(Quantity<?> quantity)
Formats an object to produce a string. This is equivalent toformat(unit, new StringBuilder()).toString();- Specified by:
formatin interfaceQuantityFormat- Parameters:
quantity- The quantity to format- Returns:
- Formatted string.
-
format
protected final StringBuffer format(ComparableQuantity<?> quantity, StringBuffer dest)
Convenience method equivalent to#format(ComparableQuantity, Appendable)except it does not raise an IOException.- Parameters:
quantity- the quantity to format.dest- the appendable destination.- Returns:
- the specified
StringBuilder.
-
formatMixed
protected abstract StringBuffer formatMixed(MixedQuantity<?> mixed, StringBuffer dest)
Convenience method equivalent to#format(MixedQuantity, Appendable)except it does not raise an IOException.- Parameters:
mixed- the mixed quantity to format.dest- the appendable destination.- Returns:
- the specified
StringBuilder.
-
-