|
|||||||||
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 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 |
---|
public static final java.lang.String EuroSymbol
public static final java.lang.String EuroUniqueName
public static final java.lang.String ParameterDisplayEuroSymbol
public static final int DefaultPrecision
Constructor Detail |
---|
public GenericMoneyFormatter(ariba.ui.validation.GenericMoneyFormatter.MoneyAdapter moneyAdapter)
MoneyFormatter
.
Method Detail |
---|
public java.lang.String getEscapedStringValue(java.lang.Object object)
object
- The Money
object to be formatted.
public java.lang.String getEscapedStringValue(java.lang.Object object, java.util.Locale locale)
object
- The Money
object to be formatted.locale
- The Locale
to be used in the
formatting of object
.
public java.lang.String getDefaultStringValue(java.lang.Object object)
object
.
object
- The Money
object to be formatted.
object
.public java.lang.String getStringValue(java.lang.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 java.lang.String getDefaultStringValue(java.lang.Object object, java.util.Locale locale)
object
- The Money
object to be formatted.locale
- The Locale
to be used in the
formatting of object
.
object
.public java.lang.String getStringValue(java.lang.Object object, java.util.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 java.lang.String getStringValue(java.lang.Object money, java.lang.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 java.lang.String getStringValue(java.lang.Object money, java.util.Locale locale, java.lang.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 java.lang.String getStringValue(java.lang.Object money, java.util.Locale locale, java.lang.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 java.lang.String getStringValue(java.math.BigDecimal amount, java.lang.Object currency, java.util.Locale locale, java.lang.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 java.lang.Object getCurrency(java.lang.Object money)
money
- The Money
object containing the
Currency
.
Money
object.public static java.math.BigDecimal getAmount(java.lang.Object money)
money
- The Money
object containing the
amount.
Money
object.public static java.lang.String dualStringValue(java.lang.Object money, java.lang.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 java.lang.String stringValueInCurrency(java.lang.Object money, java.lang.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 java.lang.String stringValueInCurrency(java.lang.Object money, java.lang.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 java.lang.Object getValue(java.lang.Object object, java.util.Locale locale)
object
.
getValue
in class Formatter
object
- The Object
to be parsed.locale
- The Locale
to be used in parsing
object
.
object
in
the specified locale.public java.lang.Object moneyValue(java.lang.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 java.lang.Object moneyValue(java.lang.Object object, java.util.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 java.lang.Object moneyValue(java.lang.Object object, java.lang.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 java.lang.Object moneyValue(java.lang.Object object, java.lang.Object currency, java.util.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 java.lang.Object parseMoney(java.lang.String string, java.lang.Object currency) throws java.text.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
.
java.text.ParseException
public java.lang.Object parseMoney(java.lang.String moneyString, java.lang.Object currency, java.util.Locale locale) throws java.text.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.
java.text.ParseException
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
java.text.ParseException
public boolean isMoney(java.lang.String moneyString)
moneyString
- The String
object to be parsed.
moneyString
represents a
Money
object in the default Locale
.public boolean isMoney(java.lang.String moneyString, java.util.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(java.lang.String moneyString)
moneyString
has too many digits.
moneyString
- The string to check.
moneyString
has too many digits.public boolean stringIsTooLong(java.lang.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 representationpublic DecimalParseInfo moneyInfo(java.lang.String moneyString) throws java.text.ParseException
moneyString
- The String
object to be parsed.
java.text.ParseException
public DecimalParseInfo parseMoneyNumber(java.lang.String string, java.util.Locale locale) throws java.text.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
.
java.text.ParseException
public DecimalParseInfo parseMoneyNumber(java.lang.String string, java.util.Locale locale, boolean suffix) throws java.text.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
.
java.text.ParseException
public java.lang.Object quickCompareValue(java.lang.Object money, java.lang.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 Formatter
money
- 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(java.lang.Object m1, java.lang.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(java.lang.Object m1, java.lang.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(java.lang.Object m1, java.lang.Object m2, boolean round, java.util.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 |