Serializable
, Cloneable
public class SimpleQuantityFormat extends AbstractQuantityFormat
The following pattern letters are defined:
Pattern letters are usually repeated, as their number determines the exact presentation:
Letter Quantity Component Presentation Examples n
Numeric value Number 27
u
Unit Text m
~
Mixed radix Text 1 m
; 27cm
"~"
is followed by a character sequence acting as mixed radix delimiter. This character sequence must not contain "~"
itself or any numeric values.Format.Field
DEFAULT_DELIMITER
Modifier | Constructor | Description |
---|---|---|
protected |
SimpleQuantityFormat() |
Constructs a
SimpleQuantityFormat using the default pattern. |
|
SimpleQuantityFormat(String pattern) |
Constructs a
SimpleQuantityFormat using the given pattern. |
Modifier and Type | Method | Description |
---|---|---|
Appendable |
format(javax.measure.Quantity<?> quantity,
Appendable dest) |
Formats the specified quantity into an
Appendable . |
protected StringBuffer |
formatCompound(CompoundQuantity<?> comp,
StringBuffer dest) |
Convenience method equivalent to
#format(CompoundQuantity, Appendable) except it does not raise an IOException. |
static SimpleQuantityFormat |
getInstance() |
Returns the quantity format for the default locale.
|
static SimpleQuantityFormat |
getInstance(String pattern) |
Returns a
SimpleQuantityFormat using the given pattern. |
String |
getPattern() |
|
javax.measure.Quantity<?> |
parse(CharSequence csq) |
Parses a portion of the specified
CharSequence from the specified position to produce an object. |
protected javax.measure.Quantity<?> |
parse(CharSequence csq,
int index) |
Parses a portion of the specified
CharSequence from the specified position to produce an object. |
javax.measure.Quantity<?> |
parse(CharSequence csq,
ParsePosition cursor) |
Parses a portion of the specified
CharSequence from the specified position to produce an object. |
String |
toString() |
format, format, format, parseObject
clone, format, formatToCharacterIterator, parseObject
public SimpleQuantityFormat(String pattern)
SimpleQuantityFormat
using the given pattern.
pattern
- the pattern describing the quantity and unit formatNullPointerException
- if the given pattern is nullIllegalArgumentException
- if the given pattern is invalidprotected SimpleQuantityFormat()
SimpleQuantityFormat
using the default pattern. For
full coverage, use the factory methods.public Appendable format(javax.measure.Quantity<?> quantity, Appendable dest) throws IOException
AbstractQuantityFormat
Appendable
.format
in class AbstractQuantityFormat
quantity
- the quantity to format.dest
- the appendable destination.Appendable
.IOException
- if an I/O exception occurs.public javax.measure.Quantity<?> parse(CharSequence csq, ParsePosition cursor) throws javax.measure.format.MeasurementParseException
AbstractQuantityFormat
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 class AbstractQuantityFormat
csq
- the CharSequence
to parse.cursor
- the cursor holding the current parsing index.javax.measure.format.MeasurementParseException
protected javax.measure.Quantity<?> parse(CharSequence csq, int index) throws javax.measure.format.MeasurementParseException
AbstractQuantityFormat
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 class AbstractQuantityFormat
csq
- the CharSequence
to parse.index
- the current parsing index.javax.measure.format.MeasurementParseException
public javax.measure.Quantity<?> parse(CharSequence csq) throws javax.measure.format.MeasurementParseException
AbstractQuantityFormat
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 class AbstractQuantityFormat
csq
- the CharSequence
to parse.javax.measure.format.MeasurementParseException
public static SimpleQuantityFormat getInstance()
Unit
separated by whitespace(s).SimpleQuantityFormat
instance.public static SimpleQuantityFormat getInstance(String pattern)
SimpleQuantityFormat
using the given pattern.
pattern
- the pattern describing the quantity and unit formatSimpleQuantityFormat.getInstance(a pattern)
public String getPattern()
protected StringBuffer formatCompound(CompoundQuantity<?> comp, StringBuffer dest)
AbstractQuantityFormat
#format(CompoundQuantity, Appendable)
except it does not raise an IOException.formatCompound
in class AbstractQuantityFormat
comp
- the composite quantity to format.dest
- the appendable destination.StringBuilder
.Copyright © 2005–2020 Units of Measurement project. All rights reserved.