Package tech.units.indriya.format
Class NumberSpaceQuantityFormat
- java.lang.Object
-
- java.text.Format
-
- tech.units.indriya.format.AbstractQuantityFormat
-
- tech.units.indriya.format.NumberSpaceQuantityFormat
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Cloneable,QuantityFormat,tech.uom.lib.common.function.Parser<java.lang.CharSequence,ComparableQuantity>
public class NumberSpaceQuantityFormat extends AbstractQuantityFormat
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private static NumberSpaceQuantityFormatDEFAULTHolds the default format instance.private static NumberSpaceQuantityFormatLOCALHolds the localized format instance.private java.text.NumberFormatnumberFormatprivate static longserialVersionUIDprivate javax.measure.format.UnitFormatunitFormat
-
Constructor Summary
Constructors Constructor Description NumberSpaceQuantityFormat(java.text.NumberFormat numberFormat, javax.measure.format.UnitFormat unitFormat)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Appendableformat(javax.measure.Quantity<?> quantity, java.lang.Appendable dest)Formats the specified quantity into anAppendable.(package private) static intgetFractionDigitsCount(double d)static NumberSpaceQuantityFormatgetInstance()Returns the default format.static NumberSpaceQuantityFormatgetInstance(java.text.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 thestandardunit format.ComparableQuantity<?>parse(java.lang.CharSequence csq)Parses a portion of the specifiedCharSequencefrom the specified position to produce an object.(package private) ComparableQuantity<?>parse(java.lang.CharSequence csq, int index)Parses a portion of the specifiedCharSequencefrom the specified position to produce an object.ComparableQuantity<?>parse(java.lang.CharSequence csq, java.text.ParsePosition cursor)Parses a portion of the specifiedCharSequencefrom the specified position to produce an object.-
Methods inherited from class tech.units.indriya.format.AbstractQuantityFormat
format, format, 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 Detail
-
DEFAULT
private static final NumberSpaceQuantityFormat DEFAULT
Holds the default format instance.
-
LOCAL
private static final NumberSpaceQuantityFormat LOCAL
Holds the localized format instance.
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
numberFormat
private final java.text.NumberFormat numberFormat
-
unitFormat
private final javax.measure.format.UnitFormat unitFormat
-
-
Method Detail
-
getFractionDigitsCount
static int getFractionDigitsCount(double d)
-
format
public java.lang.Appendable format(javax.measure.Quantity<?> quantity, java.lang.Appendable dest) throws java.io.IOExceptionDescription 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:
java.io.IOException- if an I/O exception occurs.
-
parse
public ComparableQuantity<?> parse(java.lang.CharSequence csq, java.text.ParsePosition cursor) throws java.lang.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:
java.lang.IllegalArgumentException- if any problem occurs while parsing the specified character sequence (e.g. illegal syntax).javax.measure.format.ParserException
-
parse
ComparableQuantity<?> parse(java.lang.CharSequence csq, int index) throws java.lang.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:
java.lang.IllegalArgumentException- if any problem occurs while parsing the specified character sequence (e.g. illegal syntax).javax.measure.format.ParserException
-
parse
public ComparableQuantity<?> parse(java.lang.CharSequence csq) throws java.lang.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<java.lang.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:
java.lang.IllegalArgumentException- if any problem occurs while parsing the specified character sequence (e.g. illegal syntax).javax.measure.format.ParserException
-
getInstance
public static NumberSpaceQuantityFormat getInstance(FormatBehavior style)
Returns the culture invariant format based uponBigDecimalcanonical format and thestandardunit 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"returnsQuantities.getQuantity(new BigDecimal("1.23456789"), AbstractUnit.parse("kg.m/s2")));- Parameters:
style- the format style to apply.- Returns:
- the desired format.
-
getInstance
public static NumberSpaceQuantityFormat getInstance()
Returns the default format.- Returns:
- the desired format.
-
getInstance
public static NumberSpaceQuantityFormat getInstance(java.text.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.
-
-