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

public Class NumberDelimiterQuantityFormat

extends AbstractQuantityFormat
Class Inheritance
Annotations
@SuppressWarnings:rawtypes, unchecked
Static Imports
tech.units.indriya.format.FormatBehavior.LOCALE_NEUTRAL, .CommonFormatter.parseMixedAsLeading, .CommonFormatter.parseMixedAsPrimary

An implementation of QuantityFormat combining NumberFormat and UnitFormat separated by a delimiter.
Authors
Werner Keil, Thodoris Bais
Since
2.0
Version
2.9, $Date: 2024-10-12 $

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
NumberDelimiterQuantityFormat.Builder

A fluent Builder to easily create new instances of NumberDelimiterQuantityFormat.

Field Summary

Modifier and TypeField and Description
private String
private static final NumberDelimiterQuantityFormat
LOCAL_INSTANCE

Holds the localized format instance.

private boolean
private String
private transient NumberFormat
private transient Unit<Q extends Quantity<Q>>
private static final long
private static final NumberDelimiterQuantityFormat
SIMPLE_INSTANCE

Holds the default format instance (SimpleUnitFormat).

private transient UnitFormat
Inherited from tech.units.indriya.format.AbstractQuantityFormat:
DEFAULT_DELIMITER

Constructor Summary

AccessConstructor and Description
private
NumberDelimiterQuantityFormat()

private constructor

Method Summary

Modifier and TypeMethod and Description
public static final NumberDelimiterQuantityFormat.Builder

Returns:

a new Builder.
builder
()

Returns a new instance of Builder.

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.
comp
,
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.

private static int
public static NumberDelimiterQuantityFormat

Returns:

NumberDelimiterQuantityFormat.getInstance(NumberFormat.getInstance(), UnitFormat.getInstance())
getInstance
(final FormatBehavior
the format behavior to apply.
behavior
)

Returns an instance of NumberDelimiterQuantityFormat with a particular FormatBehavior, either locale-sensitive or locale-neutral.

public static NumberDelimiterQuantityFormat

Returns:

NumberDelimiterQuantityFormat.getInstance(NumberFormat.getInstance(), UnitFormat.getInstance())
getInstance
(final FormatBehavior
the format behavior to apply.
behavior
,
int
the number format style to apply.
numberStyle
)

Returns an instance of NumberDelimiterQuantityFormat with a particular FormatBehavior, either locale-sensitive or locale-neutral, and a desired number style.

public static NumberDelimiterQuantityFormat

Returns:

the desired format.
getInstance
()

Returns the default format.

public static NumberDelimiterQuantityFormat

Returns:

the corresponding format.
getInstance
(NumberFormat
the number format.
numberFormat
,
UnitFormat
the unit format.
unitFormat
)

Returns the quantity format using the specified number format and unit format (the number and unit are separated by one space).

public boolean
isLocaleSensitive()

Overrides default javax.measure.format.QuantityFormat.isLocaleSensitive.

Returns true if this QuantityFormat depends on a Locale to perform its tasks.

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 MixedQuantity<?>
protected MixedQuantity<?>
parseMixed(CharSequence csq, int index)

public MixedQuantity<?>
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

delimiterback to summary
private String delimiter
LOCAL_INSTANCEback to summary
private static final NumberDelimiterQuantityFormat LOCAL_INSTANCE

Holds the localized format instance.

localeSensitiveback to summary
private boolean localeSensitive
mixDelimiterback to summary
private String mixDelimiter
numberFormatback to summary
private transient NumberFormat numberFormat
primaryUnitback to summary
private transient Unit<Q extends Quantity<Q>> primaryUnit
serialVersionUIDback to summary
private static final long serialVersionUID

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

SIMPLE_INSTANCEback to summary
private static final NumberDelimiterQuantityFormat SIMPLE_INSTANCE

Holds the default format instance (SimpleUnitFormat).

unitFormatback to summary
private transient UnitFormat unitFormat

Constructor Detail

NumberDelimiterQuantityFormatback to summary
private NumberDelimiterQuantityFormat()

private constructor

Method Detail

builderback to summary
public static final NumberDelimiterQuantityFormat.Builder builder()

Returns a new instance of Builder.

Returns:NumberDelimiterQuantityFormat.Builder

a new Builder.

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<?> comp, 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
comp:MixedQuantity<?>

the mixed quantity to format.

dest:StringBuffer

the appendable destination.

Returns:StringBuffer

the specified StringBuilder.

Annotations
@Override
getFractionDigitsCountback to summary
private static int getFractionDigitsCount(double d)
getInstanceback to summary
public static NumberDelimiterQuantityFormat getInstance(final FormatBehavior behavior)

