|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectariba.util.formatter.Formatter
ariba.ui.validation.GenericMoneyFormatter
public class GenericMoneyFormatter
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 String |
EuroSymbol
The Euro currency prefix symbol |
static String |
EuroUniqueName
ISO suffix and unique name for the Euro currency |
static 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(Object m1,
Object m2)
Compares two money values in the default locale. |
int |
compareMoneys(Object m1,
Object m2,
boolean round)
Compares two money values in the default locale. |
int |
compareMoneys(Object m1,
Object m2,
boolean round,
Locale locale)
Compares two money values in the given locale. |
static boolean |
displayEuroSymbol()
Returns the value of the DisplayEuroSymbol parameter. |
static String |
dualStringValue(Object money,
Object alternate)
Returns a string value for the money object in two currencies, its default currency and the alternate currency. |
static BigDecimal |
getAmount(Object money)
Get the amount for the money. |
Object |
getCurrency(Object money)
Get the currency for the money. |
String |
getDefaultStringValue(Object object)
Returns a formatted string for the given Money object. |
String |
getDefaultStringValue(Object object,
Locale locale)
Returns a formatted string for this Money object. |
String |
getEscapedStringValue(Object object)
Returns an HTML-escaped, formatted string for this Money object. |
String |
getEscapedStringValue(Object object,
Locale locale)
Returns an HTML-escaped, formatted string for this Money object. |
static String |
getStringValue(BigDecimal amount,
Object currency,
Locale locale,
String euroPrefix,
boolean suffix,
int precision)
Returns a formatted string based on a given amount and currency in the given locale. |
String |
getStringValue(Object object,
boolean suffix)
Returns a formatted string for the given Money object
Turn on/off the suffix with suffix flag |
String |
getStringValue(Object object,
Locale locale,
boolean suffix)
Returns a formatted string for this Money object. |
String |
getStringValue(Object money,
Locale locale,
String euroPrefix,
boolean suffix)
Returns a formatted string for this Money object in the given locale. |
String |
getStringValue(Object money,
Locale locale,
String euroPrefix,
boolean suffix,
int precision)
Returns a formatted string for this Money object in the given locale. |
String |
getStringValue(Object money,
String euroPrefix,
boolean suffix)
Returns a formatted string for this Money object in the default locale. |
Object |
getValue(Object object,
Locale locale)
Returns a new Money object for the given object. |
boolean |
isMoney(String moneyString)
Is this string in valid money format? Use the default locale for parsing. |
boolean |
isMoney(String moneyString,
Locale locale)
Is this string a valid money format for this locale? |
DecimalParseInfo |
moneyInfo(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). |
Object |
moneyValue(Object object)
Returns a Money object for the given object in
the default locale. |
Object |
moneyValue(Object object,
Locale locale)
Returns a Money object for the given object in
the given locale. |
Object |
moneyValue(Object object,
Object currency)
Returns a Money object for the given object in
the default locale. |
Object |
moneyValue(Object object,
Object currency,
Locale locale)
Returns a Money object for the given object using
the given locale. |
Object |
parseMoney(String string,
Object currency)
Parses the given string as a money with the appropriate
currency. |
Object |
parseMoney(String moneyString,
Object currency,
Locale locale)
Takes a string and returns a money object in the
given currency. |
Object |
parseMoney(String moneyString,
Object currency,
Locale locale,
String suffix)
|
DecimalParseInfo |
parseMoneyNumber(String string,
Locale locale)
Parses the specified String in the specified
Locale. |
DecimalParseInfo |
parseMoneyNumber(String string,
Locale locale,
boolean suffix)
Parses the specified String in the specified
Locale. |
Object |
quickCompareValue(Object money,
Object previous)
Computes a BigDecimal value for a given Money object. |
void |
setAppendSuffix(boolean appendSuffix)
|
void |
sleep()
Clean up formatter's state |
boolean |
stringIsTooLong(String moneyString)
Returns true if this moneyString has too many digits. |
boolean |
stringIsTooLong(String moneyString,
boolean insertingAfterDecimal,
int digitsToInsert)
Checks if the money string has too many digits given the size of our money representation. |
static String |
stringValueInCurrency(Object money,
Object forcedCurrency)
Returns a string value for the money object in the given currency. |
String |
stringValueInCurrency(Object money,
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, 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 |
|---|
public static final String EuroSymbol
public static final String EuroUniqueName
public static final String ParameterDisplayEuroSymbol
public static final int DefaultPrecision
| Constructor Detail |
|---|
public GenericMoneyFormatter(ariba.ui.validation.GenericMoneyFormatter.MoneyAdapter moneyAdapter)
MoneyFormatter.
| Method Detail |
|---|
public String getEscapedStringValue(Object object)
object - The Money object to be formatted.
public String getEscapedStringValue(Object object,
Locale locale)
object - The Money object to be formatted.locale - The Locale to be used in the
formatting of object.
public String getDefaultStringValue(Object object)
object.
object - The Money object to be formatted.
object.
public String getStringValue(Object object,
boolean suffix)
object
Turn on/off the suffix with suffix flag
object - The Money object to be formatted.suffix - Determines if the suffix should be in the return
value
object.
public String getDefaultStringValue(Object object,
Locale locale)
object - The Money object to be formatted.locale - The Locale to be used in the
formatting of object.
object.
public String getStringValue(Object object,
Locale locale,
boolean suffix)
suffix
flag
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
object.
public String getStringValue(Object money,
String euroPrefix,
boolean suffix)
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.
money - The Money object to be formatted.euroPrefix - The prefix to be added as the Euro
currency's prefixsuffix - Used to determine if the suffix should be in the
return value
object.
public String getStringValue(Object money,
Locale locale,
String euroPrefix,
boolean suffix)
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.
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 Eurosuffix - Used to determine if the suffix should be in the
return value
object.
public String getStringValue(Object money,
Locale locale,
String euroPrefix,
boolean suffix,
int precision)
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.
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 Eurosuffix - Used to determine if the suffix should be in the
return valueprecision - The precision to be used when rounding the string.
public static String getStringValue(BigDecimal amount,
Object currency,
Locale locale,
String euroPrefix,
boolean suffix,
int precision)
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.
amount - A BigDecimal object representing a monetary amountcurrency - A Currency object representing a monetary currencylocale - The Locale to be used in the
formatting of object.euroPrefix - The prefix to be added as the Eurosuffix - Used to determine if the suffix should be in the
return valueprecision - The precision to be used when rounding the string.
public Object getCurrency(Object money)
money - The Money object containing the
Currency.
Money
object.public static BigDecimal getAmount(Object money)
money - The Money object containing the
amount.
Money
object.
public static String dualStringValue(Object money,
Object alternate)
alternate currency.
money - The Money object to be formatted.alternate - The second Currency to be used
in the formatting of the Money object.
Money
object in two currencies.
public static String stringValueInCurrency(Object money,
Object forcedCurrency)
money - The Money object to be formatted.forcedCurrency - The Currency to be used in the
formatting of the Money object.
Money
object in the specified Currency.
public String stringValueInCurrency(Object money,
Object forcedCurrency,
boolean suffix)
money converted into
the currency forced. Turn on/off the suffix with
suffix boolean.
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
Money
object in the specified Currency.public static boolean displayEuroSymbol()
public Object getValue(Object object,
Locale locale)
object.
getValue in class Formatterobject - The Object to be parsed.locale - The Locale to be used in parsing
object.
object in
the specified locale.public Object moneyValue(Object object)
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.
object - The Object to be parsed.
object in
the default locale.
public Object moneyValue(Object object,
Locale locale)
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.
object - The Object to be parsed.locale - The Locale to be used in parsing
object.
object in
the specified locale.
public Object moneyValue(Object object,
Object currency)
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.
object - The Object to be parsed.currency - The Currency to be used in
parsing object.
object in
the default locale.
public Object moneyValue(Object object,
Object currency,
Locale locale)
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.
object - The Object to be parsed.currency - The Currency to be used in
parsing object.locale - The Locale to be used in parsing
object.
object in
the specified currency and locale.
public Object parseMoney(String string,
Object currency)
throws ParseException
string as a money with the appropriate
currency.
string - The String object to be parsed.currency - The Currency object to be used in
the parsing of the String.
Money object represented by the
String.
ParseException
public Object parseMoney(String moneyString,
Object currency,
Locale locale)
throws ParseException
money object in the
given currency.
moneyString - The string to parse into a
Money.currency - The currency the Money object
should be in.locale - The Locale to assume when parsing.
Money object.
ParseException
public Object parseMoney(String moneyString,
Object currency,
Locale locale,
String suffix)
throws ParseException
ParseExceptionpublic boolean isMoney(String moneyString)
moneyString - The String object to be parsed.
moneyString represents a
Money object in the default Locale.
public boolean isMoney(String moneyString,
Locale locale)
locale?
moneyString - The String object to be parsed.locale - The Locale to assume when parsing.
moneyString represents a
Money object in the specified Locale.public boolean stringIsTooLong(String moneyString)
moneyString has too many digits.
moneyString - The string to check.
moneyString has too many digits.
public boolean stringIsTooLong(String moneyString,
boolean insertingAfterDecimal,
int digitsToInsert)
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.
moneyString has too many
digits given the size of the money representation
public DecimalParseInfo moneyInfo(String moneyString)
throws ParseException
moneyString - The String object to be parsed.
ParseException
public DecimalParseInfo parseMoneyNumber(String string,
Locale locale)
throws ParseException
String in the specified
Locale.
string - The String object to be parsed.locale - The Locale object to be used in
parsing string.
DecimalParseInfo object containing the
Decimal info for the specified String.
ParseException
public DecimalParseInfo parseMoneyNumber(String string,
Locale locale,
boolean suffix)
throws ParseException
String in the specified
Locale.
string - The String object to be parsed.locale - The Locale object to be used in
parsing string.suffix -
DecimalParseInfo object containing the
Decimal info for the specified String.
ParseException
public Object quickCompareValue(Object money,
Object previous)
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.
quickCompareValue in class Formattermoney - The Money object to be computed.previous - The Money object whose currency
will be used to compute the return value.
BigDecimal value for the given
Money object.
public int compareMoneys(Object m1,
Object m2)
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.
m1 - The first Money object to be comparedm2 - The second Object object to be compared
m1 is less than, equal to,
or greater than m2.
public int compareMoneys(Object m1,
Object m2,
boolean round)
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.
m1 - The first Money object to be comparedm2 - The second Money object to be comparedround - Determines if the money amounts will be rounded
before the comparison is made.
m1 is less than, equal to,
or greater than m2.
public int compareMoneys(Object m1,
Object m2,
boolean round,
Locale locale)
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.
m1 - The first Money object to be comparedm2 - The second Money object to be comparedround - Determines if the money amounts will be rounded
before the comparison is made.locale - This parameter is currently ignored.
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.public void sleep()
public boolean appendSuffix()
public void setAppendSuffix(boolean appendSuffix)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||