Package tech.units.indriya.format
Class AbstractQuantityFormat
- java.lang.Object
-
- java.text.Format
-
- tech.units.indriya.format.AbstractQuantityFormat
-
- All Implemented Interfaces:
Serializable,Cloneable,javax.measure.format.QuantityFormat,tech.uom.lib.common.function.Parser<CharSequence,javax.measure.Quantity>
- Direct Known Subclasses:
NumberDelimiterQuantityFormat,SimpleQuantityFormat
public abstract class AbstractQuantityFormat extends Format implements javax.measure.format.QuantityFormat, tech.uom.lib.common.function.Parser<CharSequence,javax.measure.Quantity>
This class provides the interface for formatting and parsing
quantities.- Since:
- 1.0
- Version:
- 2.0, $Date: 2020-02-23 $
- 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
Modifier and Type Method Description StringBufferformat(Object obj, StringBuffer toAppendTo, FieldPosition pos)Stringformat(javax.measure.Quantity<?> quantity)Formats an object to produce a string.abstract Appendableformat(javax.measure.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 StringBufferformatCompound(CompoundQuantity<?> comp, StringBuffer dest)Convenience method equivalent to#format(CompoundQuantity, Appendable)except it does not raise an IOException.abstract javax.measure.Quantity<?>parse(CharSequence csq)Parses a portion of the specifiedCharSequencefrom the specified position to produce an object.protected abstract javax.measure.Quantity<?>parse(CharSequence csq, int index)Parses a portion of the specifiedCharSequencefrom the specified position to produce an object.abstract javax.measure.Quantity<?>parse(CharSequence csq, ParsePosition cursor)Parses a portion of the specifiedCharSequencefrom the specified position to produce an object.javax.measure.Quantity<?>parseObject(String source, ParsePosition pos)-
Methods inherited from class java.text.Format
clone, format, formatToCharacterIterator, parseObject
-
-
-
-
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(javax.measure.Quantity<?> quantity, Appendable dest) throws IOException
Formats the specified quantity into anAppendable.- Specified by:
formatin interfacejavax.measure.format.QuantityFormat- 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 javax.measure.Quantity<?> parse(CharSequence csq, ParsePosition cursor) throws IllegalArgumentException, javax.measure.format.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 interfacejavax.measure.format.QuantityFormat- 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).javax.measure.format.MeasurementParseException
-
parse
public abstract javax.measure.Quantity<?> parse(CharSequence csq) throws javax.measure.format.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,javax.measure.Quantity>- Specified by:
parsein interfacejavax.measure.format.QuantityFormat- 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).javax.measure.format.MeasurementParseException
-
parse
protected abstract javax.measure.Quantity<?> parse(CharSequence csq, int index) throws IllegalArgumentException, javax.measure.format.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).javax.measure.format.MeasurementParseException
-
format
public final StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos)
-
parseObject
public final javax.measure.Quantity<?> parseObject(String source, ParsePosition pos)
- Specified by:
parseObjectin classFormat
-
format
public final String format(javax.measure.Quantity<?> quantity)
Formats an object to produce a string. This is equivalent toformat(unit, new StringBuilder()).toString();- Specified by:
formatin interfacejavax.measure.format.QuantityFormat- 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.
-
formatCompound
protected abstract StringBuffer formatCompound(CompoundQuantity<?> comp, StringBuffer dest)
Convenience method equivalent to#format(CompoundQuantity, Appendable)except it does not raise an IOException.- Parameters:
comp- the composite quantity to format.dest- the appendable destination.- Returns:
- the specified
StringBuilder.
-
-