Package tech.units.indriya.format
Class NumberDelimiterQuantityFormat
- java.lang.Object
-
- java.text.Format
-
- tech.units.indriya.format.AbstractQuantityFormat
-
- tech.units.indriya.format.NumberDelimiterQuantityFormat
-
- All Implemented Interfaces:
Serializable,Cloneable,QuantityFormat,tech.uom.lib.common.function.Parser<CharSequence,Quantity>
public class NumberDelimiterQuantityFormat extends AbstractQuantityFormat
- Since:
- 2.0
- Version:
- 2.9, $Date: 2024-10-12 $
- Author:
- Werner Keil, Thodoris Bais
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classNumberDelimiterQuantityFormat.BuilderA fluent Builder to easily create new instances ofNumberDelimiterQuantityFormat.-
Nested classes/interfaces inherited from class java.text.Format
Format.Field
-
-
Field Summary
-
Fields inherited from class tech.units.indriya.format.AbstractQuantityFormat
DEFAULT_DELIMITER
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static NumberDelimiterQuantityFormat.Builderbuilder()Returns a new instance ofNumberDelimiterQuantityFormat.Builder.Appendableformat(Quantity<?> quantity, Appendable dest)Formats the specified quantity into anAppendable.protected StringBufferformatMixed(MixedQuantity<?> comp, StringBuffer dest)Convenience method equivalent to#format(MixedQuantity, Appendable)except it does not raise an IOException.static NumberDelimiterQuantityFormatgetInstance()Returns the default format.static NumberDelimiterQuantityFormatgetInstance(NumberFormat numberFormat, UnitFormat unitFormat)Returns the quantity format using the specified number format and unit format (the number and unit are separated by one space).static NumberDelimiterQuantityFormatgetInstance(FormatBehavior behavior)Returns an instance ofNumberDelimiterQuantityFormatwith a particularFormatBehavior, either locale-sensitive or locale-neutral.static NumberDelimiterQuantityFormatgetInstance(FormatBehavior behavior, int numberStyle)Returns an instance ofNumberDelimiterQuantityFormatwith a particularFormatBehavior, either locale-sensitive or locale-neutral, and a desired number style.
For example:NumberDelimiterQuantityFormat.getInstance(LOCALE_NEUTRAL))returns
new NumberDelimiterQuantityFormat.Builder().setNumberFormat(NumberFormat.getInstance(Locale.ROOT)).setUnitFormat(SimpleUnitFormat.getInstance()).build();booleanisLocaleSensitive()Quantity<?>parse(CharSequence csq)Parses a portion of the specifiedCharSequencefrom the specified position to produce an object.protected Quantity<?>parse(CharSequence csq, int index)Parses a portion of the specifiedCharSequencefrom the specified position to produce an object.Quantity<?>parse(CharSequence csq, ParsePosition cursor)Parses a portion of the specifiedCharSequencefrom the specified position to produce an object.MixedQuantity<?>parseMixed(CharSequence csq)protected MixedQuantity<?>parseMixed(CharSequence csq, int index)MixedQuantity<?>parseMixed(CharSequence csq, ParsePosition cursor)StringtoString()-
Methods inherited from class tech.units.indriya.format.AbstractQuantityFormat
format, format, format, parseObject
-
Methods inherited from class java.text.Format
clone, format, formatToCharacterIterator, parseObject
-
-
-
-
Method Detail
-
getInstance
public static NumberDelimiterQuantityFormat getInstance(FormatBehavior behavior)
Returns an instance ofNumberDelimiterQuantityFormatwith a particularFormatBehavior, either locale-sensitive or locale-neutral. For example:NumberDelimiterQuantityFormat.getInstance(LOCALE_NEUTRAL))returns
new NumberDelimiterQuantityFormat.Builder() .setNumberFormat(NumberFormat.getInstance(Locale.ROOT)).setUnitFormat(SimpleUnitFormat.getInstance()).build();- Parameters:
behavior- the format behavior to apply.- Returns:
NumberDelimiterQuantityFormat.getInstance(NumberFormat.getInstance(), UnitFormat.getInstance())
-
getInstance
public static NumberDelimiterQuantityFormat getInstance(FormatBehavior behavior, int numberStyle)
Returns an instance ofNumberDelimiterQuantityFormatwith a particularFormatBehavior, either locale-sensitive or locale-neutral, and a desired number style.
For example:NumberDelimiterQuantityFormat.getInstance(LOCALE_NEUTRAL))returns
new NumberDelimiterQuantityFormat.Builder().setNumberFormat(NumberFormat.getInstance(Locale.ROOT)).setUnitFormat(SimpleUnitFormat.getInstance()).build();- Parameters:
behavior- the format behavior to apply.numberStyle- the number format style to apply.- Returns:
NumberDelimiterQuantityFormat.getInstance(NumberFormat.getInstance(), UnitFormat.getInstance())- Since:
- 2.9
-
builder
public static final NumberDelimiterQuantityFormat.Builder builder()
Returns a new instance ofNumberDelimiterQuantityFormat.Builder.- Returns:
- a new
NumberDelimiterQuantityFormat.Builder.
-
getInstance
public static NumberDelimiterQuantityFormat getInstance()
Returns the default format.- Returns:
- the desired format.
-
getInstance
public static NumberDelimiterQuantityFormat getInstance(NumberFormat numberFormat, 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.
-
format
public Appendable format(Quantity<?> quantity, Appendable dest) throws IOException
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 Quantity<?> parse(CharSequence csq, ParsePosition cursor) throws IllegalArgumentException, MeasurementParseException
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).MeasurementParseException
-
parse
protected Quantity<?> parse(CharSequence csq, int index) throws IllegalArgumentException, MeasurementParseException
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).MeasurementParseException
-
parse
public Quantity<?> parse(CharSequence csq) throws IllegalArgumentException, MeasurementParseException
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,Quantity>- 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).MeasurementParseException
-
isLocaleSensitive
public boolean isLocaleSensitive()
-
formatMixed
protected StringBuffer formatMixed(MixedQuantity<?> comp, StringBuffer dest)
Description copied from class:AbstractQuantityFormatConvenience method equivalent to#format(MixedQuantity, Appendable)except it does not raise an IOException.- Specified by:
formatMixedin classAbstractQuantityFormat- Parameters:
comp- the mixed quantity to format.dest- the appendable destination.- Returns:
- the specified
StringBuilder.
-
parseMixed
public MixedQuantity<?> parseMixed(CharSequence csq, ParsePosition cursor) throws IllegalArgumentException, MeasurementParseException
-
parseMixed
protected MixedQuantity<?> parseMixed(CharSequence csq, int index) throws IllegalArgumentException, MeasurementParseException
-
parseMixed
public MixedQuantity<?> parseMixed(CharSequence csq) throws IllegalArgumentException, MeasurementParseException
-
-