ariba.ui.validation
Class GenericMoneyFormatter

java.lang.Object
  extended by ariba.util.formatter.Formatter
      extended by ariba.ui.validation.GenericMoneyFormatter
All Implemented Interfaces:
Compare, StringParser
Direct Known Subclasses:
BigDecimalMoneyFormatter

public class GenericMoneyFormatter
extends Formatter

Responsible for formatting, parsing, and comparing money values. This class will format money objects using a special locale-specific format string. This string is of the form: {1}#,##0.## {2} where '{1}' and '{2}' are tokens for the currency prefix and suffix. The method will replace these tokens with the appropriate values given the currency and then pass the remaining format string to the number formatter. Parsing occurs in a similar fashion where the MoneyFormatter will use the format string (pattern string) to parse a string.


Nested Class Summary
static interface GenericMoneyFormatter.MoneyConverter
           
 
Field Summary
static int DefaultPrecision
           
static java.lang.String EuroSymbol
          The Euro currency prefix symbol
static java.lang.String EuroUniqueName
          ISO suffix and unique name for the Euro currency
static java.lang.String ParameterDisplayEuroSymbol
          Parameter for turning on the display of the Euro symbol
 
Fields inherited from interface ariba.util.core.Compare
EqualTo, GreaterThan, LessThan
 
Constructor Summary
GenericMoneyFormatter(ariba.ui.validation.GenericMoneyFormatter.MoneyAdapter moneyAdapter)
          Create a new MoneyFormatter.
 
Method Summary
 boolean appendSuffix()
           
 int compareMoneys(java.lang.Object m1, java.lang.Object m2)
          Compares two money values in the default locale.
 int compareMoneys(java.lang.Object m1, java.lang.Object m2, boolean round)
          Compares two money values in the default locale.
 int compareMoneys(java.lang.Object m1, java.lang.Object m2, boolean round, java.util.Locale locale)
          Compares two money values in the given locale.
static boolean displayEuroSymbol()
          Returns the value of the DisplayEuroSymbol parameter.
static java.lang.String dualStringValue(java.lang.Object money, java.lang.Object alternate)
          Returns a string value for the money object in two currencies, its default currency and the alternate currency.
static java.math.BigDecimal getAmount(java.lang.Object money)
          Get the amount for the money.
 java.lang.Object getCurrency(java.lang.Object money)
          Get the currency for the money.
 java.lang.String getDefaultStringValue(java.lang.Object object)
          Returns a formatted string for the given Money object.
 java.lang.String getDefaultStringValue(java.lang.Object object, java.util.Locale locale)
          Returns a formatted string for this Money object.
 java.lang.String getEscapedStringValue(java.lang.Object object)
          Returns an HTML-escaped, formatted string for this Money object.
 java.lang.String getEscapedStringValue(java.lang.Object object, java.util.Locale locale)
          Returns an HTML-escaped, formatted string for this Money object.
