Package org.apache.sis.measure
Class QuantityFormat
java.lang.Object
java.text.Format
org.apache.sis.measure.QuantityFormat
- All Implemented Interfaces:
Serializable
,Cloneable
Parses and formats numbers with units of measurement.
- Since:
- 1.1
- Version:
- 1.1
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class java.text.Format
Format.Field
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final NumberFormat
The format for parsing and formatting the number part.static final char
The default separator used between numerical value and its unit of measurement.private static final long
For cross-version compatibility.protected final UnitFormat
The format for parsing and formatting the unit of measurement part. -
Constructor Summary
ConstructorsConstructorDescriptionQuantityFormat
(NumberFormat numberFormat, UnitFormat unitFormat) Creates a new instance using the given number and unit formats.QuantityFormat
(Locale locale) Creates a new instance for the given locale. -
Method Summary
Modifier and TypeMethodDescriptionclone()
Returns a clone of this format.format
(Object quantity, StringBuffer toAppendTo, FieldPosition pos) Formats the specified quantity in the given buffer.parseObject
(String source, ParsePosition pos) Parses text from a string to produce a quantity, or returnsnull
if the parsing failed.Methods inherited from class java.text.Format
format, formatToCharacterIterator, parseObject
-
Field Details
-
serialVersionUID
private static final long serialVersionUIDFor cross-version compatibility.- See Also:
-
SEPARATOR
public static final char SEPARATORThe default separator used between numerical value and its unit of measurement. Current value is narrow no-break space (U+202F).- See Also:
-
numberFormat
The format for parsing and formatting the number part. -
unitFormat
The format for parsing and formatting the unit of measurement part.
-
-
Constructor Details
-
QuantityFormat
Creates a new instance for the given locale.- Parameters:
locale
- the locale for the quantity format.
-
QuantityFormat
Creates a new instance using the given number and unit formats.- Parameters:
numberFormat
- the format for parsing and formatting the number part.unitFormat
- the format for parsing and formatting the unit of measurement part.
-
-
Method Details
-
format
Formats the specified quantity in the given buffer. The given object shall be aQuantity
instance. -
parseObject
Parses text from a string to produce a quantity, or returnsnull
if the parsing failed.- Specified by:
parseObject
in classFormat
- Parameters:
source
- the text, part of which should be parsed.pos
- index and error index information.- Returns:
- a quantity parsed from the string, or
null
in case of error.
-
clone
Returns a clone of this format.
-