public abstract class QuantityFormat extends java.text.Format implements tec.uom.lib.common.function.Parser<java.lang.CharSequence,ComparableQuantity>
This class provides the interface for formatting and parsing quantities
.
Instances of this class should be able to format quantities stated in CompoundUnit
. See formatCompound(...)
.
Modifier and Type | Field and Description |
---|---|
private static DefaultQuantityFormat |
DEFAULT
Holds the default format instance.
|
private static NumberSpaceQuantityFormat |
LOCAL
Holds the localized format instance.
|
private static long |
serialVersionUID |
Constructor and Description |
---|
QuantityFormat() |
Modifier and Type | Method and Description |
---|---|
java.lang.StringBuilder |
format(AbstractQuantity<?> quantity,
java.lang.StringBuilder dest)
Convenience method equivalent to
#format(AbstractQuantity, Appendable) except it does not raise an IOException. |
java.lang.StringBuffer |
format(java.lang.Object obj,
java.lang.StringBuffer toAppendTo,
java.text.FieldPosition pos) |
abstract java.lang.Appendable |
format(javax.measure.Quantity<?> quantity,
java.lang.Appendable dest)
Formats the specified quantity into an
Appendable . |
static QuantityFormat |
getInstance()
Returns the quantity format for the default locale.
|
static QuantityFormat |
getInstance(FormatBehavior style)
Returns the culture invariant format based upon
BigDecimal canonical format and the standard
unit format. |
static QuantityFormat |
getInstance(java.text.NumberFormat numberFormat,
javax.measure.format.UnitFormat unitFormat)
Returns the quantity format using the specified number format and unit format (the number and unit are separated by one space).
|
abstract ComparableQuantity<?> |
parse(java.lang.CharSequence csq)
Parses a portion of the specified
CharSequence from the specified position to produce an object. |
(package private) abstract ComparableQuantity<?> |
parse(java.lang.CharSequence csq,
int index)
Parses a portion of the specified
CharSequence from the specified position to produce an object. |
abstract ComparableQuantity<?> |
parse(java.lang.CharSequence csq,
java.text.ParsePosition cursor)
Parses a portion of the specified
CharSequence from the specified position to produce an object. |
javax.measure.Quantity<?> |
parseObject(java.lang.String source,
java.text.ParsePosition pos) |
private static final long serialVersionUID
private static final NumberSpaceQuantityFormat LOCAL
private static final DefaultQuantityFormat DEFAULT
public static QuantityFormat getInstance()
Unit
separated by whitespace(s).MeasureFormat.getInstance(NumberFormat.getInstance(), UnitFormat.getInstance())
public static QuantityFormat getInstance(java.text.NumberFormat numberFormat, javax.measure.format.UnitFormat unitFormat)
numberFormat
- the number format.unitFormat
- the unit format.public static QuantityFormat getInstance(FormatBehavior style)
BigDecimal
canonical format and the standard
unit format. This format is not locale-sensitive and can be used for unambiguous electronic communication of quantities together with
their units without loss of information. For example: "1.23456789 kg.m/s2"
returns
Quantities.getQuantity(new BigDecimal("1.23456789"), AbstractUnit.parse("kg.m/s2")));
style
- the format style to apply.public abstract java.lang.Appendable format(javax.measure.Quantity<?> quantity, java.lang.Appendable dest) throws java.io.IOException
Appendable
.quantity
- the quantity to format.dest
- the appendable destination.Appendable
.java.io.IOException
- if an I/O exception occurs.public abstract ComparableQuantity<?> parse(java.lang.CharSequence csq, java.text.ParsePosition cursor) throws java.lang.IllegalArgumentException, javax.measure.format.ParserException
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.csq
- the CharSequence
to parse.cursor
- the cursor holding the current parsing index.java.lang.IllegalArgumentException
- if any problem occurs while parsing the specified character sequence (e.g. illegal syntax).javax.measure.format.ParserException
public abstract ComparableQuantity<?> parse(java.lang.CharSequence csq) throws java.lang.IllegalArgumentException, javax.measure.format.ParserException
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.parse
in interface tec.uom.lib.common.function.Parser<java.lang.CharSequence,ComparableQuantity>
csq
- the CharSequence
to parse.cursor
- the cursor holding the current parsing index.java.lang.IllegalArgumentException
- if any problem occurs while parsing the specified character sequence (e.g. illegal syntax).javax.measure.format.ParserException
abstract ComparableQuantity<?> parse(java.lang.CharSequence csq, int index) throws java.lang.IllegalArgumentException, javax.measure.format.ParserException
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.csq
- the CharSequence
to parse.index
- the current parsing index.java.lang.IllegalArgumentException
- if any problem occurs while parsing the specified character sequence (e.g. illegal syntax).javax.measure.format.ParserException
public final java.lang.StringBuffer format(java.lang.Object obj, java.lang.StringBuffer toAppendTo, java.text.FieldPosition pos)
format
in class java.text.Format
public final javax.measure.Quantity<?> parseObject(java.lang.String source, java.text.ParsePosition pos)
parseObject
in class java.text.Format
public final java.lang.StringBuilder format(AbstractQuantity<?> quantity, java.lang.StringBuilder dest)
#format(AbstractQuantity, Appendable)
except it does not raise an IOException.quantity
- the quantity to format.dest
- the appendable destination.StringBuilder
.