Top Description Fields Constructors Methods
tech.units.indriya.format

public abstract Class AbstractQuantityFormat

extends Format
implements QuantityFormat, Parser<CharSequence, Quantity<Q extends Quantity<Q>>>
Class Inheritance
All Implemented Interfaces
tech.uom.lib.common.function.Parser, javax.measure.format.QuantityFormat
Known Direct Subclasses
tech.units.indriya.format.NumberDelimiterQuantityFormat, tech.units.indriya.format.SimpleQuantityFormat
Annotations
@SuppressWarnings:rawtypes
Imports
java.io.IOException, java.text.FieldPosition, .Format, .ParsePosition, javax.measure.MeasurementException, .Quantity, .Unit, javax.measure.format.MeasurementParseException, .QuantityFormat, tech.units.indriya.ComparableQuantity, tech.units.indriya.quantity.MixedQuantity, tech.uom.lib.common.function.Parser

This class provides the interface for formatting and parsing quantities.

Authors
Jean-Marie Dautelle, Werner Keil
Since
1.0
Version
2.1, $Date: 2023-06-05 $

Field Summary

Modifier and TypeField and Description
protected static final String
DEFAULT_DELIMITER

The default delimiter.

private static final long

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public abstract Appendable

Returns:

the specified Appendable.
format
(Quantity<?>
the quantity to format.
quantity
,
Appendable
the appendable destination.
dest
)

Redeclares javax.measure.format.QuantityFormat.format.

Formats the specified quantity into an Appendable.

public final StringBuffer
format(Object
The object to format
obj
,
final StringBuffer
where the text is to be appended
toAppendTo
,
FieldPosition
A FieldPosition identifying a field in the formatted text
pos
)

Implements abstract java.text.Format.format.

Formats an object and appends the resulting text to a given string buffer.

public final String

Returns:

Formatted string.
format
(Quantity<?>
The quantity to format
quantity
)

Implements javax.measure.format.QuantityFormat.format.

Formats an object to produce a string.

protected final StringBuffer

Returns:

the specified StringBuilder.
format
(ComparableQuantity<?>
the quantity to format.
quantity
,
StringBuffer
the appendable destination.
dest
)

Convenience method equivalent to format(ComparableQuantity, Appendable) except it does not raise an IOException.

protected abstract StringBuffer

Returns:

the specified StringBuilder.
formatMixed
(MixedQuantity<?>
the mixed quantity to format.
mixed
,
StringBuffer
the appendable destination.
dest
)

Convenience method equivalent to format(MixedQuantity, Appendable) except it does not raise an IOException.

public abstract Quantity<?>

Returns:

the object parsed from the specified character sub-sequence.
parse
(CharSequence
the CharSequence to parse.
csq
,
ParsePosition
the cursor holding the current parsing index.
cursor
)

Redeclares javax.measure.format.QuantityFormat.parse.

Parses a portion of the specified CharSequence from the specified position to produce an object.

public abstract Quantity<?>

Returns:

the object parsed from the specified character sub-sequence.
parse
(CharSequence
the CharSequence to parse.
csq
)

Redeclares javax.measure.format.QuantityFormat.parse, tech.uom.lib.common.function.Parser.parse.

Parses a portion of the specified CharSequence from the specified position to produce an object.

protected abstract Quantity<?>

Returns:

the object parsed from the specified character sub-sequence.
parse
(CharSequence
the CharSequence to parse.
csq
,
int
the current parsing index.
index
)

Parses a portion of the specified CharSequence from the specified position to produce an object.

public final Quantity<?>
parseObject(String
the String to parse
source
,
ParsePosition
A ParsePosition object with index and error index information as described above.
pos
)

Implements abstract java.text.Format.parseObject.

Parses text from the given string to produce an object.

Inherited from java.text.Format:
cloneformatformatToCharacterIteratorparseObject

Field Detail

DEFAULT_DELIMITERback to summary
protected static final String DEFAULT_DELIMITER

The default delimiter.

serialVersionUIDback to summary
private static final long serialVersionUID

Hides java.text.Format.serialVersionUID.

Constructor Detail

AbstractQuantityFormatback to summary
public AbstractQuantityFormat()

Method Detail

formatback to summary
public abstract Appendable format(Quantity<?> quantity, Appendable dest) throws IOException

Redeclares javax.measure.format.QuantityFormat.format.

Formats the specified quantity into an Appendable.

Parameters
quantity:Quantity<?>

the quantity to format.

dest:Appendable

the appendable destination.

Returns:Appendable

the specified Appendable.

Exceptions
IOException:
if an I/O exception occurs.
formatback to summary
public final StringBuffer format(Object obj, final StringBuffer toAppendTo, FieldPosition pos)