static java.lang.String getStringValue(java.math.BigDecimal amount, java.lang.Object currency, java.util.Locale locale, java.lang.String euroPrefix, boolean suffix, int precision)
          Returns a formatted string based on a given amount and currency in the given locale.
 java.lang.String getStringValue(java.lang.Object object, boolean suffix)
          Returns a formatted string for the given Money object Turn on/off the suffix with suffix flag
 java.lang.String getStringValue(java.lang.Object object, java.util.Locale locale, boolean suffix)
          Returns a formatted string for this Money object.
 java.lang.String getStringValue(java.lang.Object money, java.util.Locale locale, java.lang.String euroPrefix, boolean suffix)
          Returns a formatted string for this Money object in the given locale.
 java.lang.String getStringValue(java.lang.Object money, java.util.Locale locale, java.lang.String euroPrefix, boolean suffix, int precision)
          Returns a formatted string for this Money object in the given locale.
 java.lang.String getStringValue(java.lang.Object money, java.lang.String euroPrefix, boolean suffix)
          Returns a formatted string for this Money object in the default locale.
 java.lang.Object getValue(java.lang.Object object, java.util.Locale locale)
          Returns a new Money object for the given object.
 boolean isMoney(java.lang.String moneyString)
          Is this string in valid money format? Use the default locale for parsing.
 boolean isMoney(java.lang.String moneyString, java.util.Locale locale)
          Is this string a valid money format for this locale?
 DecimalParseInfo moneyInfo(java.lang.String moneyString)
          Parses the money string to generate some information about the number of digits and the location of the decimal separator (among other things).
 java.lang.Object moneyValue(java.lang.Object object)
          Returns a Money object for the given object in the default locale.
 java.lang.Object moneyValue(java.lang.Object object, java.util.Locale locale)
          Returns a Money object for the given object in the given locale.
 java.lang.Object moneyValue(java.lang.Object object, java.lang.Object currency)
          Returns a Money object for the given object in the default locale.
 java.lang.Object moneyValue(java.lang.Object object, java.lang.Object currency, java.util.Locale locale)
          Returns a Money object for the given object using the given locale.
 java.lang.Object parseMoney(java.lang.String string, java.lang.Object currency)
          Parses the given string as a money with the appropriate currency.
 java.lang.Object parseMoney(java.lang.String moneyString, java.lang.Object currency, java.util.Locale locale)
          Takes a string and returns a money object in the given currency.
 java.lang.Object parseMoney(java.lang.String moneyString, java.lang.Object currency, java.util.Locale locale, java.lang.String suffix)
           
 DecimalParseInfo parseMoneyNumber(java.lang.String string, java.util.Locale locale)
          Parses the specified String in the specified Locale.
 DecimalParseInfo parseMoneyNumber(java.lang.String string, java.util.Locale locale, boolean suffix)
          Parses the specified String in the specified Locale.
 java.lang.Object quickCompareValue(java.lang.Object money, java.lang.Object previous)
          Computes a BigDecimal value for a given Money object.
 void setAppendSuffix(boolean appendSuffix)
           
 void sleep()
          Clean up formatter's state
 boolean stringIsTooLong(java.lang.String moneyString)
          Returns true if this moneyString has too many digits.
 boolean stringIsTooLong(java.lang.String moneyString, boolean insertingAfterDecimal, int digitsToInsert)
          Checks if the money string has too many digits given the size of our money representation.
static java.lang.String stringValueInCurrency(java.lang.Object money, java.lang.Object forcedCurrency)
          Returns a string value for the money object in the given currency.
 java.lang.String stringValueInCurrency(java.lang.Object money, java.lang.Object forcedCurrency, boolean suffix)
          Returns a string value for this money converted into the currency forced.
 
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, registerFormatter
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EuroSymbol

public static final java.lang.String EuroSymbol
The Euro currency prefix symbol

See Also:
Constant Field Values

EuroUniqueName

public static final java.lang.String EuroUniqueName
ISO suffix and unique name for the Euro currency

See Also:
Constant Field Values

ParameterDisplayEuroSymbol

public static final java.lang.String ParameterDisplayEuroSymbol
Parameter for turning on the display of the Euro symbol

See Also:
Constant Field Values

DefaultPrecision

public static final int DefaultPrecision
See Also:
Constant Field Values
Constructor Detail

GenericMoneyFormatter

public GenericMoneyFormatter(ariba.ui.validation.GenericMoneyFormatter.MoneyAdapter moneyAdapter)
Create a new MoneyFormatter.

Method Detail

getEscapedStringValue

public java.lang.String getEscapedStringValue(java.lang.Object object)
Returns an HTML-escaped, formatted string for this Money object. This method is useful for formatting Euro currencies for HTML display.

Parameters:
object - The Money object to be formatted.
Returns:
An HTML-escaped, formatted string for this Money object. This method is useful for formatting Euro currencies for HTML display.

getEscapedStringValue

public java.lang.String getEscapedStringValue(java.lang.Object object,
                                              java.util.Locale locale)
Returns an HTML-escaped, formatted string for this Money object. The money is forced into the format of that locale. Currency remains the same. This method is useful for formatting Euro currencies for HTML display.

Parameters:
object - The Money object to be formatted.
locale - The Locale to be used in the formatting of object.
Returns:
An HTML-escaped, formatted string for this Money object. This method is useful for formatting Euro currencies for HTML display.

getDefaultStringValue

public java.lang.String getDefaultStringValue(java.lang.Object object)
Returns a formatted string for the given Money object.

Parameters:
object - The Money object to be formatted.
Returns:
A formatted string for the given Money object.

getStringValue

public java.lang.String getStringValue(java.lang.Object object,
                                       boolean suffix)
Returns a formatted string for the given Money object Turn on/off the suffix with suffix flag

Parameters:
object - The Money object to be formatted.
suffix - Determines if the suffix should be in the return value
Returns:
A formatted string for the given Money object.

getDefaultStringValue

public java.lang.String getDefaultStringValue(java.lang.Object object,
                                              java.util.Locale locale)
Returns a formatted string for this Money object. The money is forced into the format of that locale. Currency remains the same.

