Permalink
Browse files

Allow registration of currencies by application code

Fixes #17
  • Loading branch information...
1 parent 20fc0cd commit 6be9b4e947d4e849e12d553ded18c0b8d868e211 @jodastephen jodastephen committed Apr 19, 2013
Showing with 15 additions and 4 deletions.
  1. +1 −1 RELEASE-NOTES.txt
  2. +5 −0 src/changes/changes.xml
  3. +9 −3 src/main/java/org/joda/money/CurrencyUnit.java
View
@@ -4,7 +4,7 @@ Joda-Money
Joda-Money is a monetary library that fills the gap in the JDK
by providing a Money class and associated formatting.
-This is release 0.8 of Joda-Money.
+This is release 0.8.1 of Joda-Money.
The release runs on JDK 6 or later.
View
@@ -8,6 +8,11 @@
<body>
<!-- types are add, fix, remove, update -->
+ <release version="0.8.1" date="" description="Version 0.8.1">
+ <action dev="scolebourne" type="add">
+ Allow registration of currencies by application code [17]
+ </action>
+ </release>
<release version="0.8" date="2013-01-30" description="Version 0.8">
<action dev="scolebourne" type="update" >
Change to requiring JDK 1.6.
@@ -127,17 +127,22 @@
* Registers a currency allowing it to be used.
* <p>
* This class only permits known currencies to be returned.
- * To achieve this, all currencies have to be registered in advance, at
- * application startup.
+ * To achieve this, all currencies have to be registered in advance.
+ * <p>
+ * Since this method is public, it is possible to add currencies in
+ * application code. It is recommended to do this only at startup, however
+ * it is safe to do so later as the internal implementation is thread-safe.
*
* @param currencyCode the currency code, not null
* @param numericCurrencyCode the numeric currency code, -1 if none
* @param decimalPlaces the number of decimal places that the currency
* normally has, from 0 to 9 (normally 0, 2 or 3), or -1 for a pseudo-currency
* @param countryCodes the country codes to register the currency under, not null
* @return the new instance, never null
+ * @throws IllegalArgumentException if the code is already registered, or the
+ * specified data is invalid
*/
- static synchronized CurrencyUnit registerCurrency(
+ public static synchronized CurrencyUnit registerCurrency(
String currencyCode, int numericCurrencyCode, int decimalPlaces, List<String> countryCodes) {
MoneyUtils.checkNotNull(currencyCode, "Currency code must not be null");
if (numericCurrencyCode < -1 || numericCurrencyCode > 999) {
@@ -190,6 +195,7 @@ static synchronized CurrencyUnit registerCurrency(
*
* @param currency the currency, not null
* @return the singleton instance, never null
+ * @throws IllegalCurrencyException if the currency is unknown
*/
public static CurrencyUnit of(Currency currency) {
MoneyUtils.checkNotNull(currency, "Currency must not be null");

0 comments on commit 6be9b4e

Please sign in to comment.