Top Description Fields Constructors Methods
org.apache.commons.math3.fraction

public abstract Class AbstractFormat

extends NumberFormat
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Known Direct Subclasses
org.apache.commons.math3.fraction.BigFractionFormat, org.apache.commons.math3.fraction.FractionFormat
Imports
java.io.Serializable, java.text.FieldPosition, .NumberFormat, .ParsePosition, java.util.Locale, org.apache.commons.math3.exception.NullArgumentException, org.apache.commons.math3.exception.util.LocalizedFormats

Common part shared by both FractionFormat and BigFractionFormat.
Since
2.0

Field Summary

Modifier and TypeField and Description
private NumberFormat
denominatorFormat

The format used for the denominator.

private NumberFormat
numeratorFormat

The format used for the numerator.

private static final long
serialVersionUID

Hides java.text.NumberFormat.serialVersionUID.

Serializable version identifier.
Inherited from java.text.NumberFormat:
FRACTION_FIELDINTEGER_FIELD

Constructor Summary

AccessConstructor and Description
protected
AbstractFormat()

Create an improper formatting instance with the default number format for the numerator and denominator.

protected
AbstractFormat(final NumberFormat
the custom format for both the numerator and denominator.
format
)

Create an improper formatting instance with a custom number format for both the numerator and denominator.

protected
AbstractFormat(final NumberFormat
the custom format for the numerator.
numeratorFormat
,
final NumberFormat
the custom format for the denominator.
denominatorFormat
)

Create an improper formatting instance with a custom number format for the numerator and a custom number format for the denominator.

Method Summary

Modifier and TypeMethod and Description
public StringBuffer

Returns:

a reference to the appended buffer
format
(final double
the double value to format
value
,
final StringBuffer
StringBuffer to append to
buffer
,
final FieldPosition
On input: an alignment field, if desired. On output: the offsets of the alignment field
position
)

Implements abstract java.text.NumberFormat.format.

Formats a double value as a fraction and appends the result to a StringBuffer.

public StringBuffer

Returns:

a reference to the appended buffer
format
(final long
the long value to format
value
,
final StringBuffer
StringBuffer to append to
buffer
,
final FieldPosition
On input: an alignment field, if desired. On output: the offsets of the alignment field
position
)

Implements abstract java.text.NumberFormat.format.

Formats a long value as a fraction and appends the result to a StringBuffer.

protected static NumberFormat

Returns:

the default number format.
getDefaultNumberFormat
()

Create a default number format.

protected static NumberFormat

Returns:

the default number format specific to the given locale.
getDefaultNumberFormat
(final Locale
the specific locale used by the format.
locale
)

Create a default number format.

public NumberFormat

Returns:

the denominator format.
getDenominatorFormat
()

Access the denominator format.

public NumberFormat

Returns:

the numerator format.
getNumeratorFormat
()

Access the numerator format.

protected static void
parseAndIgnoreWhitespace(final String
the string to parse
source
,
final ParsePosition
input/output parsing parameter. On output, pos holds the index of the next non-whitespace character.
pos
)

Parses source until a non-whitespace character is found.

protected static char

Returns:

the first non-whitespace character.
parseNextCharacter
(final String
the string to parse
source
,
final ParsePosition
input/output parsing parameter.
pos
)

Parses source until a non-whitespace character is found.

public void
setDenominatorFormat(final NumberFormat
the new denominator format value.
format
)

Modify the denominator format.

public void
setNumeratorFormat(final NumberFormat
the new numerator format value.
format
)

Modify the numerator format.

Inherited from java.text.NumberFormat:
cloneequalsformatformatformatgetAvailableLocalesgetCompactNumberInstancegetCompactNumberInstancegetCurrencygetCurrencyInstancegetCurrencyInstancegetInstancegetInstancegetIntegerInstancegetIntegerInstancegetMaximumFractionDigitsgetMaximumIntegerDigitsgetMinimumFractionDigitsgetMinimumIntegerDigitsgetNumberInstancegetNumberInstancegetPercentInstancegetPercentInstancegetRoundingModehashCodeisGroupingUsedisParseIntegerOnlyisStrictparseparseparseObjectsetCurrencysetGroupingUsedsetMaximumFractionDigitssetMaximumIntegerDigitssetMinimumFractionDigitssetMinimumIntegerDigitssetParseIntegerOnlysetRoundingModesetStrict

