Java Code Examples for javax.money.convert.ExchangeRateProvider#getCurrencyConversion()
The following examples show how to use
javax.money.convert.ExchangeRateProvider#getCurrencyConversion() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExchangeExample.java From javamoney-examples with Apache License 2.0 | 6 votes |
public static void main(String[] args) { ExchangeRateProvider imfRateProvider = MonetaryConversions .getExchangeRateProvider("IMF"); ExchangeRateProvider ecbRateProvider = MonetaryConversions .getExchangeRateProvider("ECB"); CurrencyUnit euro = Monetary.getCurrency("EUR"); CurrencyUnit dollar = Monetary.getCurrency(Locale.US); CurrencyConversion ecbDollarConvertion = ecbRateProvider .getCurrencyConversion(dollar); CurrencyConversion imfDollarConvertion = imfRateProvider .getCurrencyConversion(dollar); MonetaryAmount money = Money.of(10, euro); System.out.println(money.with(ecbDollarConvertion)); System.out.println(money.with(imfDollarConvertion)); }
Example 2
Source File: MonetaryFunctions.java From jsr354-ri with Apache License 2.0 | 5 votes |
/** * comparator to sort the {@link MonetaryAmount} considering the * {@link ExchangeRate} * @param provider the rate provider to be used, not null. * @return the sort of {@link MonetaryAmount} using {@link ExchangeRate} */ public static Comparator<? super MonetaryAmount> sortValuable( ExchangeRateProvider provider) { return (m1, m2) -> { CurrencyConversion conversion = provider.getCurrencyConversion(m1 .getCurrency()); return m1.compareTo(conversion.apply(m2)); }; }
Example 3
Source File: MonetaryFunctions.java From jsr354-ri with Apache License 2.0 | 5 votes |
/** * return the sum and convert all values to specific currency using the * provider, if necessary * @param provider the rate provider to be used, not null. * @param currency * currency * @return the list convert to specific currency unit */ public static BinaryOperator<MonetaryAmount> sum( ExchangeRateProvider provider, CurrencyUnit currency) { CurrencyConversion currencyConversion = provider .getCurrencyConversion(currency); return (m1, m2) -> currencyConversion.apply(m1).add( currencyConversion.apply(m2)); }
Example 4
Source File: MonetaryFunctions.java From jsr354-ri with Apache License 2.0 | 5 votes |
/** * return the minimum value, if the monetary amounts have different * currencies, will converter first using the given ExchangeRateProvider * @param provider * the ExchangeRateProvider to convert the currencies * @return the minimum value */ public static BinaryOperator<MonetaryAmount> min( ExchangeRateProvider provider) { return (m1, m2) -> { CurrencyConversion conversion = provider.getCurrencyConversion(m1 .getCurrency()); if (m1.isGreaterThan(conversion.apply(m2))) { return m2; } return m1; }; }
Example 5
Source File: MonetaryFunctions.java From jsr354-ri with Apache License 2.0 | 5 votes |
/** * return the maximum value, if the monetary amounts have different * currencies, will converter first using the given ExchangeRateProvider * @param provider * the ExchangeRateProvider to convert the currencies * @return the maximum value */ public static BinaryOperator<MonetaryAmount> max( ExchangeRateProvider provider) { return (m1, m2) -> { CurrencyConversion conversion = provider .getCurrencyConversion(m1.getCurrency()); if (m1.isGreaterThan(conversion.apply(m2))) { return m1; } return m2; }; }
Example 6
Source File: ExchangeRateMonetarySummaryStatistics.java From jsr354-ri with Apache License 2.0 | 5 votes |
ExchangeRateMonetarySummaryStatistics(CurrencyUnit currencyUnit, ExchangeRateProvider provider) { super(currencyUnit); this.provider = provider; currencyConversion = provider.getCurrencyConversion(getCurrencyUnit()); }