ariba.util.formatter
Class BigDecimalFormatter

java.lang.Object
  extended by ariba.util.formatter.Formatter
      extended by ariba.util.formatter.DecimalFormatterCommon
          extended by ariba.util.formatter.BigDecimalFormatter
All Implemented Interfaces:
Compare, StringParser

public class BigDecimalFormatter
extends DecimalFormatterCommon

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

ClassName

public static final java.lang.String ClassName
Our Java class name.

See Also:
Constant Field Values
Constructor Detail

BigDecimalFormatter

public BigDecimalFormatter()
Creates a new BigDecimalFormatter.

Method Detail

getStringValue

public static java.lang.String getStringValue(java.math.BigDecimal object)
Returns a formatted string for the given BigDecimal object in the default locale.

Parameters:
object - The BigDecimal used to generate the string value
Returns:
Returns a string representation of the BigDecimal

getStringValue

public static java.lang.String getStringValue(java.math.BigDecimal object,
                                              java.util.Locale locale)
Returns a formatted string for this BigDecimal object in this locale. Trailing decimal zeros are removed from the string.

Parameters:
object - BigDecimal to convert to a string value
locale - Locale to use to format the string
Returns:
Returns a string representation of the BigDecimal

getStringValue

public 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. Uses the formatter's default locale.

Parameters:
value - BigDecimal to convert to a string value
scale - The number of decimal places to create in the string value
Returns:
Returns a string representation of the BigDecimal

getStringValue

public 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. Uses the default pattern for this locale.

Parameters:
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
Returns:
Returns a string representation of the BigDecimal

getStringValue

public 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. Uses the default pattern for this locale.

Parameters:
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
pattern - the DecimalFormat pattern to use for formatting
Returns:
Returns a string representation of the BigDecimal
See Also:
DecimalFormat

getStringValue

public 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. Uses the DecimalFormat passed in to format the number.

Parameters:
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.
Returns:
Returns a string representation of the BigDecimal.

parseBigDecimal

public static java.math.BigDecimal parseBigDecimal(java.lang.String string)
                                            throws java.text.ParseException
Parses this string as a BigDecimal in the default locale.

Parameters:
string - The string to be parsed
Returns:
Returns a BigDecimal for the input string using the default locale
Throws:
java.text.ParseException

parseBigDecimal

public static java.math.BigDecimal parseBigDecimal(java.lang.String string,
                                                   java.util.Locale locale)
                                            throws java.text.ParseException
Parses this 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.

Parameters:
string - The string to parse.
locale - The locale to use to get localized number and currency symbols such as the decimal separator.
Returns:
Returns the BigDecimal corresponding to the string parameter.
Throws:
java.text.ParseException

parseBigDecimal

public static java.math.BigDecimal parseBigDecimal(java.lang.String string,
                                                   java.util.Locale locale,
                                                   java.lang.String pattern)
                                            throws java.text.ParseException
Parses this 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.

Parameters:
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
Returns:
Returns the BigDecimal corresponding to the string parameter.
Throws:
java.text.ParseException
See Also:
DecimalFormat

parseBigDecimal

public static java.math.BigDecimal parseBigDecimal(java.lang.String string,
                                                   java.util.Locale locale,
                                                   java.lang.String pattern,
                                                   boolean strict)
                                            throws java.text.ParseException
Parses this 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.

Parameters:
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
strict - If we should be lenient in what we accept, or throw an exception on a bad string.
Returns:
Returns the BigDecimal corresponding to the string parameter.
Throws:
java.text.ParseException
See Also:
DecimalFormat

parseBigDecimalInfo

public static DecimalParseInfo parseBigDecimalInfo(java.lang.String string,
                                                   java.util.Locale locale)
                                            throws java.text.ParseException
Parses this 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.

Parameters:
string - The string to parse.
locale - The locale to use to get localized number and currency symbols such as the decimal separator.
Returns:
Returns the DecimalParseInfo object corresponding to the string parameter.
Throws:
java.text.ParseException

parseBigDecimalInfo

public static DecimalParseInfo parseBigDecimalInfo(java.lang.String string,
                                                   java.util.Locale locale,
                                                   boolean strict)
                                            throws java.text.ParseException
Parses this 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.

Parameters:
string - The string to parse.
locale - The locale to use to get localized number and currency symbols such as the decimal separator.
Returns:
Returns the DecimalParseInfo object corresponding to the string parameter.
Throws:
java.text.ParseException

parseBigDecimal

public static DecimalParseInfo parseBigDecimal(java.lang.String string,
                                               java.text.DecimalFormat fmt)
                                        throws java.text.ParseException
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. If the parse cannot be performed successfully, the parser throws a ParseException.

