Skip to main content

[JSR-354] Re: Simplified Exchange rate/ConvertionProvider

  • From: Anatole Tresch <atsticks@...>
  • To: Jsr 354 JavaMoney Public Mailinglist <jcurrency_mail@...>
  • Subject: [JSR-354] Re: Simplified Exchange rate/ConvertionProvider
  • Date: Tue, 14 May 2013 09:28:01 +0200

Hi Rash

the following is possible:
- you can access a Conversion for a certain target from a corresponding CurrencyConverter.
- you can then apply this MonetaryFunction to the amount

In code:

CurrencyConversion convToEuro = MonetaryConversions
.getConversionProvider(EZB_RATE_TYPE).getConverter()
.getConversion(MoneyCurrency.of("EUR"));
Money m1InEuro = Money.of(MoneyCurrency.of("CHF"), 100).with(convToEuro);
Money m2InEuro = Money.of(MoneyCurrency.of("GBP"), 100).with(convToEuro);
Money m3InEuro = Money.of(MoneyCurrency.of("USD"), 100).with(convToEuro);
// currently a cast to Money is necessary, but this should be not necessary in the future...

I think, we will have to streamline even more here, so finally the following could be possible (for ISO only, but this is the most common case):

CurrencyConversion convToEuro = MonetaryConversions
.getConversionProvider(EZB_RATE_TYPE).getConversion("EUR");
Money m1InEuro = Money.of("CHF", 100).with(convToEuro);
Money m2InEuro = Money.of("GBP", 100).with(convToEuro);
Money m3InEuro = Money.of("USD", 100).with(convToEuro);

What do you think?

Cheers,
Anatole



2013/5/14 rajmahendra@... <rajmahendra@...>

Hi

Currently we are doing like this for currency conversion:

MonetaryAmount srcCHF = Money.of("CHF", 100.15);

MonetaryAmount tgt = MonetaryConversions.getConversionProvider(EZB_RATE_TYPE).getConverter().convert(srcCHF, MoneyCurrency.of("EUR"));

I am just wondering is there any way to simplify this, because srcCHF is already specified necessary things like currency type and value so I am thinking something like….

MonetaryAmount convertCHFtoEUR = srcCHF.conversionProvider().use(EZB_RATE_TYPE).convertTo(MoneyCurrency.of("EUR")) ;

I can understand the reason of separating MonetaryAmount and MonetaryConversions, but to reduce some boilerplate code we can do something like this.


--
Thank you and regards,
Rajmahendra R Hegde (Raj)
Website:
http://www.twitter.com/rajonjava
http://www.jugchennai.in             
----------------------------------------------------------------------------------------------
"DREAM is not what you see in sleep;
is the thing which does not let you sleep" - APJ Abdul Kalam
Do the difficult things while they are easy and do the great things while they are small.
A journey of a thousand miles must begin with a single step. - Lao Tzu





--
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] Simplified Exchange rate/ConvertionProvider

rajmahendra@... 05/14/2013

[JSR-354] Re: Simplified Exchange rate/ConvertionProvider

Anatole Tresch 05/14/2013

[JSR-354] Re: Simplified Exchange rate/ConvertionProvider

rajmahendra@... 05/14/2013

[JSR-354] Re: Simplified Exchange rate/ConvertionProvider

Werner Keil 05/14/2013

[JSR-354] Re: Simplified Exchange rate/ConvertionProvider

Anatole Tresch 05/14/2013

[JSR-354] Re: Simplified Exchange rate/ConvertionProvider

Werner Keil 05/14/2013

[JSR-354] Re: Simplified Exchange rate/ConvertionProvider

Anatole Tresch 05/14/2013

[JSR-354] Re: Simplified Exchange rate/ConvertionProvider

Werner Keil 05/14/2013
 
 
Close
loading
Please Confirm
Close