Returns an instance of NumberDelimiterQuantityFormat with a particular FormatBehavior, either locale-sensitive or locale-neutral. For example: NumberDelimiterQuantityFormat.getInstance(LOCALE_NEUTRAL)) returns
new NumberDelimiterQuantityFormat.Builder() .setNumberFormat(NumberFormat.getInstance(Locale.ROOT)).setUnitFormat(SimpleUnitFormat.getInstance()).build();

Parameters
behavior:FormatBehavior

the format behavior to apply.

Returns:NumberDelimiterQuantityFormat

NumberDelimiterQuantityFormat.getInstance(NumberFormat.getInstance(), UnitFormat.getInstance())

getInstanceback to summary
public static NumberDelimiterQuantityFormat getInstance(final FormatBehavior behavior, int numberStyle)

Returns an instance of NumberDelimiterQuantityFormat with a particular FormatBehavior, either locale-sensitive or locale-neutral, and a desired number style.
For example: NumberDelimiterQuantityFormat.getInstance(LOCALE_NEUTRAL)) returns
new NumberDelimiterQuantityFormat.Builder().setNumberFormat(NumberFormat.getInstance(Locale.ROOT)).setUnitFormat(SimpleUnitFormat.getInstance()).build();

Implementation Note

Note: numberStyle will be ignored before Java 17. Although the COMPACT NumberFormat is already available from Java 12, Indriya supports major LTS versions like 8, 11 or 17.

Parameters
behavior:FormatBehavior

the format behavior to apply.

numberStyle:int

the number format style to apply.

Returns:NumberDelimiterQuantityFormat

NumberDelimiterQuantityFormat.getInstance(NumberFormat.getInstance(), UnitFormat.getInstance())

Since
2.9
getInstanceback to summary
public static NumberDelimiterQuantityFormat getInstance()

Returns the default format.

Returns:NumberDelimiterQuantityFormat

the desired format.

getInstanceback to summary
public static NumberDelimiterQuantityFormat getInstance(NumberFormat numberFormat, UnitFormat unitFormat)

Returns the quantity format using the specified number format and unit format (the number and unit are separated by one space).

Parameters
numberFormat:NumberFormat

the number format.

unitFormat:UnitFormat

the unit format.

Returns:NumberDelimiterQuantityFormat

the corresponding format.

isLocaleSensitiveback to summary
public boolean isLocaleSensitive()

Overrides default javax.measure.format.QuantityFormat.isLocaleSensitive.

Doc from javax.measure.format.QuantityFormat.isLocaleSensitive.

Returns true if this QuantityFormat depends on a Locale to perform its tasks.

In environments that do not support a Locale, e.g. Java ME, this usually returns false.

Returns:boolean

whether this format depends on the locale.

Annotations
@Override
parseback to summary
public Quantity<?> parse(CharSequence csq, ParsePosition cursor) throws IllegalArgumentException, 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
@Override
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
protected Quantity<?> parse(CharSequence csq, int index) throws IllegalArgumentException, 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
Exceptions
IllegalArgumentException:
if any problem occurs while parsing the specified character sequence (e.g. illegal syntax).
parseback to summary
public Quantity<?> parse(CharSequence csq) throws IllegalArgumentException, 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
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).

parseMixedback to summary
public MixedQuantity<?> parseMixed(CharSequence csq, ParsePosition cursor) throws IllegalArgumentException, MeasurementParseException
parseMixedback to summary
protected MixedQuantity<?> parseMixed(CharSequence csq, int index) throws IllegalArgumentException, MeasurementParseException
parseMixedback to summary
public MixedQuantity<?> parseMixed(CharSequence csq) throws IllegalArgumentException, MeasurementParseException
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
tech.units.indriya.format back to summary

public Class NumberDelimiterQuantityFormat.Builder

extends Object
Class Inheritance
  • java.lang.Object
  • tech.units.indriya.format.NumberDelimiterQuantityFormat.Builder

A fluent Builder to easily create new instances of NumberDelimiterQuantityFormat.

Field Summary

Modifier and TypeField and Description
private transient String
private boolean
private transient String
private transient NumberFormat
private transient Unit<Q extends Quantity<Q>>
private transient UnitFormat

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public NumberDelimiterQuantityFormat
public NumberDelimiterQuantityFormat.Builder

Returns:

this NumberDelimiterQuantityFormat.Builder
setDelimiter
(String
the delimiter to use
delimiter
)

Sets the delimiter between a NumberFormat and UnitFormat.

