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,javax.measure.format.QuantityFormat,tech.uom.lib.common.function.Parser<CharSequence,javax.measure.Quantity>
public class NumberDelimiterQuantityFormat extends AbstractQuantityFormat
- Since:
- 2.0
- Version:
- 2.1.2, $Date: 2020-04-26 $
- 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
Modifier and Type Method Description static NumberDelimiterQuantityFormat.Builderbuilder()Returns a new instance ofNumberDelimiterQuantityFormat.Builder.Appendableformat(javax.measure.Quantity<?> quantity, Appendable dest)Formats the specified quantity into anAppendable.protected StringBufferformatCompound(CompoundQuantity<?> comp, StringBuffer dest)Convenience method equivalent to#format(CompoundQuantity, Appendable)except it does not raise an IOException.static NumberDelimiterQuantityFormatgetInstance()Returns the default format.static NumberDelimiterQuantityFormatgetInstance(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 NumberDelimiterQuantityFormatgetInstance(FormatBehavior behavior)Returns an instance ofNumberDelimiterQuantityFormatwith a particularFormatBehavior, either locale-sensitive or locale-neutral.booleanisLocaleSensitive()javax.measure.Quantity<?>parse(CharSequence csq)Parses a portion of the specifiedCharSequencefrom the specified position to produce an object.protected javax.measure.Quantity<?>parse(CharSequence csq, int index)Parses a portion of the specifiedCharSequencefrom the specified position to produce an object.javax.measure.Quantity<?>parse(CharSequence csq, ParsePosition cursor)Parses a portion of the specifiedCharSequencefrom the specified position to produce an object.CompoundQuantity<?>parseCompound(CharSequence csq)protected CompoundQuantity<?>parseCompound(CharSequence csq, int index)CompoundQuantity<?>parseCompound(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())
-
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, 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.
-
format
public Appendable format(javax.measure.Quantity<?> quantity, Appendable dest) throws IOException
Description copied from class:AbstractQuantityFormatFormats the specified quantity into anAppendable.- Specified by:
formatin interfacejavax.measure.format.QuantityFormat- 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 javax.measure.Quantity<?> parse(CharSequence csq, ParsePosition cursor) throws IllegalArgumentException, javax.measure.format.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 interfacejavax.measure.format.QuantityFormat- 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.MeasurementParseException
-
parse
protected javax.measure.Quantity<?> parse(CharSequence csq, int index) throws IllegalArgumentException, javax.measure.format.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).javax.measure.format.MeasurementParseException
-
parse
public javax.measure.Quantity<?> parse(CharSequence csq) throws IllegalArgumentException, javax.measure.format.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,javax.measure.Quantity>- Specified by:
parsein interfacejavax.measure.format.QuantityFormat- 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.MeasurementParseException
-
isLocaleSensitive
public boolean isLocaleSensitive()
-
formatCompound
protected StringBuffer formatCompound(CompoundQuantity<?> comp, StringBuffer dest)
Description copied from class:AbstractQuantityFormatConvenience method equivalent to#format(CompoundQuantity, Appendable)except it does not raise an IOException.- Specified by:
formatCompoundin classAbstractQuantityFormat- Parameters:
comp- the composite quantity to format.dest- the appendable destination.- Returns:
- the specified
StringBuilder.
-
parseCompound
public CompoundQuantity<?> parseCompound(CharSequence csq, ParsePosition cursor) throws IllegalArgumentException, javax.measure.format.MeasurementParseException
- Throws:
IllegalArgumentExceptionjavax.measure.format.MeasurementParseException
-
parseCompound
protected CompoundQuantity<?> parseCompound(CharSequence csq, int index) throws IllegalArgumentException, javax.measure.format.MeasurementParseException
- Throws:
IllegalArgumentExceptionjavax.measure.format.MeasurementParseException
-
parseCompound
public CompoundQuantity<?> parseCompound(CharSequence csq) throws IllegalArgumentException, javax.measure.format.MeasurementParseException
- Throws:
IllegalArgumentExceptionjavax.measure.format.MeasurementParseException
-
-