Class NumberSpaceQuantityFormat
java.lang.Object
java.text.Format
tech.units.indriya.format.AbstractQuantityFormat
tech.units.indriya.format.NumberSpaceQuantityFormat
- All Implemented Interfaces:
Serializable, Cloneable, QuantityFormat, tech.uom.lib.common.function.Parser<CharSequence, ComparableQuantity>
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class Format
Format.Field -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final NumberSpaceQuantityFormatHolds the default format instance.private static final NumberSpaceQuantityFormatHolds the localized format instance.private final NumberFormatprivate static final longprivate final javax.measure.format.UnitFormat -
Constructor Summary
ConstructorsConstructorDescriptionNumberSpaceQuantityFormat(NumberFormat numberFormat, javax.measure.format.UnitFormat unitFormat) -
Method Summary
Modifier and TypeMethodDescriptionformat(javax.measure.Quantity<?> quantity, Appendable dest) Formats the specified quantity into anAppendable.(package private) static intgetFractionDigitsCount(double d) static NumberSpaceQuantityFormatReturns the default format.static NumberSpaceQuantityFormatgetInstance(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).static NumberSpaceQuantityFormatgetInstance(FormatBehavior style) Returns the culture invariant format based uponBigDecimalcanonical format and theunit format.invalid reference
standardparse(CharSequence csq) Parses a portion of the specifiedCharSequencefrom the specified position to produce an object.(package private) ComparableQuantity<?> parse(CharSequence csq, int index) Parses a portion of the specifiedCharSequencefrom the specified position to produce an object.parse(CharSequence csq, ParsePosition cursor) Parses a portion of the specifiedCharSequencefrom the specified position to produce an object.Methods inherited from class AbstractQuantityFormat
format, format, parseObjectMethods inherited from class Format
clone, format, formatToCharacterIterator, parseObjectMethods inherited from class Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface QuantityFormat
isLocaleSensitive
-
Field Details
-
DEFAULT
Holds the default format instance. -
LOCAL
Holds the localized format instance. -
serialVersionUID
private static final long serialVersionUID- See Also:
-
numberFormat
-
unitFormat
private final javax.measure.format.UnitFormat unitFormat
-
-
Constructor Details
-
NumberSpaceQuantityFormat
NumberSpaceQuantityFormat(NumberFormat numberFormat, javax.measure.format.UnitFormat unitFormat)
-
-
Method Details
-
getFractionDigitsCount
static int getFractionDigitsCount(double d) -
format
Description copied from class:AbstractQuantityFormatFormats the specified quantity into anAppendable.- Specified by:
formatin interfaceQuantityFormat- Specified by:
formatin 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 IllegalArgumentException, javax.measure.format.ParserException Description copied from class:AbstractQuantityFormatParses a portion of the specifiedCharSequencefrom the specified position to produce an object. If parsing succeeds, then the index of thecursorargument is updated to the index after the last character used.- Specified by:
parsein interfaceQuantityFormat- Specified by:
parsein classAbstractQuantityFormat- Parameters:
csq- theCharSequenceto parse.cursor- the cursor holding the current parsing index.- Returns:
- the object parsed from the specified character sub-sequence.
- Throws:
IllegalArgumentException- if any problem occurs while parsing the specified character sequence (e.g. illegal syntax).javax.measure.format.ParserException
-
parse
ComparableQuantity<?> parse(CharSequence csq, int index) throws IllegalArgumentException, javax.measure.format.ParserException Description copied from class:AbstractQuantityFormatParses a portion of the specifiedCharSequencefrom the specified position to produce an object. If parsing succeeds, then the index of thecursorargument is updated to the index after the last character used.- Specified by:
parsein classAbstractQuantityFormat- Parameters:
csq- theCharSequenceto parse.index- the current parsing index.- Returns:
- the object parsed from the specified character sub-sequence.
- Throws:
IllegalArgumentException- if any problem occurs while parsing the specified character sequence (e.g. illegal syntax).javax.measure.format.ParserException
-
parse
public ComparableQuantity<?> parse(CharSequence csq) throws IllegalArgumentException, javax.measure.format.ParserException Description copied from class:AbstractQuantityFormatParses a portion of the specifiedCharSequencefrom the specified position to produce an object. If parsing succeeds, then the index of thecursorargument is updated to the index after the last character used.- Specified by:
parsein interfacetech.uom.lib.common.function.Parser<CharSequence, ComparableQuantity>- Specified by:
parsein interfaceQuantityFormat- Specified by:
parsein classAbstractQuantityFormat- Parameters:
csq- theCharSequenceto parse.- Returns:
- the object parsed from the specified character sub-sequence.
- Throws:
IllegalArgumentException- if any problem occurs while parsing the specified character sequence (e.g. illegal syntax).javax.measure.format.ParserException
-
getInstance
Returns the culture invariant format based uponBigDecimalcanonical format and theunit 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:invalid reference
standard"1.23456789 kg.m/s2"returnsQuantities.getQuantity(new BigDecimal("1.23456789"), AbstractUnit.parse("kg.m/s2")));- Parameters:
style- the format style to apply.- Returns:
- the desired format.
-
getInstance
Returns the default format.- Returns:
- the desired format.
-
getInstance
public static NumberSpaceQuantityFormat 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).- Parameters:
numberFormat- the number format.unitFormat- the unit format.- Returns:
- the corresponding format.
-