Parameters:
object - The Money object to be formatted.
locale - The Locale to be used in the formatting of object.
Returns:
A formatted string for the given Money object.

getStringValue

public java.lang.String getStringValue(java.lang.Object object,
                                       java.util.Locale locale,
                                       boolean suffix)
Returns a formatted string for this Money object. The money is forced into the format of that locale. Currency remains the same. Turn on/off the suffix with suffix flag

Parameters:
object - The Money object to be formatted.
locale - The Locale to be used in the formatting of object.
suffix - Used to determine if the suffix should be in the return value
Returns:
A formatted string for the given Money object.

getStringValue

public java.lang.String getStringValue(java.lang.Object money,
                                       java.lang.String euroPrefix,
                                       boolean suffix)
Returns a formatted string for this Money object in the default locale. If euroPrefix is non-null, we will always add the prefix string as the Euro currency's prefix. If suffix is true, we will generate the suffix.

Parameters:
money - The Money object to be formatted.
euroPrefix - The prefix to be added as the Euro currency's prefix
suffix - Used to determine if the suffix should be in the return value
Returns:
A formatted string for the given Money object.

getStringValue

public java.lang.String getStringValue(java.lang.Object money,
                                       java.util.Locale locale,
                                       java.lang.String euroPrefix,
                                       boolean suffix)
Returns a formatted string for this Money object in the given locale. If euroPrefix is non-null, we will always add the prefix string as the Euro currency's prefix. If suffix is true, we will generate the suffix.

Parameters:
money - The Money object to be formatted.
locale - The Locale to be used in the formatting of object.
euroPrefix - The prefix to be added as the Euro
suffix - Used to determine if the suffix should be in the return value
Returns:
A formatted string for the given Money object.

getStringValue

public java.lang.String getStringValue(java.lang.Object money,
                                       java.util.Locale locale,
                                       java.lang.String euroPrefix,
                                       boolean suffix,
                                       int precision)
Returns a formatted string for this Money object in the given locale. If euroPrefix is non-null, we will always add the prefix string as the Euro currency's prefix. If suffix is true, we will generate the suffix.

Parameters:
money - The Money object to be formatted.
locale - The Locale to be used in the formatting of object.
euroPrefix - The prefix to be added as the Euro
suffix - Used to determine if the suffix should be in the return value
precision - The precision to be used when rounding the string.
Returns:
A formatted string for the given Money object.

getStringValue

public static java.lang.String getStringValue(java.math.BigDecimal amount,
                                              java.lang.Object currency,
                                              java.util.Locale locale,
                                              java.lang.String euroPrefix,
                                              boolean suffix,
                                              int precision)
Returns a formatted string based on a given amount and currency in the given locale. If euroPrefix is non-null, we will always add the prefix string as the Euro currency's prefix. If suffix is true, we will generate the suffix.

Parameters:
amount - A BigDecimal object representing a monetary amount
currency - A Currency object representing a monetary currency
locale - The Locale to be used in the formatting of object.
euroPrefix - The prefix to be added as the Euro
suffix - Used to determine if the suffix should be in the return value
precision - The precision to be used when rounding the string.
Returns:
A formatted string for the given Money object.

getCurrency

public java.lang.Object getCurrency(java.lang.Object money)
Get the currency for the money. Could be overridden to return reporting currency or basecurrency

Parameters:
money - The Money object containing the Currency.
Returns:
The currency for the specified Money object.

getAmount

public static java.math.BigDecimal getAmount(java.lang.Object money)
Get the amount for the money. Could be overridden to return reporting amount or base amount

Parameters:
money - The Money object containing the amount.
Returns:
The amount for the specified Money object.

dualStringValue

public static java.lang.String dualStringValue(java.lang.Object money,
                                               java.lang.Object alternate)
Returns a string value for the money object in two currencies, its default currency and the alternate currency.

Parameters:
money - The Money object to be formatted.
alternate - The second Currency to be used in the formatting of the Money object.
Returns:
A formatted string for the given Money object in two currencies.

stringValueInCurrency

public static java.lang.String stringValueInCurrency(java.lang.Object money,
                                                     java.lang.Object forcedCurrency)
Returns a string value for the money object in the given currency.

Parameters:
money - The Money object to be formatted.
forcedCurrency - The Currency to be used in the formatting of the Money object.
Returns:
A formatted string for the given Money object in the specified Currency.

stringValueInCurrency

public java.lang.String stringValueInCurrency(java.lang.Object money,
                                              java.lang.Object forcedCurrency,
                                              boolean suffix)