Implements abstract java.text.Format.format.

Doc from java.text.Format.format.

Formats an object and appends the resulting text to a given string buffer. If the pos argument identifies a field used by the format, then its indices are set to the beginning and end of the first such field encountered.

Parameters
obj:Object

The object to format

toAppendTo:StringBuffer

where the text is to be appended

pos:FieldPosition

A FieldPosition identifying a field in the formatted text

Returns:StringBuffer

the string buffer passed in as toAppendTo, with formatted text appended

Annotations
@Override
formatback to summary
public final String format(Quantity<?> quantity)

Implements javax.measure.format.QuantityFormat.format.

Formats an object to produce a string. This is equivalent to

format(unit, new StringBuilder()).toString();
Parameters
quantity:Quantity<?>

The quantity to format

Returns:String

Formatted string.

formatback to summary
protected final StringBuffer format(ComparableQuantity<?> quantity, StringBuffer dest)

Convenience method equivalent to format(ComparableQuantity, Appendable) except it does not raise an IOException.

Parameters
quantity:ComparableQuantity<?>

the quantity to format.

dest:StringBuffer

the appendable destination.

Returns:StringBuffer

the specified StringBuilder.

formatMixedback to summary
protected abstract StringBuffer formatMixed(MixedQuantity<?> mixed, StringBuffer dest)

Convenience method equivalent to format(MixedQuantity, Appendable) except it does not raise an IOException.

Parameters
mixed:MixedQuantity<?>

the mixed quantity to format.

dest:StringBuffer

the appendable destination.

Returns:StringBuffer

the specified StringBuilder.

parseback to summary
public abstract Quantity<?> parse(CharSequence csq, ParsePosition cursor) throws IllegalArgumentException, MeasurementParseException

Redeclares javax.measure.format.QuantityFormat.parse.

Parses a portion of the specified CharSequence from the specified position to produce an object. If parsing succeeds, then the index of the cursor argument is updated to the index after the last character used.

Parameters
csq:CharSequence

the CharSequence to parse.

cursor:ParsePosition

the cursor holding the current parsing index.

Returns:Quantity<?>

the object parsed from the specified character sub-sequence.

Exceptions
IllegalArgumentException:
if any problem occurs while parsing the specified character sequence (e.g. illegal syntax).
MeasurementParseException:

Doc from javax.measure.format.QuantityFormat.parse.

if any problem occurs while parsing the specified character sequence (e.g. illegal syntax).

parseback to summary
public abstract Quantity<?> parse(CharSequence csq) throws MeasurementParseException

Redeclares javax.measure.format.QuantityFormat.parse, tech.uom.lib.common.function.Parser.parse.

Parses a portion of the specified CharSequence from the specified position to produce an object. If parsing succeeds, then the index of the cursor argument is updated to the index after the last character used.

Parameters
csq:CharSequence

the CharSequence to parse.

Returns:Quantity<?>

the object parsed from the specified character sub-sequence.

Annotations
@Override
Exceptions
MeasurementParseException:

Doc from javax.measure.format.QuantityFormat.parse.

if any problem occurs while parsing the specified character sequence (e.g. illegal syntax).

IllegalArgumentException:
if any problem occurs while parsing the specified character sequence (e.g. illegal syntax).
parseback to summary
protected abstract Quantity<?> parse(CharSequence csq, int index) throws IllegalArgumentException, MeasurementParseException

Parses a portion of the specified CharSequence from the specified position to produce an object. If parsing succeeds, then the index of the cursor argument is updated to the index after the last character used.

Parameters
csq:CharSequence

the CharSequence to parse.

index:int

the current parsing index.

Returns:Quantity<?>

the object parsed from the specified character sub-sequence.

Exceptions
IllegalArgumentException:
if any problem occurs while parsing the specified character sequence (e.g. illegal syntax).
parseObjectback to summary
public final Quantity<?> parseObject(String source, ParsePosition pos)

Implements abstract java.text.Format.parseObject.

Doc from java.text.Format.parseObject.

Parses text from the given string to produce an object.

This method attempts to parse text starting at the index given by pos. If parsing succeeds, then the index of pos is updated to the index after the last character used (parsing does not necessarily use all characters up to the end of the string), and the parsed object is returned. The updated pos can be used to indicate the starting point for the next call to this method. If an error occurs, then the index of pos is not changed, the error index of pos is set to the index of the character where the error occurred, and null is returned.

Parameters
source:String

the String to parse

pos:ParsePosition

A ParsePosition object with index and error index information as described above.

Returns:Quantity<?>

An Object parsed from the string. In case of error, returns null.

Annotations
@Override