|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectariba.util.formatter.Formatter
ariba.util.formatter.DecimalFormatterCommon
ariba.util.formatter.BigDecimalFormatter
public class BigDecimalFormatter
Responsible for formatting, parsing, and comparing BigDecimal values.
Nested Class Summary | |
---|---|
static class |
BigDecimalFormatter.StrictParseException
If a parse fails ONLY because strict behavior is specified this is used. |
Field Summary | |
---|---|
static java.lang.String |
ClassName
Our Java class name. |
Fields inherited from interface ariba.util.core.Compare |
---|
EqualTo, GreaterThan, LessThan |
Constructor Summary | |
---|---|
BigDecimalFormatter()
Creates a new BigDecimalFormatter . |
Method Summary | |
---|---|
static boolean |
canParseBigDecimalValue(java.lang.Object object)
Returns whether this object can be parsed as a BigDecimal using
the default locale. |
static boolean |
canParseBigDecimalValue(java.lang.Object object,
java.util.Locale locale)
Returns wheteher this object can be parsed as a BigDecimal using
the default locale. |
static int |
compareBigDecimals(java.math.BigDecimal bd1,
java.math.BigDecimal bd2)
Compares two BigDecimals and returns 1, 0, or -1 if bd1 is greater, equal, or less than bd2. |
static void |
enableParserDebug()
Meant for testing only. |
static java.math.BigDecimal |
getBigDecimalValue(double value)
Returns a BigDecimal for this object . |
static java.math.BigDecimal |
getBigDecimalValue(java.lang.Object object)
Returns a BigDecimal for this object using the default
locale. |
static java.math.BigDecimal |
getBigDecimalValue(java.lang.Object object,
java.util.Locale locale)
Returns a BigDecimal for this object using this
locale . |
static java.text.DecimalFormatSymbols |
getDecimalFormatSymbol()
Get the decimal format for the default locale. |
static java.text.DecimalFormatSymbols |
getDecimalFormatSymbol(java.util.Locale locale)
Get the decimal format for this locale |
static java.lang.String |
getStringValue(java.math.BigDecimal object)
Returns a formatted string for the given BigDecimal object in the default locale. |
static java.lang.String |
getStringValue(java.math.BigDecimal value,
int scale)
Returns a formatted string for this BigDecimal value
using this scale to determine how many fractional digits
are shown. |
static java.lang.String |
getStringValue(java.math.BigDecimal value,
int scale,
java.util.Locale locale)
Returns a formatted string for this BigDecimal value
using this scale to determine how many fractional digits
are shown. |
static java.lang.String |
getStringValue(java.math.BigDecimal value,
int scale,
java.util.Locale locale,
java.text.DecimalFormat fmt)
Returns a formatted string for this value using
this scale to determine how many fractional digits are
shown. |
static java.lang.String |
getStringValue(java.math.BigDecimal value,
int scale,
java.util.Locale locale,
java.lang.String pattern)
Returns a formatted string for this BigDecimal value
using this scale to determine how many fractional digits
are shown. |
static java.lang.String |
getStringValue(java.math.BigDecimal object,
java.util.Locale locale)
Returns a formatted string for this BigDecimal object in
this locale . |
java.lang.Object |
getValue(java.lang.Object object,
java.util.Locale locale)
Returns a BigDecimal for this object using this
locale . |
static boolean |
hasDecimal(java.math.BigDecimal amount)
Returns true if the amount has a fractional
component. |
static int |
numDecimalDigits(java.math.BigDecimal bd)
Returns the number of digits in the decimal part of the number. |
static int |
numWholeDigits(java.math.BigDecimal bd)
Returns the number of digits in the whole part of the number. |
static java.math.BigDecimal |
parseBigDecimal(java.lang.String string)
Parses this string as a BigDecimal in the
default locale. |
static DecimalParseInfo |
parseBigDecimal(java.lang.String string,
java.text.DecimalFormat fmt)
Parse the string parameter and return a
DecimalParseInfo that returns information gleaned
from parse such as the BigDecimal number
corresponding to the string, the number of decimal places,
etc. |
static DecimalParseInfo |
parseBigDecimal(java.lang.String string,
java.text.DecimalFormat fmt,
boolean strict)
Parse the string parameter and return a
DecimalParseInfo that returns information gleaned
from parse such as the BigDecimal number
corresponding to the string, the number of decimal places,
etc. |
static java.math.BigDecimal |
parseBigDecimal(java.lang.String string,
java.util.Locale locale)
Parses this string as a BigDecimal in this
locale . |
static java.math.BigDecimal |
parseBigDecimal(java.lang.String string,
java.util.Locale locale,
java.lang.String pattern)
Parses this string as a BigDecimal in this
locale . |
static java.math.BigDecimal |
parseBigDecimal(java.lang.String string,
java.util.Locale locale,
java.lang.String pattern,
boolean strict)
Parses this string as a BigDecimal in this
locale . |
static DecimalParseInfo |
parseBigDecimalInfo(java.lang.String string,
java.util.Locale locale)
Parses this string as a BigDecimal in this
locale , returning a DecimalParseInfo
object describing the parse. |
static DecimalParseInfo |
parseBigDecimalInfo(java.lang.String string,
java.util.Locale locale,
boolean strict)
Parses this string as a BigDecimal in this
locale , returning a DecimalParseInfo
object describing the parse. |
static java.math.BigDecimal |
reciprocal(java.math.BigDecimal value)
Returns the reciprocal of this value. |
static java.math.BigDecimal |
round(java.math.BigDecimal amount,
int scale)
Rounds the amount to the number of decimal places
specified by scale and returns the new amount. |
static java.math.BigDecimal |
roundCeiling(java.math.BigDecimal amount,
int scale)
Rounds the money amount toward positive infinity, to the number of decimal places specified by scale
and returns the new amount. |
Methods inherited from class ariba.util.formatter.DecimalFormatterCommon |
---|
trimString, trimString |
Methods inherited from class ariba.util.formatter.Formatter |
---|
canFormatNulls, compare, compare, equal, equal, getFormat, getFormat, getFormatterClassForType, getFormatterForObject, getFormatterForType, getLocale, getStringValue, getStringValue, getValue, handlesNulls, isBidirectional, makeParseException, makeParseException, makeParseException, makeParseExceptionMessage, makeParseExceptionMessage, objectsAreEqual, objectsAreEqual, parse, parse, parseString, parseString, quickCompare, quickCompare, quickCompareValue, registerFormatter |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String ClassName
Constructor Detail |
---|
public BigDecimalFormatter()
BigDecimalFormatter
.
Method Detail |
---|
public static java.lang.String getStringValue(java.math.BigDecimal object)
object
in the default locale.
object
- The BigDecimal used to generate the string value
public static java.lang.String getStringValue(java.math.BigDecimal object, java.util.Locale locale)
object
in
this locale
. Trailing decimal zeros are removed from the
string.
object
- BigDecimal
to convert to a string valuelocale
- Locale
to use to format the string
BigDecimal
public static java.lang.String getStringValue(java.math.BigDecimal value, int scale)
value
using this scale
to determine how many fractional digits
are shown. Uses the formatter's default locale.
value
- BigDecimal
to convert to a string valuescale
- The number of decimal places to create in the string value
BigDecimal
public static java.lang.String getStringValue(java.math.BigDecimal value, int scale, java.util.Locale locale)
value
using this scale
to determine how many fractional digits
are shown. Uses the default pattern for this locale
.
value
- BigDecimal
to convert to a string valuescale
- The number of decimal places to create in the string valuelocale
- Locale
to use to format the string
BigDecimal
public static java.lang.String getStringValue(java.math.BigDecimal value, int scale, java.util.Locale locale, java.lang.String pattern)
value
using this scale
to determine how many fractional digits
are shown. Uses the default pattern for this locale
.
value
- BigDecimal
to convert to a string valuescale
- The number of decimal places to create in the string valuelocale
- Locale
to use to format the stringpattern
- the DecimalFormat pattern to use for formatting
BigDecimal
DecimalFormat
public static java.lang.String getStringValue(java.math.BigDecimal value, int scale, java.util.Locale locale, java.text.DecimalFormat fmt)
value
using
this scale
to determine how many fractional digits are
shown. Uses the DecimalFormat
passed in to format the number.
value
- BigDecimal
to convert to a string value.scale
- The number of decimal places to create in the string value.locale
- Locale
to use to format the string.fmt
- The DecimalFormat
to use for fetching localized
symbols.
BigDecimal
.public static java.math.BigDecimal parseBigDecimal(java.lang.String string) throws java.text.ParseException
string
as a BigDecimal
in the
default locale.
string
- The string to be parsed
java.text.ParseException
public static java.math.BigDecimal parseBigDecimal(java.lang.String string, java.util.Locale locale) throws java.text.ParseException
string
as a BigDecimal in this
locale
.
First converts the number string into a "canonical" number string
which is acceptable to the BigDecimal(string) constructor. It then
calls this constructor and returns a new BigDecimal.
If the parse cannot be performed successfully, the parser throws
a ParseException
.
string
- The string to parse.locale
- The locale to use to get localized number and currency
symbols such as the decimal separator.
BigDecimal
corresponding to the
string
parameter.
java.text.ParseException
public static java.math.BigDecimal parseBigDecimal(java.lang.String string, java.util.Locale locale, java.lang.String pattern) throws java.text.ParseException
string
as a BigDecimal in this
locale
.
First converts the number string into a "canonical" number string
which is acceptable to the BigDecimal(string) constructor. It then
calls this constructor and returns a new BigDecimal.
If the parse cannot be performed successfully, the parser throws
a ParseException
.
string
- The string to parse.locale
- The locale to use to get localized number and currency
symbols such as the decimal separator.pattern
- The DecimalFormat pattern to use for parsing
BigDecimal
corresponding to the
string
parameter.
java.text.ParseException
DecimalFormat
public static java.math.BigDecimal parseBigDecimal(java.lang.String string, java.util.Locale locale, java.lang.String pattern, boolean strict) throws java.text.ParseException
string
as a BigDecimal in this
locale
.
First converts the number string into a "canonical" number string
which is acceptable to the BigDecimal(string) constructor. It then
calls this constructor and returns a new BigDecimal.
If the parse cannot be performed successfully, the parser throws
a ParseException
.
string
- The string to parse.locale
- The locale to use to get localized number and currency
symbols such as the decimal separator.pattern
- The DecimalFormat pattern to use for parsingstrict
- If we should be lenient in what we accept, or throw an exception
on a bad string.
BigDecimal
corresponding to the
string
parameter.
java.text.ParseException
DecimalFormat
public static DecimalParseInfo parseBigDecimalInfo(java.lang.String string, java.util.Locale locale) throws java.text.ParseException
string
as a BigDecimal in this
locale
, returning a DecimalParseInfo
object describing the parse.
The BigDecimal result can be accessed through the number
public member on DecimalParseInfo
If the parse cannot be performed successfully, the parser throws
a ParseException
.
string
- The string to parse.locale
- The locale to use to get localized number and currency
symbols such as the decimal separator.
DecimalParseInfo
object corresponding
to the string
parameter.
java.text.ParseException
public static DecimalParseInfo parseBigDecimalInfo(java.lang.String string, java.util.Locale locale, boolean strict) throws java.text.ParseException
string
as a BigDecimal in this
locale
, returning a DecimalParseInfo
object describing the parse.
The BigDecimal result can be accessed through the number
public member on DecimalParseInfo
If the parse cannot be performed successfully, the parser throws
a ParseException
.
string
- The string to parse.locale
- The locale to use to get localized number and currency
symbols such as the decimal separator.
DecimalParseInfo
object corresponding
to the string
parameter.
java.text.ParseException
public static DecimalParseInfo parseBigDecimal(java.lang.String string, java.text.DecimalFormat fmt) throws java.text.ParseException
string
parameter and return a
DecimalParseInfo
that returns information gleaned
from parse such as the BigDecimal
number
corresponding to the string, the number of decimal places,
etc.
If the parse cannot be performed successfully, the parser throws
a ParseException
.
string
- The string to parse.fmt
- The DecimalFormat
to use for fetching localized
symbols.
BigDecimal
corresponding to the
string
parameter.
java.text.ParseException
public static DecimalParseInfo parseBigDecimal(java.lang.String string, java.text.DecimalFormat fmt, boolean strict) throws java.text.ParseException
string
parameter and return a
DecimalParseInfo
that returns information gleaned
from parse such as the BigDecimal
number
corresponding to the string, the number of decimal places,
etc.
If the parse cannot be performed successfully, the parser throws
a ParseException
.
string
- The string to parse.fmt
- The DecimalFormat
to use for fetching localized
symbols.strict
- If we should be lenient in what we accept, or throw an exception
on a bad string.
BigDecimal
corresponding to the
string
parameter.
java.text.ParseException
public static void enableParserDebug()
public static java.math.BigDecimal getBigDecimalValue(java.lang.Object object)
object
using the default
locale. If object
is not a BigDecimal, the object is converted
to a string and parsed. If there is a problem parsing the string, or
the value is null, we return zero as a default value.
object
- If object is not a BigDecimal, the object is converted to a string and parsed.
public static java.math.BigDecimal getBigDecimalValue(java.lang.Object object, java.util.Locale locale)
object
using this
locale
. If object
is not a BigDecimal, the object is
converted to a string and parsed. If there is a problem parsing the
string, or the value is null, we return zero as a default value.
object
- The object to convert to a BigDecimal
.locale
- Locale
to use to parse the
object
if necessary.
BigDecimal
corresponding to the
object
parameter.public static boolean canParseBigDecimalValue(java.lang.Object object)
object
can be parsed as a BigDecimal using
the default locale. If object
is not a BigDecimal, the object is
converted to a string and parsed. If there is a problem parsing the string, we
return false.
object
- If object is not a BigDecimal, the object is converted to a string and parsed.
public static boolean canParseBigDecimalValue(java.lang.Object object, java.util.Locale locale)
object
can be parsed as a BigDecimal using
the default locale. If object
is not a BigDecimal, the object is
converted to a string and parsed. If there is a problem parsing the string, we
return false.
object
- If object is not a BigDecimal, the object is converted to a string and parsed.locale
- Locale
to use to parse the
object
if necessary.
public static java.math.BigDecimal getBigDecimalValue(double value)
object
. If object
is
not a BigDecimal, the object is converted to a string and parsed. If
there is a problem parsing the string, or the value is null, we return
zero as a default value.
value
- a double for which a BigDecimal
is returned
public java.lang.Object getValue(java.lang.Object object, java.util.Locale locale)
object
using this
locale
. The meat of this method is implemented
in bigDecimalValue(object, locale)
.
getValue
in class Formatter
object
- The object to convert to a BigDecimal
.locale
- Locale
to use to parse the
object
if necessary.
BigDecimal
corresponding to the
object
parameter.public static java.math.BigDecimal reciprocal(java.math.BigDecimal value)
value
BigDecimal
must have the desired scale of the result.
value
- the input BigDecimal
public static java.math.BigDecimal round(java.math.BigDecimal amount, int scale)
amount
to the number of decimal places
specified by scale
and returns the new amount.
If the amount
is already rounded to scale
or has fewer decimal places than scale
, we simply
return the amount
.
amount
- The number to round.scale
- The number of decimal places to round to.
BigDecimal
.public static java.math.BigDecimal roundCeiling(java.math.BigDecimal amount, int scale)
scale
and returns the new amount.
amount
- The BigDecimal inputscale
- The number of decimal places to round the input
public static java.text.DecimalFormatSymbols getDecimalFormatSymbol()
public static java.text.DecimalFormatSymbols getDecimalFormatSymbol(java.util.Locale locale)
locale
- the locale to use when returning the decimal format
public static boolean hasDecimal(java.math.BigDecimal amount)
true
if the amount
has a fractional
component.
amount
- The BigDecimal
input
public static int numDecimalDigits(java.math.BigDecimal bd)
bd
- The BigDecimal input
public static int numWholeDigits(java.math.BigDecimal bd)
bd
- The BigDecimal being input
public static int compareBigDecimals(java.math.BigDecimal bd1, java.math.BigDecimal bd2)
bd1
- BigDecimal
used in comparisionbd2
- BigDecimal
used in comparision
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |