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.


Field Summary
static 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(Object object)
          Returns whether this object can be parsed as a BigDecimal using the default locale.
static boolean canParseBigDecimalValue(Object object, Locale locale)
          Returns wheteher this object can be parsed as a BigDecimal using the default locale.
static int compareBigDecimals(BigDecimal bd1, BigDecimal bd2)
          Compares two BigDecimals and returns 1, 0, or -1 if bd1 is greater, equal, or less than bd2.
static BigDecimal getBigDecimalValue(double value)
          Returns a BigDecimal for this object.
static BigDecimal getBigDecimalValue(Object object)
          Returns a BigDecimal for this object using the default locale.
static BigDecimal getBigDecimalValue(Object object, Locale locale)
          Returns a BigDecimal for this object using this locale.
static DecimalFormatSymbols getDecimalFormatSymbol()
          Get the decimal format for the default locale.
static DecimalFormatSymbols getDecimalFormatSymbol(Locale locale)
          Get the decimal format for this locale
static String getStringValue(BigDecimal object)
          Returns a formatted string for the given BigDecimal object in the default locale.
static String getStringValue(BigDecimal value, int scale)
          Returns a formatted string for this BigDecimal value using this scale to determine how many fractional digits are shown.
static String getStringValue(BigDecimal value, int scale, Locale locale)
          Returns a formatted string for this BigDecimal value using this scale to determine how many fractional digits are shown.
static String getStringValue(BigDecimal value, int scale, Locale locale, DecimalFormat fmt)
          Returns a formatted string for this value using this scale to determine how many fractional digits are shown.
static String getStringValue(BigDecimal value, int scale, Locale locale, String pattern)
          Returns a formatted string for this BigDecimal value using this scale to determine how many fractional digits are shown.
static String getStringValue(BigDecimal object, Locale locale)
          Returns a formatted string for this BigDecimal object in this locale.
 Object getValue(Object object, Locale locale)
          Returns a BigDecimal for this object using this locale.
static boolean hasDecimal(BigDecimal amount)
          Returns true if the amount has a fractional component.
static int numDecimalDigits(BigDecimal bd)
          Returns the number of digits in the decimal part of the number.
static int numWholeDigits(BigDecimal bd)
          Returns the number of digits in the whole part of the number.
static BigDecimal parseBigDecimal(String string)
          Parses this string as a BigDecimal in the default locale.
static DecimalParseInfo parseBigDecimal(String string, 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 BigDecimal parseBigDecimal(String string, Locale locale)
          Parses this string as a BigDecimal in this locale.
static BigDecimal parseBigDecimal(String string, Locale locale, String pattern)
          Parses this string as a BigDecimal in this locale.
static DecimalParseInfo parseBigDecimalInfo(String string, Locale locale)
          Parses this string as a BigDecimal in this locale, returning a DecimalParseInfo object describing the parse.
static BigDecimal reciprocal(BigDecimal value)
          Returns the reciprocal of this value.
static BigDecimal round(BigDecimal amount, int scale)
          Rounds the amount to the number of decimal places specified by scale and returns the new amount.
static BigDecimal roundCeiling(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, 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 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 String getStringValue(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 String getStringValue(BigDecimal object,
                                    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 String getStringValue(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 String getStringValue(BigDecimal value,
                                    int scale,
                                    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 String getStringValue(BigDecimal value,
                                    int scale,
                                    Locale locale,
                                    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 String getStringValue(BigDecimal value,
                                    int scale,
                                    Locale locale,
                                    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 BigDecimal parseBigDecimal(String string)
                                  throws 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:
ParseException

parseBigDecimal

public static BigDecimal parseBigDecimal(String string,
                                         Locale locale)
                                  throws 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:
ParseException

parseBigDecimal

public static BigDecimal parseBigDecimal(String string,
                                         Locale locale,
                                         String pattern)
                                  throws 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:
ParseException
See Also:
DecimalFormat

parseBigDecimalInfo

public static DecimalParseInfo parseBigDecimalInfo(String string,
                                                   Locale locale)
                                            throws 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:
ParseException

parseBigDecimal

public static DecimalParseInfo parseBigDecimal(String string,
                                               DecimalFormat fmt)
                                        throws 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:
ParseException

getBigDecimalValue

public static BigDecimal getBigDecimalValue(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 BigDecimal getBigDecimalValue(Object object,
                                            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(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(Object object,
                                              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 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 Object getValue(Object object,
                       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 BigDecimal reciprocal(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 BigDecimal round(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 BigDecimal roundCeiling(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 DecimalFormatSymbols getDecimalFormatSymbol()
Get the decimal format for the default locale.

Returns:
Returns decimal format for the default locale

getDecimalFormatSymbol

public static DecimalFormatSymbols getDecimalFormatSymbol(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(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(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(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(BigDecimal bd1,
                                     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-2009 Ariba, Inc. All Rights Reserved.