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

public Class BigFractionFormat

extends AbstractFormat
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Known Direct Subclasses
org.apache.commons.math3.fraction.ProperBigFractionFormat
Imports
java.io.Serializable, java.math.BigInteger, java.text.FieldPosition, .NumberFormat, .ParsePosition, java.util.Locale, org.apache.commons.math3.exception.MathIllegalArgumentException, .MathParseException, org.apache.commons.math3.exception.util.LocalizedFormats

Formats a BigFraction number in proper format or improper format.

The number format for each of the whole number, numerator and, denominator can be configured.

Since
2.0

Field Summary

Modifier and TypeField and Description
private static final long

Constructor Summary

AccessConstructor and Description
public
BigFractionFormat()

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

public
BigFractionFormat(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.

public
BigFractionFormat(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:

the value passed in as toAppendTo.
format
(final BigFraction
the object to format.
BigFraction
,
final StringBuffer
where the text is to be appended
toAppendTo
,
final FieldPosition
On input: an alignment field, if desired. On output: the offsets of the alignment field
pos
)

Formats a BigFraction object to produce a string.

public StringBuffer

Returns:

the value passed in as toAppendTo.
format
(final Object
the object to format.
obj
,
final StringBuffer
where the text is to be appended
toAppendTo
,
final FieldPosition
On input: an alignment field, if desired. On output: the offsets of the alignment field
pos
)

Overrides java.text.NumberFormat.format.

Formats an object and appends the result to a StringBuffer.

public static String

Returns:

A formatted BigFraction in proper form.
formatBigFraction
(final BigFraction
BigFraction object to format
f
)

This static method calls formatBigFraction() on a default instance of BigFractionFormat.

public static Locale[]

Returns:

available complex format locales.
getAvailableLocales
()

Hides java.text.NumberFormat.getAvailableLocales.

Get the set of locales for which complex formats are available.

public static BigFractionFormat

Returns:

the default complex format.
getImproperInstance
()

Returns the default complex format for the current locale.

public static BigFractionFormat

Returns:

the complex format specific to the given locale.
getImproperInstance
(final Locale
the specific locale used by the format.
locale
)

Returns the default complex format for the given locale.

public static BigFractionFormat

Returns:

the default complex format.
getProperInstance
()

Returns the default complex format for the current locale.

public static BigFractionFormat

Returns:

the complex format specific to the given locale.
getProperInstance
(final Locale
the specific locale used by the format.
locale
)

Returns the default complex format for the given locale.

public BigFraction

Returns:

the parsed BigFraction object.
parse
(final String
the string to parse
source
)

Overrides java.text.NumberFormat.parse.

Parses a string to produce a BigFraction object.

public BigFraction

Returns:

the parsed BigFraction object.
parse
(final String
the string to parse
source
,
final ParsePosition
input/output parsing parameter.
pos
)

Implements abstract java.text.NumberFormat.parse.

Parses a string to produce a BigFraction object.

protected BigInteger

Returns:

a parsed BigInteger or null if string does not contain a BigInteger at the specified position
parseNextBigInteger
(final String
the string to parse
source
,
final ParsePosition
input/output parsing parameter.
pos
)

Parses a string to produce a BigInteger.

Inherited from org.apache.commons.math3.fraction.AbstractFormat:
formatformatgetDefaultNumberFormatgetDefaultNumberFormatgetDenominatorFormatgetNumeratorFormatparseAndIgnoreWhitespaceparseNextCharactersetDenominatorFormatsetNumeratorFormat

Field Detail

serialVersionUIDback to summary
private static final long serialVersionUID

Hides org.apache.commons.math3.fraction.AbstractFormat.serialVersionUID.

Serializable version identifier

Constructor Detail

BigFractionFormatback to summary
public BigFractionFormat()

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

BigFractionFormatback to summary
public BigFractionFormat(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.

BigFractionFormatback to summary
public BigFractionFormat(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 BigFraction BigFraction, final StringBuffer toAppendTo, final FieldPosition pos)

Formats a BigFraction object to produce a string. The BigFraction is output in improper format.

Parameters
BigFraction:BigFraction

the object to format.

toAppendTo:StringBuffer

where the text is to be appended

pos:FieldPosition

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

Returns:StringBuffer

the value passed in as toAppendTo.

formatback to summary
public StringBuffer format(final Object obj, final StringBuffer toAppendTo, final FieldPosition pos)

Overrides java.text.NumberFormat.format.

Formats an object and appends the result to a StringBuffer. obj must be either a BigFraction object or a BigInteger object or a Number object. Any other type of object will result in an IllegalArgumentException being thrown.

Parameters
obj:Object

the object to format.

toAppendTo:StringBuffer

where the text is to be appended

pos:FieldPosition

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

Returns:StringBuffer

the value passed in as toAppendTo.

Annotations
@Override
Exceptions
MathIllegalArgumentException:
if obj is not a valid type.
See Also
java.text.Format#format(java.lang.Object, java.lang.StringBuffer, java.text.FieldPosition)
formatBigFractionback to summary
public static String formatBigFraction(final BigFraction f)

This static method calls formatBigFraction() on a default instance of BigFractionFormat.

Parameters
f:BigFraction

BigFraction object to format

Returns:String

A formatted BigFraction in proper form.

getAvailableLocalesback to summary
public static Locale[] getAvailableLocales()

Hides java.text.NumberFormat.getAvailableLocales.

Get the set of locales for which complex formats are available. This is the same set as the NumberFormat set.

Returns:Locale[]

available complex format locales.

getImproperInstanceback to summary
public static BigFractionFormat getImproperInstance()

Returns the default complex format for the current locale.

Returns:BigFractionFormat

the default complex format.

getImproperInstanceback to summary
public static BigFractionFormat getImproperInstance(final Locale locale)

Returns the default complex format for the given locale.

Parameters
locale:Locale

the specific locale used by the format.

Returns:BigFractionFormat

the complex format specific to the given locale.

getProperInstanceback to summary
public static BigFractionFormat getProperInstance()

Returns the default complex format for the current locale.

Returns:BigFractionFormat

the default complex format.

getProperInstanceback to summary
public static BigFractionFormat getProperInstance(final Locale locale)

Returns the default complex format for the given locale.

Parameters
locale:Locale

the specific locale used by the format.

Returns:BigFractionFormat

the complex format specific to the given locale.

parseback to summary
public BigFraction parse(final String source) throws MathParseException

Overrides java.text.NumberFormat.parse.

Parses a string to produce a BigFraction object.

Parameters
source:String

the string to parse

Returns:BigFraction

the parsed BigFraction object.

Annotations
@Override
Exceptions
MathParseException:
if the beginning of the specified string cannot be parsed.
parseback to summary
public BigFraction parse(final String source, final ParsePosition pos)

Implements abstract java.text.NumberFormat.parse.

Parses a string to produce a BigFraction object. This method expects the string to be formatted as an improper BigFraction.

Parameters
source:String

the string to parse

pos:ParsePosition

input/output parsing parameter.

Returns:BigFraction

the parsed BigFraction object.

Annotations
@Override
parseNextBigIntegerback to summary
protected BigInteger parseNextBigInteger(final String source, final ParsePosition pos)

Parses a string to produce a BigInteger.

Parameters
source:String

the string to parse

pos:ParsePosition

input/output parsing parameter.

Returns:BigInteger

a parsed BigInteger or null if string does not contain a BigInteger at the specified position