Currency#getInstance(String theISOCode) to validate the input currency code

Description

Deleted Component: misc

In ICU4J, Currency#getInstance(Stirng theISOCode) does not validate the input code other than checking 3-alpha. The corresponding method in JDK throws IllegalArgumentException when the input code is invalid.

Currency instance initialized with non ISO 4217 code is not useful at all and JDK implementation makes more sense. We probably should change the behavior aligned to JDK's behavior.

Activity

Show:
TracBot
July 1, 2018, 12:13 AM
Trac Comment 1.2 by —2010-09-20T15:19:52.352Z

Replying to (Comment 1 yoshito):

  • JDK 7 added a static method - getAvailableCurrencies. ICU4J should match the new API.

This specific item is tracked by ticket along with some other new JDK APIs.

TracBot
July 1, 2018, 12:13 AM
Trac Comment 3 by —2010-09-20T15:31:01.541Z

Proposals:

  • Currency#getInstance to support 3 different modes. 1) ANY: no code validation 2) SUPPORTED: IAE when the input currency code is not known 3) ACTIVE: IAE when the input currency code is unknown or known - but deprecated.

  • Above 3 different modes are controlled by an extra enum arg in getInstance method - static Currency getInstance(String code, ValidationOption opt).

  • The default getInstance(String) uses the mode ACTIVE (which is the closest to JDK's behavior).

  • Add static Set<Currency> getAvailableCurrencies() (ticket). In addition to this, add static Set<Currency> getAvailableCurrencies(Date d), which includes only currencies available at the given date.

TracBot
July 1, 2018, 12:13 AM
Trac Comment 6 by —2010-10-14T03:31:14.632Z

After reviewing the current data structure, I found checking availability of input currency code is a relatively heavy operation. ICU maintains historic currency codes associated with region and active duration. To match the JDK's implementation, it has to filter all non-active currencies by iterating through all regional mapping data.

Because such usage (checking availability by this method) is probably not a common use case, I propose to add a new method for checking availability separated from getInstance, at least for now. Below is the proposed new API.

TracBot
July 1, 2018, 12:13 AM
Trac Comment 6.7 by —2010-10-28T18:32:43.457Z

Update to the previous API proposal. After some discussions about the API signature, we reached to an agreement to make the API a little bit more generic, by specifying data range. Below is the final API signature -

TracBot
July 1, 2018, 12:13 AM
Trac Comment 8 by —2010-10-28T18:36:19.414Z

Created a ticket for C - #8093

Fixed

Assignee

Yoshito Umaoka

Reporter

Yoshito Umaoka

Components

None

Labels

None

Reviewer

None

Priority

major

Time Needed

Days

Fix versions