Package tech.units.indriya.format
Class SimpleQuantityFormat
java.lang.Object
java.text.Format
tech.units.indriya.format.AbstractQuantityFormat
tech.units.indriya.format.SimpleQuantityFormat
- All Implemented Interfaces:
Serializable
,Cloneable
,QuantityFormat
,tech.uom.lib.common.function.Parser<CharSequence,
ComparableQuantity>
A simple implementation of QuantityFormat
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class java.text.Format
Format.Field
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final SimpleQuantityFormat
Holds the default format instance.private static final long
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionformat
(javax.measure.Quantity quantity, Appendable dest) Formats the specified quantity into anAppendable
.static SimpleQuantityFormat
Returns the quantity format for the default locale.parse
(CharSequence csq) Parses a portion of the specifiedCharSequence
from the specified position to produce an object.(package private) AbstractQuantity
<?> parse
(CharSequence csq, int index) Parses a portion of the specifiedCharSequence
from the specified position to produce an object.parse
(CharSequence csq, ParsePosition cursor) Parses a portion of the specifiedCharSequence
from the specified position to produce an object.Methods inherited from class tech.units.indriya.format.AbstractQuantityFormat
format, format, parseObject
Methods inherited from class java.text.Format
clone, format, formatToCharacterIterator, parseObject
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface tech.units.indriya.format.QuantityFormat
isLocaleSensitive
-
Field Details
-
DEFAULT
Holds the default format instance. -
serialVersionUID
private static final long serialVersionUID- See Also:
-
-
Constructor Details
-
SimpleQuantityFormat
public SimpleQuantityFormat()
-
-
Method Details
-
format
Description copied from class:AbstractQuantityFormat
Formats the specified quantity into anAppendable
.- Specified by:
format
in interfaceQuantityFormat
- Specified by:
format
in classAbstractQuantityFormat
- Parameters:
quantity
- the quantity to format.dest
- the appendable destination.- Returns:
- the specified
Appendable
. - Throws:
IOException
- if an I/O exception occurs.
-
parse
public ComparableQuantity<?> parse(CharSequence csq, ParsePosition cursor) throws javax.measure.format.ParserException Description copied from class:AbstractQuantityFormat
Parses a portion of the specifiedCharSequence
from the specified position to produce an object. If parsing succeeds, then the index of thecursor
argument is updated to the index after the last character used.- Specified by:
parse
in interfaceQuantityFormat
- Specified by:
parse
in classAbstractQuantityFormat
- Parameters:
csq
- theCharSequence
to parse.cursor
- the cursor holding the current parsing index.- Returns:
- the object parsed from the specified character sub-sequence.
- Throws:
javax.measure.format.ParserException
-
parse
Description copied from class:AbstractQuantityFormat
Parses a portion of the specifiedCharSequence
from the specified position to produce an object. If parsing succeeds, then the index of thecursor
argument is updated to the index after the last character used.- Specified by:
parse
in classAbstractQuantityFormat
- Parameters:
csq
- theCharSequence
to parse.index
- the current parsing index.- Returns:
- the object parsed from the specified character sub-sequence.
- Throws:
javax.measure.format.ParserException
-
parse
Description copied from class:AbstractQuantityFormat
Parses a portion of the specifiedCharSequence
from the specified position to produce an object. If parsing succeeds, then the index of thecursor
argument is updated to the index after the last character used.- Specified by:
parse
in interfacetech.uom.lib.common.function.Parser<CharSequence,
ComparableQuantity> - Specified by:
parse
in interfaceQuantityFormat
- Specified by:
parse
in classAbstractQuantityFormat
- Parameters:
csq
- theCharSequence
to parse.- Returns:
- the object parsed from the specified character sub-sequence.
- Throws:
javax.measure.format.ParserException
-
getInstance
Returns the quantity format for the default locale. The default format assumes the quantity is composed of a decimal number and aUnit
separated by whitespace(s).- Returns:
MeasureFormat.getInstance(NumberFormat.getInstance(), UnitFormat.getInstance())
-