public NumberDelimiterQuantityFormat.Builder

Returns:

this NumberDelimiterQuantityFormat.Builder
setLocaleSensitive
(boolean
the flag, if the NumberDelimiterQuantityFormat to be built will depend on a Locale to perform its tasks.
localeSensitive
)

Sets the localeSensitive flag.

public NumberDelimiterQuantityFormat.Builder

Returns:

this NumberDelimiterQuantityFormat.Builder
setNumberFormat
(NumberFormat numberFormat)

Sets the numberFormat parameter to the given NumberFormat.

public NumberDelimiterQuantityFormat.Builder

Returns:

this NumberDelimiterQuantityFormat.Builder
setPrimaryUnit
(final Unit<Q extends Quantity<Q>>
the primary Unit
primary
)

Sets the primary unit parameter for multiple mixed quantities to the given Unit.

public NumberDelimiterQuantityFormat.Builder

Returns:

this NumberDelimiterQuantityFormat.Builder
setRadixPartsDelimiter
(String
the delimiter to use
radixPartsDelimiter
)

Sets the radix delimiter between multiple mixed quantities.

public NumberDelimiterQuantityFormat.Builder

Returns:

this NumberDelimiterQuantityFormat.Builder
setUnitFormat
(UnitFormat unitFormat)

Sets the unitFormat parameter to the given UnitFormat.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

delimiterback to summary
private transient String delimiter
localeSensitiveback to summary
private boolean localeSensitive
mixedRadixDelimiterback to summary
private transient String mixedRadixDelimiter
numberFormatback to summary
private transient NumberFormat numberFormat
primaryUnitback to summary
private transient Unit<Q extends Quantity<Q>> primaryUnit
unitFormatback to summary
private transient UnitFormat unitFormat

Constructor Detail

Builderback to summary
public Builder()

Method Detail

buildback to summary
public NumberDelimiterQuantityFormat build()
setDelimiterback to summary
public NumberDelimiterQuantityFormat.Builder setDelimiter(String delimiter)

Sets the delimiter between a NumberFormat and UnitFormat.

Parameters
delimiter:String

the delimiter to use

Returns:NumberDelimiterQuantityFormat.Builder

this NumberDelimiterQuantityFormat.Builder

Exceptions
NullPointerException:
if delimiter is null
setLocaleSensitiveback to summary
public NumberDelimiterQuantityFormat.Builder setLocaleSensitive(boolean localeSensitive)

Sets the localeSensitive flag.

Parameters
localeSensitive:boolean

the flag, if the NumberDelimiterQuantityFormat to be built will depend on a Locale to perform its tasks.

Returns:NumberDelimiterQuantityFormat.Builder

this NumberDelimiterQuantityFormat.Builder

See Also
UnitFormat#isLocaleSensitive()
setNumberFormatback to summary
public NumberDelimiterQuantityFormat.Builder setNumberFormat(NumberFormat numberFormat)

Sets the numberFormat parameter to the given NumberFormat.

Parameters
numberFormat:NumberFormat

the NumberFormat

Returns:NumberDelimiterQuantityFormat.Builder

this NumberDelimiterQuantityFormat.Builder

Exceptions
NullPointerException:
if numberFormat is null
setPrimaryUnitback to summary
public NumberDelimiterQuantityFormat.Builder setPrimaryUnit(final Unit<Q extends Quantity<Q>> primary)

Sets the primary unit parameter for multiple mixed quantities to the given Unit.

Parameters
primary:Unit<Q extends Quantity<Q>>

the primary Unit

Returns:NumberDelimiterQuantityFormat.Builder

this NumberDelimiterQuantityFormat.Builder

Exceptions
NullPointerException:
if primary is null
setRadixPartsDelimiterback to summary
public NumberDelimiterQuantityFormat.Builder setRadixPartsDelimiter(String radixPartsDelimiter)

Sets the radix delimiter between multiple mixed quantities.

Parameters
radixPartsDelimiter:String

the delimiter to use

Returns:NumberDelimiterQuantityFormat.Builder

this NumberDelimiterQuantityFormat.Builder

Exceptions
NullPointerException:
if radixPartsDelimiter is null
setUnitFormatback to summary
public NumberDelimiterQuantityFormat.Builder setUnitFormat(UnitFormat unitFormat)

Sets the unitFormat parameter to the given UnitFormat.

Parameters
unitFormat:UnitFormat

the UnitFormat

Returns:NumberDelimiterQuantityFormat.Builder

this NumberDelimiterQuantityFormat.Builder

Exceptions
NullPointerException:
if unitFormat is null