Parameters:
string - The string to parse.
fmt - The DecimalFormat to use for fetching localized symbols.
Returns:
Returns the BigDecimal corresponding to the string parameter.
Throws:
java.text.ParseException

parseBigDecimal

public static DecimalParseInfo parseBigDecimal(java.lang.String string,
                                               java.text.DecimalFormat fmt,
                                               boolean strict)
                                        throws java.text.ParseException
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. If the parse cannot be performed successfully, the parser throws a ParseException.

Parameters:
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.
Returns:
Returns the BigDecimal corresponding to the string parameter.
Throws:
java.text.ParseException

enableParserDebug

public static void enableParserDebug()
Meant for testing only.


getBigDecimalValue

public static java.math.BigDecimal getBigDecimalValue(java.lang.Object object)
Returns a BigDecimal for this 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.

Parameters:
object - If object is not a BigDecimal, the object is converted to a string and parsed.
Returns:
Returns a BigDecimal for the object

getBigDecimalValue

public static java.math.BigDecimal getBigDecimalValue(java.lang.Object object,
                                                      java.util.Locale locale)
Returns a BigDecimal for this 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.

Parameters:
object - The object to convert to a BigDecimal.
locale - Locale to use to parse the object if necessary.
Returns:
Returns a BigDecimal corresponding to the object parameter.

canParseBigDecimalValue

public static boolean canParseBigDecimalValue(java.lang.Object object)
Returns whether this 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.

Parameters:
object - If object is not a BigDecimal, the object is converted to a string and parsed.
Returns:
Returns true if the object can be parsed as a BigDecimal

canParseBigDecimalValue

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

Parameters:
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.
Returns:
Returns true if the object can be parsed as a BigDecimal

getBigDecimalValue

public static java.math.BigDecimal getBigDecimalValue(double value)
Returns a BigDecimal for this 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.

Parameters:
value - a double for which a BigDecimal is returned
Returns:
Returns a BigDecimal for the double

getValue

public java.lang.Object getValue(java.lang.Object object,
                                 java.util.Locale locale)
Returns a BigDecimal for this object using this locale. The meat of this method is implemented in bigDecimalValue(object, locale).

Specified by:
getValue in class Formatter
Parameters:
object - The object to convert to a BigDecimal.
locale - Locale to use to parse the object if necessary.
Returns:
Returns a BigDecimal corresponding to the object parameter.

reciprocal

public static java.math.BigDecimal reciprocal(java.math.BigDecimal value)
Returns the reciprocal of this value. The value BigDecimal must have the desired scale of the result.

Parameters:
value - the input BigDecimal
Returns:
Returns a BigDecimal that is the reciprocal of the input

round

public 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. If the amount is already rounded to scale or has fewer decimal places than scale, we simply return the amount.

Parameters:
amount - The number to round.
scale - The number of decimal places to round to.
Returns:
The rounded BigDecimal.

roundCeiling

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

Parameters:
amount - The BigDecimal input
scale - The number of decimal places to round the input
Returns:
Returns a big decimal that has been rounded to scale decimal places

getDecimalFormatSymbol

public static java.text.DecimalFormatSymbols getDecimalFormatSymbol()
Get the decimal format for the default locale.

Returns:
Returns decimal format for the default locale

getDecimalFormatSymbol

public static java.text.DecimalFormatSymbols getDecimalFormatSymbol(java.util.Locale locale)
Get the decimal format for this locale

Parameters:
locale - the locale to use when returning the decimal format
Returns:
Returns decimal format for the locale

hasDecimal

public static boolean hasDecimal(java.math.BigDecimal amount)
Returns true if the amount has a fractional component.

Parameters:
amount - The BigDecimal input
Returns:
Returns true if the amount has a fractional component

numDecimalDigits

public static int numDecimalDigits(java.math.BigDecimal bd)
Returns the number of digits in the decimal part of the number.

Parameters:
bd - The BigDecimal input
Returns:
Returns the number of digits in the decimal part of the BigNumber

numWholeDigits

public static int numWholeDigits(java.math.BigDecimal bd)
Returns the number of digits in the whole part of the number.

Parameters:
bd - The BigDecimal being input
Returns:
Returns the number of digits in the whole part of the number

compareBigDecimals

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

Parameters:
bd1 - BigDecimal used in comparision
bd2 - BigDecimal used in comparision
Returns:
Returns 1, 0, or -1 if bd1 is greater, equal, or less than bd2.


AribaWeb User Interface Development Framework
Copyright © 2000-2014 Ariba, Inc. All Rights Reserved.