Skip to main content

[JSR-354] Re: Separation of Validity

  • From: Mark Davis ☕ <mark@...>
  • To: Anatole Tresch <atsticks@...>
  • Cc: Jsr 354 JavaMoney Public Mailinglist <jcurrency_mail@...>
  • Subject: [JSR-354] Re: Separation of Validity
  • Date: Sun, 9 Jun 2013 17:12:07 +0200

I agree with separating out the validity checks from the currencies. As to the precise form that takes, I suggest a class (name TBD), with a factory method that returns a concrete class that has the CLDR data for currencies. The two main requirements are: 
  1. for a region (country code), find the currencies and periods in which they were valid;
  2. for a currency, find the countries in which it was valid (and for which periods).
So you could do something like:

CurrencyValidityData myCurrencyInfo = CurrencyValidityData.getInstance("cldr");

for (CurrencyValidity info : myCurrencyInfo.getInfo(CurrencyUnit.getInstance("USD")) {
// would cycle through the regions in use, eg for USD: Haiti (HT), Panama (PA), U.S. Virgin Islands (VI), Caribbean Netherlands (BQ), Zimbabwe (ZW), Ecuador (EC), Northern Mariana Islands (MP), Diego Garcia (DG), El Salvador (SV), U.S. Outlying Islands (UM), Guam (GU), Palau (PW), Puerto Rico (PR), American Samoa (AS), British Indian Ocean Territory (IO), Micronesia (FM), United States (US), British Virgin Islands (VG), Turks and Caicos Islands (TC), Timor-Leste (TL), Marshall Islands (MH), Cuba (CU), Dominican Republic (DO)

  CurrencyUnit unit = info.getCurrencyUnit(); // constant USD in this case
  String region = info.getRegion(); // eg US or TC
  long from = info.getFrom(); // eg 1792-01-01 00:00 or 1969-09-08 00:00; MIN_LONG if no known start date
  long to = info.getTo(); // eg MAX_LONG  if no known end date
  boolean tender = info.getTender(); // eg true
}

or

for (CurrencyValidity info : myCurrencyInfo.getInfo("RS") {
  // would cycle through the CurrencyUnits for Serbia: eg RSD, CSD, YUM
...
}

The info could also have:
  int decimals = info.getDecimalDigits(); // eg 2
  int rounding = info.getRounding(); // eg 0
  int cashRounding = info.getCashRounding(); // eg 5

The stock info could have a getInstance for "cldr". We could have methods so that others could be registered, and you could find the available ones.



— Il meglio è l’inimico del bene —


On Sat, Jun 8, 2013 at 8:39 AM, Anatole Tresch <atsticks@...> wrote:
Deaar all

I was thinking about, how we can separate Validity from the instances, e.g. CurrencyUnit (one of the key feedback points out of the EDR). As attachment find my proposal how we can achieve that:

  • The Validity value type defines a validity for any item where it can be used: CurrencyUnit, but also ExchangeRate.
  • I defined another interface Validateable which can be implemented by classes that support validity ranges. I suggest hereby that
    • CurrencyUnit will NOT extend this interface. Basically this leads to a very lean CurrencyUnit, which basically only extends the current Currency class by namespaces, the general legal tender and virtual flags (see also attached interface). As a side effect the implementation of equals/hashCode also gets simple.
    • ExchangeRate would implement this interface.
    • Additionally for the MonetaryCurrencies singleton, within the ext package a ValidatedCurrencyUnit class can be implemented that extends CurrencyUnit with Validateable.
    • Similarly a ValideatableAmount class can be added that combines validity with a MonetaryAmount.
I know that not all details were worked out, but I think, it is worth starting the discussion given the two interfaces attached and the comments above. So the discussion is open!

Cheers,
Anatole


--
Anatole Tresch
Java Lead Engineer, JSR Spec Lead
Glärnischweg 10
CH - 8620 Wetzikon

Switzerland, Europe Zurich, GMT+1
Twitter:  @atsticks
Google: atsticks
Phone   +41-44 334 40 87
Mobile  +41-76 344 62 79



[JSR-354] Separation of Validity

Anatole Tresch 06/08/2013

[JSR-354] Re: Separation of Validity

Werner Keil 06/08/2013

[JSR-354] Re: Separation of Validity

Werner Keil 06/08/2013

[JSR-354] Re: Separation of Validity

Thomas Hüsler 06/08/2013

[JSR-354] Re: Separation of Validity

Werner Keil 06/08/2013

[JSR-354] Re: Separation of Validity

Werner Keil 06/08/2013

[JSR-354] Re: Separation of Validity

Chris Pheby 06/09/2013

[JSR-354] Re: Separation of Validity

Werner Keil 06/09/2013

[JSR-354] Re: Separation of Validity

Anatole Tresch 06/09/2013

[JSR-354] Re: Separation of Validity

Werner Keil 06/09/2013

[JSR-354] Re: Separation of Validity

Mark Davis ☕ 06/09/2013

[JSR-354] Re: Separation of Validity

Werner Keil 06/09/2013
 
 
Close
loading
Please Confirm
Close