I had to expand on the Money class for one of the projects I'm involved with. I hope others will find these enhancements useful. (And if not, I hope to get feedback as to why not.) In general, this patch adds:
- Enhanced formatting of monetary amounts (e.g. negative 1,500.75 USD is formatted as "$-1,500.75" if rendered in the US, but the same amount is formatted as "-1.500,00 USD" if rendered in a European locale).
- Parsing of monetary amounts (back) from strings such as shown above, with allowance for things like the use of parenthesis for enclosing negative amounts instead of a minus sign, and the (superflous) use of both a dollar sign symbol and the "USD" code.
- Some small, corresponding changes to the Money class itself.
Specifcally, this path includes:
1. A new MoneyLocalizer class that parses and renders formatted monetary amounts with respect to a given locale (or the default locale).
2. The addition of a Money(String) constructor (that uses the MoneyLocalizer.parseString function against the default locale).
3. Changed the two Money.toString() functions to use the MoneyLocalizer.formatString() method (against the default locale).
4. The new MoneyLocalizer utility class was placed in a new "moneyutil" package was so that TimeAndMoneyDomainClassFilter could easily exempt it from the automated unit testing of persistable objects.
See the JavaDocs and unit tests for details.
A patch for the Money class