Skip to main content

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

  • From: Werner Keil <werner.keil@...>
  • To: jcurrency_mail@...
  • Subject: [JSR-354] Re: Simplified Exchange rate/ConvertionProvider
  • Date: Tue, 14 May 2013 11:26:41 +0200

Raj,

The idea you mentioned goes very much along the lines of the Amount abstract base class of JScience on top of JSR-275:

Where
Amount<Money> tripCostEUR = tripCost.to(EUR);

would be the way to go, but the problem with that and that's why we went with a separate Converter/ExchangeRate element is, that you'd "ear-mark" a particular exchange rate or conversion provider onto Money. And the idea is more a "delegate" of 
Converter.convert(Money1, Money2), optionally with arguments like date or the transaction.

So I'm curious to hear from others, especially Anatole, but I think adding any of that inside Money or MonetaryAmount (only there it'll be universally available to all implementations

Werner

On Tue, May 14, 2013 at 10:30 AM, rajmahendra@... <rajmahendra@...> wrote:
If that is the case, then we can encourage something like

Money m1InEuro = Money.of("CHF", 100).with(MonetaryConversions
.getConversionProvider(EZB_RATE_TYPE).getConverter()
.getConversion(MoneyCurrency.of("EUR"))
);

Money m1InEuro = Money.of("CHF", 100).

Thought the MonetaryConversions going to use the EZB_RATE_TYPE internally and works with the provider cant we add a feature directly to use internal to Money object o convert something like

MonetaryAmount convertCHFtoEUR = Money.of("CHF", 100).with((EZB_RATE_TYPE).getConverter()
.getConversion(MoneyCurrency.of("EUR")

My thought is to reduce the creation of CurrencyConversion and add it inside Money



On Tue, May 14, 2013 at 12:58 PM, Anatole Tresch <atsticks@...> wrote:
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



--
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





[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