public abstract class QuantityFormat extends Format implements tec.uom.lib.common.function.Parser<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(...)
.
Format.Field
Constructor and Description |
---|
QuantityFormat() |
Modifier and Type | Method and Description |
---|---|
StringBuilder |
format(AbstractQuantity<?> quantity,
StringBuilder dest)
Convenience method equivalent to
#format(AbstractQuantity, Appendable) except it does not raise an IOException. |
StringBuffer |
format(Object obj,
StringBuffer toAppendTo,
FieldPosition pos) |
abstract Appendable |
format(javax.measure.Quantity<?> quantity,
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(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(CharSequence csq)
Parses a portion of the specified
CharSequence from the specified position to produce an object. |
abstract ComparableQuantity<?> |
parse(CharSequence csq,
ParsePosition cursor)
Parses a portion of the specified
CharSequence from the specified position to produce an object. |
javax.measure.Quantity<?> |
parseObject(String source,
ParsePosition pos) |
clone, format, formatToCharacterIterator, parseObject
public QuantityFormat()
public static QuantityFormat getInstance()
Unit
separated by whitespace(s).MeasureFormat.getInstance(NumberFormat.getInstance(), UnitFormat.getInstance())
public static QuantityFormat getInstance(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 Appendable format(javax.measure.Quantity<?> quantity, Appendable dest) throws IOException
Appendable
.quantity
- the quantity to format.dest
- the appendable destination.Appendable
.IOException
- if an I/O exception occurs.public abstract ComparableQuantity<?> parse(CharSequence csq, ParsePosition cursor) throws 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.IllegalArgumentException
- if any problem occurs while parsing the specified character sequence (e.g. illegal syntax).javax.measure.format.ParserException
public abstract ComparableQuantity<?> parse(CharSequence csq) throws 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<CharSequence,ComparableQuantity>
csq
- the CharSequence
to parse.cursor
- the cursor holding the current parsing index.IllegalArgumentException
- if any problem occurs while parsing the specified character sequence (e.g. illegal syntax).javax.measure.format.ParserException
public final StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos)
public final javax.measure.Quantity<?> parseObject(String source, ParsePosition pos)
parseObject
in class Format
public final StringBuilder format(AbstractQuantity<?> quantity, StringBuilder dest)
#format(AbstractQuantity, Appendable)
except it does not raise an IOException.quantity
- the quantity to format.dest
- the appendable destination.StringBuilder
.Copyright © 2005-2018 Units of Measurement project. All Rights Reserved.