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

public Class SimpleQuantityFormat

extends AbstractQuantityFormat
Class Inheritance
Annotations
@SuppressWarnings:rawtypes
Static Imports
tech.units.indriya.format.CommonFormatter.parseMixedAsLeading

A simple implementation of QuantityFormat
The following pattern letters are defined:
Chart shows pattern letters, date/time component, presentation, and examples.
Letter Quantity Component Presentation Examples
n Numeric value Number 27
u Unit Text m
~ Mixed radix Text 1 m; 27 cm
Pattern letters are usually repeated, as their number determines the exact presentation:
Since
2.0
Version
2.2, Jan 7, 2024

Field Summary

Modifier and TypeField and Description
private static final SimpleQuantityFormat
DEFAULT

Holds the default format instance.

private String
private String
private static final String
private final String
pattern

The pattern string of this formatter.

private static final String
private static final long
private static final String
Inherited from tech.units.indriya.format.AbstractQuantityFormat:
DEFAULT_DELIMITER

Constructor Summary

AccessConstructor and Description
public
SimpleQuantityFormat(String
the pattern describing the quantity and unit format
pattern
)

Constructs a SimpleQuantityFormat using the given pattern.

protected
SimpleQuantityFormat()

Constructs a SimpleQuantityFormat using the default pattern.

Method Summary

Modifier and TypeMethod and Description
public Appendable
format(Quantity<?>
the quantity to format.
quantity
,
Appendable
the appendable destination.
dest
)

Implements abstract tech.units.indriya.format.AbstractQuantityFormat.format.

Implements javax.measure.format.QuantityFormat.format.

Formats the specified quantity into an Appendable.

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

Implements abstract tech.units.indriya.format.AbstractQuantityFormat.formatMixed.

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

public static SimpleQuantityFormat

Returns:

a default SimpleQuantityFormat instance.
getInstance
()

Returns the quantity format for the default locale.

public static SimpleQuantityFormat

Returns:

SimpleQuantityFormat.getInstance(a pattern)
getInstance
(String
the pattern describing the quantity and unit format
pattern
)

Returns a SimpleQuantityFormat using the given pattern.

public String

Returns:

a pattern
getPattern
()

Returns the pattern of this format.

public Quantity<?>
parse(CharSequence
the CharSequence to parse.
csq
,
ParsePosition
the cursor holding the current parsing index.
cursor
)

Implements abstract tech.units.indriya.format.AbstractQuantityFormat.parse.

Implements javax.measure.format.QuantityFormat.parse.

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

protected Quantity<?>
parse(CharSequence
the CharSequence to parse.
csq
,
int
the current parsing index.
index
)

Implements abstract tech.units.indriya.format.AbstractQuantityFormat.parse.

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

public Quantity<?>
parse(CharSequence
the CharSequence to parse.
csq
)

Implements abstract tech.units.indriya.format.AbstractQuantityFormat.parse.

Implements 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.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from tech.units.indriya.format.AbstractQuantityFormat:
formatformatformatparseObject

Field Detail

DEFAULTback to summary
private static final SimpleQuantityFormat DEFAULT

Holds the default format instance.

delimiterback to summary
private String delimiter
mixDelimiterback to summary
private String mixDelimiter
NUM_PARTback to summary
private static final String NUM_PART
patternback to summary
private final String pattern

The pattern string of this formatter. This is always a non-localized pattern. May not be null. See class documentation for details.

RADIXback to summary
private static final String RADIX
serialVersionUIDback to summary
private static final long serialVersionUID

Hides tech.units.indriya.format.AbstractQuantityFormat.serialVersionUID.

UNIT_PARTback to summary
private static final String UNIT_PART

Constructor Detail

SimpleQuantityFormatback to summary
public SimpleQuantityFormat(String pattern)

Constructs a SimpleQuantityFormat using the given pattern.

Parameters
pattern:String

the pattern describing the quantity and unit format

Exceptions
NullPointerException:
if the given pattern is null
IllegalArgumentException:
if the given pattern is invalid
SimpleQuantityFormatback to summary
protected SimpleQuantityFormat()

Constructs a SimpleQuantityFormat using the default pattern. For full coverage, use the factory methods.

Method Detail

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

Implements abstract tech.units.indriya.format.AbstractQuantityFormat.format.

Implements javax.measure.format.QuantityFormat.format.

Doc from tech.units.indriya.format.AbstractQuantityFormat.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.

Annotations
@Override
Exceptions
IOException:
if an I/O exception occurs.
formatMixedback to summary
protected StringBuffer formatMixed(MixedQuantity<?> mixed, StringBuffer dest)

Implements abstract tech.units.indriya.format.AbstractQuantityFormat.formatMixed.

Doc from tech.units.indriya.format.AbstractQuantityFormat.formatMixed.

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.

Annotations
@Override
getInstanceback to summary
public static SimpleQuantityFormat getInstance()

Returns the quantity format for the default locale. The default format assumes the quantity is composed of a decimal number and a Unit separated by whitespace(s).

Returns:SimpleQuantityFormat

a default SimpleQuantityFormat instance.

getInstanceback to summary
public static SimpleQuantityFormat getInstance(String pattern)

Returns a SimpleQuantityFormat using the given pattern.

Parameters
pattern:String

the pattern describing the quantity and unit format

Returns:SimpleQuantityFormat

SimpleQuantityFormat.getInstance(a pattern)

getPatternback to summary
public String getPattern()

Returns the pattern of this format.

Returns:String

a pattern

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

Implements abstract tech.units.indriya.format.AbstractQuantityFormat.parse.

Implements javax.measure.format.QuantityFormat.parse.

Doc from tech.units.indriya.format.AbstractQuantityFormat.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.

Annotations
@SuppressWarnings:unchecked
@Override
Exceptions
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
protected Quantity<?> parse(CharSequence csq, int index) throws MeasurementParseException

Implements abstract tech.units.indriya.format.AbstractQuantityFormat.parse.

Doc from tech.units.indriya.format.AbstractQuantityFormat.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.

index:int

the current parsing index.

Returns:Quantity<?>

the object parsed from the specified character sub-sequence.

Annotations
@Override
parseback to summary
public Quantity<?> parse(CharSequence csq) throws MeasurementParseException

Implements abstract tech.units.indriya.format.AbstractQuantityFormat.parse.

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

Doc from tech.units.indriya.format.AbstractQuantityFormat.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).

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override