Returns a string value for this money converted into the currency forced. Turn on/off the suffix with suffix boolean.

Parameters:
money - The Money object to be formatted.
forcedCurrency - The Currency to be used in the formatting of the Money object.
suffix - Determines if the suffix should be in the return value
Returns:
A formatted string for the given Money object in the specified Currency.

displayEuroSymbol

public static boolean displayEuroSymbol()
Returns the value of the DisplayEuroSymbol parameter.

Returns:
The value of the DisplayEuroSymbol parameter.

getValue

public java.lang.Object getValue(java.lang.Object object,
                                 java.util.Locale locale)
Returns a new Money object for the given object.

Specified by:
getValue in class Formatter
Parameters:
object - The Object to be parsed.
locale - The Locale to be used in parsing object.
Returns:
A Money object for the given object in the specified locale.

moneyValue

public java.lang.Object moneyValue(java.lang.Object object)
Returns a Money object for the given object in the default locale. If object is not a Money object, it is converted to a string and parsed as a currency string. If there is a problem parsing the string, or if the Money object is null, returns null.

Parameters:
object - The Object to be parsed.
Returns:
A Money object for the given object in the default locale.

moneyValue

public java.lang.Object moneyValue(java.lang.Object object,
                                   java.util.Locale locale)
Returns a Money object for the given object in the given locale. If object is not a Money object, it is converted to a string and parsed as a currency string. If there is a problem parsing the string, or if the Money object is null, returns null.

Parameters:
object - The Object to be parsed.
locale - The Locale to be used in parsing object.
Returns:
A Money object for the given object in the specified locale.

moneyValue

public java.lang.Object moneyValue(java.lang.Object object,
                                   java.lang.Object currency)
Returns a Money object for the given object in the default locale. If object is not a Money object, it is converted to a string and parsed as a currency string. If there is a problem parsing the string, or if the Money object is null, returns null. If the object doesn't specify a currency, then the currency parameter will be used. If currency is also null, then null is returned.

Parameters:
object - The Object to be parsed.
currency - The Currency to be used in parsing object.
Returns:
A Money object for the given object in the default locale.

moneyValue

public java.lang.Object moneyValue(java.lang.Object object,
                                   java.lang.Object currency,
                                   java.util.Locale locale)
Returns a Money object for the given object using the given locale. If locale is null, we use the default locale for parsing. If object is not a Money object, it is converted to a string and parsed as a currency string. If there is a problem parsing the string, or if the Money object is null, returns null. If the object doesn't specify a currency, then the currency parameter will be used. If currency is also null, then null will be returned.

Parameters:
object - The Object to be parsed.
currency - The Currency to be used in parsing object.
locale - The Locale to be used in parsing object.
Returns:
A Money object for the given object in the specified currency and locale.

parseMoney

public java.lang.Object parseMoney(java.lang.String string,
                                   java.lang.Object currency)
                            throws java.text.ParseException
Parses the given string as a money with the appropriate currency.

Parameters:
string - The String object to be parsed.
currency - The Currency object to be used in the parsing of the String.
Returns:
A Money object represented by the String.
Throws:
java.text.ParseException

parseMoney

public java.lang.Object parseMoney(java.lang.String moneyString,
                                   java.lang.Object currency,
                                   java.util.Locale locale)
                            throws java.text.ParseException
Takes a string and returns a money object in the given currency.

Parameters:
moneyString - The string to parse into a Money.
currency - The currency the Money object should be in.
locale - The Locale to assume when parsing.
Returns:
a new Money object.
Throws:
java.text.ParseException

parseMoney

public java.lang.Object parseMoney(java.lang.String moneyString,
                                   java.lang.Object currency,
                                   java.util.Locale locale,
                                   java.lang.String suffix)
                            throws java.text.ParseException
Throws:
java.text.ParseException

isMoney

public boolean isMoney(java.lang.String moneyString)
Is this string in valid money format? Use the default locale for parsing.

Parameters:
moneyString - The String object to be parsed.
Returns:
true if the moneyString represents a Money object in the default Locale.

isMoney

public boolean isMoney(java.lang.String moneyString,
                       java.util.Locale locale)
Is this string a valid money format for this locale?

Parameters:
moneyString - The String object to be parsed.
locale - The Locale to assume when parsing.
Returns:
true if the moneyString represents a Money object in the specified Locale.

stringIsTooLong

public boolean stringIsTooLong(java.lang.String moneyString)
Returns true if this moneyString has too many digits.

Parameters:
moneyString - The string to check.
Returns:
true if this moneyString has too many digits.

