@@ -31,6 +31,10 @@ public class ConfigurableCurrencyUnitProvider extends BaseCurrencyProviderSpi {
3131 * The currency units, identified by currency code.
3232 */
3333 private static final Map <String , CurrencyUnit > currencyUnits = new ConcurrentHashMap <>();
34+ /**
35+ * The currency units, identified by numeric code.
36+ */
37+ private static final Map <Integer , CurrencyUnit > currencyUnitsByNumericCode = new ConcurrentHashMap <>();
3438 /**
3539 * The currency units identified by Locale.
3640 */
@@ -65,19 +69,33 @@ public Set<CurrencyUnit> getCurrencies(CurrencyQuery currencyQuery) {
6569 }
6670 return result ;
6771 }
72+ if (!currencyQuery .getNumericCodes ().isEmpty ()) {
73+ for (Integer numericCode : currencyQuery .getNumericCodes ()) {
74+ CurrencyUnit cu = currencyUnitsByNumericCode .get (numericCode );
75+ if (cu != null ) {
76+ result .add (cu );
77+ }
78+ }
79+ return result ;
80+ }
6881 result .addAll (currencyUnits .values ());
6982 return result ;
7083 }
7184
7285 /**
73- * Registers a bew currency unit under its currency code.
86+ * Registers a bew currency unit under its currency code and potentially numeric code .
7487 *
7588 * @param currencyUnit the new currency to be registered, not null.
7689 * @return any unit instance registered previously by this instance, or null.
7790 */
7891 public static CurrencyUnit registerCurrencyUnit (CurrencyUnit currencyUnit ) {
7992 Objects .requireNonNull (currencyUnit );
80- return ConfigurableCurrencyUnitProvider .currencyUnits .put (currencyUnit .getCurrencyCode (), currencyUnit );
93+ CurrencyUnit registered = ConfigurableCurrencyUnitProvider .currencyUnits .put (currencyUnit .getCurrencyCode (), currencyUnit );
94+ int numericCode = currencyUnit .getNumericCode ();
95+ if (numericCode != -1 ) {
96+ ConfigurableCurrencyUnitProvider .currencyUnitsByNumericCode .put (numericCode , currencyUnit );
97+ }
98+ return registered ;
8199 }
82100
83101 /**
@@ -101,7 +119,14 @@ public static CurrencyUnit registerCurrencyUnit(CurrencyUnit currencyUnit, Local
101119 */
102120 public static CurrencyUnit removeCurrencyUnit (String currencyCode ) {
103121 Objects .requireNonNull (currencyCode );
104- return ConfigurableCurrencyUnitProvider .currencyUnits .remove (currencyCode );
122+ CurrencyUnit removed = ConfigurableCurrencyUnitProvider .currencyUnits .remove (currencyCode );
123+ if (removed != null ) {
124+ int numericCode = removed .getNumericCode ();
125+ if (numericCode != -1 ) {
126+ ConfigurableCurrencyUnitProvider .currencyUnitsByNumericCode .remove (numericCode );
127+ }
128+ }
129+ return removed ;
105130 }
106131
107132 /**
@@ -122,8 +147,9 @@ public static CurrencyUnit removeCurrencyUnit(Locale locale) {
122147 */
123148 @ Override
124149 public String toString () {
125- return "ConfigurableCurrencyUnitProvider [currencyUnits=" + currencyUnits + ", currencyUnitsByLocale=" +
126- currencyUnitsByLocale + ']' ;
150+ return "ConfigurableCurrencyUnitProvider [currencyUnits=" + currencyUnits
151+ + ", currencyUnitsByNumericCode=" + currencyUnitsByNumericCode
152+ + ", currencyUnitsByLocale=" + currencyUnitsByLocale + ']' ;
127153 }
128154
129155}
0 commit comments