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

public Class ProperBigFractionFormat

extends BigFractionFormat
Class Inheritance
Imports
java.math.BigInteger, java.text.FieldPosition, .NumberFormat, .ParsePosition, org.apache.commons.math3.exception.util.LocalizedFormats, org.apache.commons.math3.exception.NullArgumentException

Formats a BigFraction number in proper format. The number format for each of the whole number, numerator and, denominator can be configured.

Minus signs are only allowed in the whole number part - i.e., "-3 1/2" is legitimate and denotes -7/2, but "-3 -1/2" is invalid and will result in a ParseException.

Since
1.1

Field Summary

Modifier and TypeField and Description
private static final long
private NumberFormat
wholeFormat

The format used for the whole number.

Constructor Summary

AccessConstructor and Description
public
ProperBigFractionFormat()

Create a proper formatting instance with the default number format for the whole, numerator, and denominator.

public
ProperBigFractionFormat(final NumberFormat
the custom format for the whole, numerator, and denominator.
format
)

Create a proper formatting instance with a custom number format for the whole, numerator, and denominator.

public
ProperBigFractionFormat(final NumberFormat
the custom format for the whole.
wholeFormat
,
final NumberFormat
the custom format for the numerator.
numeratorFormat
,
final NumberFormat
the custom format for the denominator.
denominatorFormat
)

Create a proper formatting instance with a custom number format for each of the whole, numerator, and denominator.

Method Summary

Modifier and TypeMethod and Description
public StringBuffer

Returns:

the value passed in as toAppendTo.
format
(final BigFraction
the object to format.
fraction
,
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 org.apache.commons.math3.fraction.BigFractionFormat.format.

Formats a BigFraction object to produce a string.

public NumberFormat

Returns:

the whole format.
getWholeFormat
()

Access the whole format.

public BigFraction

Returns:

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

Overrides org.apache.commons.math3.fraction.BigFractionFormat.parse.

Parses a string to produce a BigFraction object.

public void
setWholeFormat(final NumberFormat
The new whole format value.
format
)

Modify the whole format.

Inherited from org.apache.commons.math3.fraction.BigFractionFormat:
formatformatBigFractiongetAvailableLocalesgetImproperInstancegetImproperInstancegetProperInstancegetProperInstanceparseparseNextBigInteger

Field Detail

serialVersionUIDback to summary
private static final long serialVersionUID

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

Serializable version identifier

wholeFormatback to summary
private NumberFormat wholeFormat

The format used for the whole number.

Constructor Detail

ProperBigFractionFormatback to summary
public ProperBigFractionFormat()

Create a proper formatting instance with the default number format for the whole, numerator, and denominator.

ProperBigFractionFormatback to summary
public ProperBigFractionFormat(final NumberFormat format)

Create a proper formatting instance with a custom number format for the whole, numerator, and denominator.

Parameters
format:NumberFormat

the custom format for the whole, numerator, and denominator.

ProperBigFractionFormatback to summary
public ProperBigFractionFormat(final NumberFormat wholeFormat, final NumberFormat numeratorFormat, final NumberFormat denominatorFormat)

Create a proper formatting instance with a custom number format for each of the whole, numerator, and denominator.

Parameters
wholeFormat:NumberFormat

the custom format for the whole.

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 fraction, final StringBuffer toAppendTo, final FieldPosition pos)

Overrides org.apache.commons.math3.fraction.BigFractionFormat.format.

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

Parameters
fraction: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.

Annotations
@Override
getWholeFormatback to summary
public NumberFormat getWholeFormat()

Access the whole format.

Returns:NumberFormat

the whole format.

parseback to summary
public BigFraction parse(final String source, final ParsePosition pos)

Overrides org.apache.commons.math3.fraction.BigFractionFormat.parse.

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

Minus signs are only allowed in the whole number part - i.e., "-3 1/2" is legitimate and denotes -7/2, but "-3 -1/2" is invalid and will result in a ParseException.

Parameters
source:String

the string to parse

pos:ParsePosition

input/ouput parsing parameter.

Returns:BigFraction

the parsed BigFraction object.

Annotations
@Override
setWholeFormatback to summary
public void setWholeFormat(final NumberFormat format)

Modify the whole format.

Parameters
format:NumberFormat

The new whole format value.

Exceptions
NullArgumentException:
if format is null.