stringIsTooLong

public boolean stringIsTooLong(java.lang.String moneyString,
                               boolean insertingAfterDecimal,
                               int digitsToInsert)
Checks if the money string has too many digits given the size of our money representation.

Parameters:
moneyString - The string to check.
insertingAfterDecimal - True if the user is inserting digits after the decimal point.
digitsToInsert - The number of digits are going to be inserted into the money string. This parameter is added to the existing digit count to see if we exceed size limits.
Returns:
true if this moneyString has too many digits given the size of the money representation

moneyInfo

public DecimalParseInfo moneyInfo(java.lang.String moneyString)
                           throws java.text.ParseException
Parses the money string to generate some information about the number of digits and the location of the decimal separator (among other things).

Parameters:
moneyString - The String object to be parsed.
Returns:
information about the number of digits and the location of the decimal separator (among other things).
Throws:
java.text.ParseException

parseMoneyNumber

public DecimalParseInfo parseMoneyNumber(java.lang.String string,
                                         java.util.Locale locale)
                                  throws java.text.ParseException
Parses the specified String in the specified Locale.

Parameters:
string - The String object to be parsed.
locale - The Locale object to be used in parsing string.
Returns:
A DecimalParseInfo object containing the Decimal info for the specified String.
Throws:
java.text.ParseException

parseMoneyNumber

public DecimalParseInfo parseMoneyNumber(java.lang.String string,
                                         java.util.Locale locale,
                                         boolean suffix)
                                  throws java.text.ParseException
Parses the specified String in the specified Locale.

Parameters:
string - The String object to be parsed.
locale - The Locale object to be used in parsing string.
suffix -
Returns:
A DecimalParseInfo object containing the Decimal info for the specified String.
Throws:
java.text.ParseException

quickCompareValue

public java.lang.Object quickCompareValue(java.lang.Object money,
                                          java.lang.Object previous)
Computes a BigDecimal value for a given Money object. The previous argument is used to make sure that all amounts returned are expressed in terms of the same currency. Note: this should be fixed to always convert into the base currency.

Overrides:
quickCompareValue in class Formatter
Parameters:
money - The Money object to be computed.
previous - The Money object whose currency will be used to compute the return value.
Returns:
The BigDecimal value for the given Money object.

compareMoneys

public int compareMoneys(java.lang.Object m1,
                         java.lang.Object m2)
Compares two money values in the default locale. Returns a value less than, equal to, or greater than zero depending on whether m1 is less than, equal to, or greater than m2. The currency of m2 is converted to that of m1 if they're not already the same.

Parameters:
m1 - The first Money object to be compared
m2 - The second Object object to be compared
Returns:
A value less than, equal to, or greater than zero depending on whether m1 is less than, equal to, or greater than m2.

compareMoneys

public int compareMoneys(java.lang.Object m1,
                         java.lang.Object m2,
                         boolean round)
Compares two money values in the default locale. Returns a value less than, equal to, or greater than zero depending on whether m1 is less than, equal to, or greater than m2. The currency of m2 is converted to that of m1 if they're not already the same. If round is set to true, the money amounts will be rounded to the default precision of their currencies before the comparison is made.

Parameters:
m1 - The first Money object to be compared
m2 - The second Money object to be compared
round - Determines if the money amounts will be rounded before the comparison is made.
Returns:
A value less than, equal to, or greater than zero depending on whether m1 is less than, equal to, or greater than m2.

compareMoneys

public int compareMoneys(java.lang.Object m1,
                         java.lang.Object m2,
                         boolean round,
                         java.util.Locale locale)
Compares two money values in the given locale. Returns a value less than, equal to, or greater than zero depending on whether m1 is less than, equal to, or greater than m2. The currency of m2 is converted to that of m1 if they're not already the same. If round is set to true, the money amounts will be rounded to the default precision of their currencies before the comparison is made. The locale parameter is currently ignored.

Parameters:
m1 - The first Money object to be compared
m2 - The second Money object to be compared
round - Determines if the money amounts will be rounded before the comparison is made.
locale - This parameter is currently ignored.
Returns:
A value less than, equal to, or greater than zero depending on whether m1 is less than, equal to, or greater than m2. Returns zero if the two objects are if both are null. Otherwise, arbitrarily returns -1 if the first object is null, or 1 if the second is null.

sleep

public void sleep()
Clean up formatter's state


appendSuffix

public boolean appendSuffix()

setAppendSuffix

public void setAppendSuffix(boolean appendSuffix)


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