Field Detail

denominatorFormatback to summary
private NumberFormat denominatorFormat

The format used for the denominator.

numeratorFormatback to summary
private NumberFormat numeratorFormat

The format used for the numerator.

serialVersionUIDback to summary
private static final long serialVersionUID

Hides java.text.NumberFormat.serialVersionUID.

Serializable version identifier.

Constructor Detail

AbstractFormatback to summary
protected AbstractFormat()

Create an improper formatting instance with the default number format for the numerator and denominator.

AbstractFormatback to summary
protected AbstractFormat(final NumberFormat format)

Create an improper formatting instance with a custom number format for both the numerator and denominator.

Parameters
format:NumberFormat

the custom format for both the numerator and denominator.

AbstractFormatback to summary
protected AbstractFormat(final NumberFormat numeratorFormat, final NumberFormat denominatorFormat)

Create an improper formatting instance with a custom number format for the numerator and a custom number format for the denominator.

Parameters
numeratorFormat:NumberFormat

the custom format for the numerator.

denominatorFormat:NumberFormat

the custom format for the denominator.

Method Detail

formatback to summary
public StringBuffer format(final double value, final StringBuffer buffer, final FieldPosition position)

Implements abstract java.text.NumberFormat.format.

Formats a double value as a fraction and appends the result to a StringBuffer.

Parameters
value:double

the double value to format

buffer:StringBuffer

StringBuffer to append to

position:FieldPosition

On input: an alignment field, if desired. On output: the offsets of the alignment field

Returns:StringBuffer

a reference to the appended buffer

Annotations
@Override
See Also
format(Object, StringBuffer, FieldPosition)
formatback to summary
public StringBuffer format(final long value, final StringBuffer buffer, final FieldPosition position)

Implements abstract java.text.NumberFormat.format.

Formats a long value as a fraction and appends the result to a StringBuffer.

Parameters
value:long

the long value to format

buffer:StringBuffer

StringBuffer to append to

position:FieldPosition

On input: an alignment field, if desired. On output: the offsets of the alignment field

Returns:StringBuffer

a reference to the appended buffer

Annotations
@Override
See Also
format(Object, StringBuffer, FieldPosition)
getDefaultNumberFormatback to summary
protected static NumberFormat getDefaultNumberFormat()

Create a default number format. The default number format is based on NumberFormat#getNumberInstance(java.util.Locale). The only customization is the maximum number of BigFraction digits, which is set to 0.

Returns:NumberFormat

the default number format.

getDefaultNumberFormatback to summary
protected static NumberFormat getDefaultNumberFormat(final Locale locale)

Create a default number format. The default number format is based on NumberFormat#getNumberInstance(java.util.Locale). The only customization is the maximum number of BigFraction digits, which is set to 0.

Parameters
locale:Locale

the specific locale used by the format.

Returns:NumberFormat

the default number format specific to the given locale.

getDenominatorFormatback to summary
public NumberFormat getDenominatorFormat()

Access the denominator format.

Returns:NumberFormat

the denominator format.

getNumeratorFormatback to summary
public NumberFormat getNumeratorFormat()

Access the numerator format.

Returns:NumberFormat

the numerator format.

parseAndIgnoreWhitespaceback to summary
protected static void parseAndIgnoreWhitespace(final String source, final ParsePosition pos)

Parses source until a non-whitespace character is found.

Parameters
source:String

the string to parse

pos:ParsePosition

input/output parsing parameter. On output, pos holds the index of the next non-whitespace character.

parseNextCharacterback to summary
protected static char parseNextCharacter(final String source, final ParsePosition pos)

Parses source until a non-whitespace character is found.

Parameters
source:String

the string to parse

pos:ParsePosition

input/output parsing parameter.

Returns:char

the first non-whitespace character.

setDenominatorFormatback to summary
public void setDenominatorFormat(final NumberFormat format)

Modify the denominator format.

Parameters
format:NumberFormat

the new denominator format value.

Exceptions
NullArgumentException:
if format is null.
setNumeratorFormatback to summary
public void setNumeratorFormat(final NumberFormat format)

Modify the numerator format.

Parameters
format:NumberFormat

the new numerator format value.

Exceptions
NullArgumentException:
if format is null.