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 12:06:29 +0200

Hi

We try to keep Money as small as possible, though with more than 50 methods, it is already really huge (perhaps it is even a good idea to reduce it further). So I think it is good advice to separate concerns here. Additionally the core part (where Money is part of) and the conversion part may have different scopes (Money is core/platform scoped, conversion standalone).
Additionally in financial mathematics conversion is mostly done at the beginning, or the end of a functional chain. This also shows to me similarly that currency conversion has not the same cohesion with an amount as basic algorithmic operations have.

Finally the CurrencyConversion obtained from a provider for a certain target currency can easily used in parallel for different operations and should also be thread-safe, similar to other MonetaryOperator instances. So it behaves basically like every other external operation.

So summarizing I see more disadvantages than advantages adding it to the MonetaryAmount. Also from an interface design perspective, I think conversion is a different concern and should not be mixed up with amounts, which are more some kind of value types.
If somebody, also from the EG has a different opinion, please write your thoughts... ;-)

Cheers,
Anatole



2013/5/14 rajmahendra@... <rajmahendra@...>
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





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