Top Description Fields Constructors Methods
tech.units.indriya.internal.format

public Class RationalNumberFormat

extends NumberFormat
Class Inheritance
Annotations
@API
status:INTERNAL
Static Imports
org.apiguardian.api.API.Status.INTERNAL

Wraps a given NumberFormat and extends it to also support the rational number format.

eg. 5÷3

Author
Andi Huber

Field Summary

Modifier and TypeField and Description
private final NumberFormat
private static final long
Inherited from java.text.NumberFormat:
FRACTION_FIELDINTEGER_FIELD

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public StringBuffer
format(double
the double number to format
number
,
StringBuffer
the StringBuffer to which the formatted text is to be appended
toAppendTo
,
FieldPosition
keeps track on the position of the field within the returned string. For example, for formatting a number 1234567.89 in Locale.US locale, if the given fieldPosition is NumberFormat#INTEGER_FIELD, the begin index and end index of fieldPosition will be set to 0 and 9, respectively for the output string 1,234,567.89.
pos
)

Implements abstract java.text.NumberFormat.format.

Specialization of format.

public StringBuffer
format(long
the long number to format
number
,
StringBuffer
the StringBuffer to which the formatted text is to be appended
toAppendTo
,
FieldPosition
keeps track on the position of the field within the returned string. For example, for formatting a number 123456789 in Locale.US locale, if the given fieldPosition is NumberFormat#INTEGER_FIELD, the begin index and end index of fieldPosition will be set to 0 and 11, respectively for the output string 123,456,789.
pos
)

Implements abstract java.text.NumberFormat.format.

Specialization of format.

public Number
parse(String
the String to parse
source
,
ParsePosition
A ParsePosition object with index and error index information as described above.
parsePosition
)

Implements abstract java.text.NumberFormat.parse.

Parses text from the beginning of the given string to produce a Number.

public static RationalNumberFormat
wrap(NumberFormat numberFormat)

Inherited from java.text.NumberFormat:
cloneequalsformatformatformatgetAvailableLocalesgetCompactNumberInstancegetCompactNumberInstancegetCurrencygetCurrencyInstancegetCurrencyInstancegetInstancegetInstancegetIntegerInstancegetIntegerInstancegetMaximumFractionDigitsgetMaximumIntegerDigitsgetMinimumFractionDigitsgetMinimumIntegerDigitsgetNumberInstancegetNumberInstancegetPercentInstancegetPercentInstancegetRoundingModehashCodeisGroupingUsedisParseIntegerOnlyisStrictparseparseObjectsetCurrencysetGroupingUsedsetMaximumFractionDigitssetMaximumIntegerDigitssetMinimumFractionDigitssetMinimumIntegerDigitssetParseIntegerOnlysetRoundingModesetStrict

Field Detail

numberFormatback to summary
private final NumberFormat numberFormat
serialVersionUIDback to summary
private static final long serialVersionUID

Hides java.text.NumberFormat.serialVersionUID.

Constructor Detail

RationalNumberFormatback to summary
private RationalNumberFormat(NumberFormat numberFormat)

Method Detail

formatback to summary
public StringBuffer format(double number, StringBuffer toAppendTo, FieldPosition pos)

Implements abstract java.text.NumberFormat.format.

Doc from java.text.NumberFormat.format.

Specialization of format.

Parameters
number:double

the double number to format

toAppendTo:StringBuffer

the StringBuffer to which the formatted text is to be appended

pos:FieldPosition

keeps track on the position of the field within the returned string. For example, for formatting a number 1234567.89 in Locale.US locale, if the given fieldPosition is NumberFormat#INTEGER_FIELD, the begin index and end index of fieldPosition will be set to 0 and 9, respectively for the output string 1,234,567.89.

Returns:StringBuffer

the formatted StringBuffer

Annotations
@Override
formatback to summary
public StringBuffer format(long number, StringBuffer toAppendTo, FieldPosition pos)

Implements abstract java.text.NumberFormat.format.

Doc from java.text.NumberFormat.format.

Specialization of format.

Parameters
number:long

the long number to format

toAppendTo:StringBuffer

the StringBuffer to which the formatted text is to be appended

pos:FieldPosition

keeps track on the position of the field within the returned string. For example, for formatting a number 123456789 in Locale.US locale, if the given fieldPosition is NumberFormat#INTEGER_FIELD, the begin index and end index of fieldPosition will be set to 0 and 11, respectively for the output string 123,456,789.

Returns:StringBuffer

the formatted StringBuffer

Annotations
@Override
parseback to summary
public Number parse(String source, ParsePosition parsePosition)

Implements abstract java.text.NumberFormat.parse.

Doc from java.text.NumberFormat.parse.

Parses text from the beginning of the given string to produce a Number.

This method attempts to parse text starting at the index given by the ParsePosition. If parsing succeeds, then the index of the ParsePosition is updated to the index after the last character used (parsing does not necessarily use all characters up to the end of the string), and the parsed number is returned. The updated ParsePosition can be used to indicate the starting point for the next call to this method. If an error occurs, then the index of the ParsePosition is not changed, the error index of the ParsePosition is set to the index of the character where the error occurred, and null is returned.

This method will return a Long if possible (e.g., within the range [Long.MIN_VALUE, Long.MAX_VALUE] and with no decimals), otherwise a Double.

Parameters
source:String

the String to parse

parsePosition:ParsePosition

A ParsePosition object with index and error index information as described above.

Returns:Number

A Number parsed from the string. In case of failure, returns null.

Annotations
@Override
wrapback to summary
public static RationalNumberFormat wrap(NumberFormat numberFormat)