本文整理汇总了Java中javax.money.convert.MonetaryConversions类的典型用法代码示例。如果您正苦于以下问题:Java MonetaryConversions类的具体用法?Java MonetaryConversions怎么用?Java MonetaryConversions使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MonetaryConversions类属于javax.money.convert包,在下文中一共展示了MonetaryConversions类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: testProviderComparison
import javax.money.convert.MonetaryConversions; //导入依赖的package包/类
@Test
public void testProviderComparison() {
ExchangeRateProvider ecbRateProvider = MonetaryConversions.getExchangeRateProvider("ECB");
ExchangeRateProvider imfRateProvider = MonetaryConversions.getExchangeRateProvider("IMF");
CurrencyConversion ecbDollarConversion = ecbRateProvider.getCurrencyConversion("USD");
CurrencyConversion imfDollarConversion = imfRateProvider.getCurrencyConversion("USD");
try {
// Wait for IMF provider to load
Thread.sleep(10000L);
for (String currency : new String[]{"INR", "CHF", "BRL"}) {
Money money = Money.of(2, currency);
System.out.println("ECB : " + money.with(ecbDollarConversion));
System.out.println("IMF : " + money.with(imfDollarConversion));
assertEquals("Too much difference (ECB/IMF) for " + money,
money.with(ecbDollarConversion).getNumber().doubleValue(), money.with(imfDollarConversion).getNumber().doubleValue(), 0.4d);
}
} catch (Exception e) {
// This test may fail, if the network is slow or not available, so only write the exception as of now...
e.printStackTrace();
}
}
开发者ID:JavaMoney,项目名称:jsr354-ri-bp,代码行数:25,代码来源:CurrencyProviderTest.java
示例2: main
import javax.money.convert.MonetaryConversions; //导入依赖的package包/类
public static void main(String[] args) {
CurrencyUnit dollar = Monetary.getCurrency("USD");
CurrencyUnit euro = Monetary.getCurrency("EUR");
CurrencyUnit real = Monetary.getCurrency("BRL");
MonetaryAmount money = Money.of(9, euro);
MonetaryAmount money2 = Money.of(10, dollar);
MonetaryAmount money3 = Money.of(11, real);
ExchangeRateProvider provider =
MonetaryConversions.getExchangeRateProvider(ExchangeRateType.IMF);
;
List<MonetaryAmount> resultAsc = Stream.of(money, money2, money3)
.sorted(MonetaryFunctions
.sortValuable(provider))
.collect(Collectors.toList());//[BRL 11, EUR 9, USD 10]
List<MonetaryAmount> resultDesc = Stream.of(money, money2, money3)
.sorted(MonetaryFunctions
.sortValuableDesc(provider)).collect(Collectors.toList());//[USD 10, EUR 9, BRL 11]
}
开发者ID:otaviojava,项目名称:money-api-book-samples,代码行数:24,代码来源:SortMonetaryAmountExchange.java
示例3: main
import javax.money.convert.MonetaryConversions; //导入依赖的package包/类
public static void main(String[] args) {
CurrencyUnit dollar = Monetary.getCurrency("USD");
CurrencyUnit euro = Monetary.getCurrency("EUR");
ExchangeRateProvider provider = MonetaryConversions.getExchangeRateProvider(ExchangeRateType.IMF);
MonetaryAmount money = Money.of(10, dollar);
MonetaryAmount money2 = Money.of(10, euro);
MonetaryAmount money3 = Money.of(10, dollar);
MonetaryAmount money4 = Money.of(9, euro);
MonetaryAmount money5 = Money.of(8, dollar);
Optional<MonetaryAmount> max = Stream.of(money, money2, money3, money4, money5).reduce(
MonetaryFunctions.max(provider));//javax.money.MonetaryException: Currency mismatch: BRL/USD
max.ifPresent(System.out::println);//EUR 10
Optional<MonetaryAmount> min = Stream.of(money, money2, money3, money4, money5).reduce(
MonetaryFunctions.min(provider));
min.ifPresent(System.out::println);//USD 8
}
开发者ID:otaviojava,项目名称:money-api-book-samples,代码行数:21,代码来源:ReduceMaxMinMonetaryAmountExchange.java
示例4: main
import javax.money.convert.MonetaryConversions; //导入依赖的package包/类
public static void main(String[] args) {
CurrencyUnit dollar = Monetary.getCurrency("USD");
CurrencyUnit real = Monetary.getCurrency("BRL");
ExchangeRateProvider provider = MonetaryConversions.getExchangeRateProvider(ExchangeRateType.IMF);
MonetaryAmount money = Money.of(10, dollar);
MonetaryAmount money2 = Money.of(10, real);
MonetaryAmount money3 = Money.of(10, dollar);
MonetaryAmount money4 = Money.of(9, real);
MonetaryAmount money5 = Money.of(25, dollar);
MonetarySummaryStatistics summary = Stream.of(money, money2, money3, money4, money5)
.collect(ConversionOperators.summarizingMonetary(dollar, provider));
MonetaryAmount min = summary.getMin();//USD 2.831248
MonetaryAmount max = summary.getMax();//USD 25
MonetaryAmount average = summary.getAverage();//USD 10.195416
long count = summary.getCount();//5
MonetaryAmount sum = summary.getSum();//50.97708
}
开发者ID:otaviojava,项目名称:money-api-book-samples,代码行数:24,代码来源:AggregateSummaringExchangeRateMonetaryAmount.java
示例5: main
import javax.money.convert.MonetaryConversions; //导入依赖的package包/类
public static void main(String[] args) {
CurrencyUnit dollar = Monetary.getCurrency("USD");
CurrencyUnit real = Monetary.getCurrency("BRL");
ExchangeRateProvider provider = MonetaryConversions.getExchangeRateProvider(ExchangeRateType.IMF);
MonetaryAmount money = Money.of(10, dollar);
MonetaryAmount money2 = Money.of(10, dollar);
MonetaryAmount money3 = Money.of(10, real);
MonetaryAmount money4 = Money.of(9, dollar);
MonetaryAmount money5 = Money.of(8, dollar);
Optional<MonetaryAmount> result = Stream.of(money, money2, money3, money4, money5).reduce(
MonetaryFunctions.sum(provider, dollar));//javax.money.MonetaryException: Currency mismatch: BRL/USD
result.ifPresent(System.out::println);//money converted in dollar
}
开发者ID:otaviojava,项目名称:money-api-book-samples,代码行数:17,代码来源:ReduceSumMonetaryAmountExchange.java
示例6: testGetExchangeRateProvider_Chained
import javax.money.convert.MonetaryConversions; //导入依赖的package包/类
@Test
public void testGetExchangeRateProvider_Chained()
throws InterruptedException {
ExchangeRateProvider prov = MonetaryConversions
.getExchangeRateProvider("ECB");
assertTrue(Objects.nonNull(prov));
assertEquals(ECBCurrentRateProvider.class, prov.getClass());
// Test rate provided by IMF (derived)
Thread.sleep(5000L); // wait for provider to load...
ExchangeRate r = prov.getExchangeRate(Monetary.getCurrency("USD"),
Monetary.getCurrency("INR"));
assertTrue(Objects.nonNull(r));
assertTrue(r.isDerived());
// Test rate provided by ECB
r = prov.getExchangeRate(Monetary.getCurrency("EUR"),
Monetary.getCurrency("CHF"));
assertTrue(Objects.nonNull(r));
assertFalse(r.isDerived());
}
开发者ID:JavaMoney,项目名称:jsr354-ri,代码行数:20,代码来源:MonetaryConversionTest.java
示例7: testGetExchangeRateProvider_Chained
import javax.money.convert.MonetaryConversions; //导入依赖的package包/类
@Test
public void testGetExchangeRateProvider_Chained()
throws InterruptedException {
ExchangeRateProvider prov = MonetaryConversions
.getExchangeRateProvider("IMF");
assertTrue(Objects.nonNull(prov));
assertEquals(IMFRateProvider.class, prov.getClass());
// Test rate provided by IMF (derived)
Thread.sleep(5000L); // wait for provider to load...
ExchangeRate exchangeRate = prov.getExchangeRate(Monetary.getCurrency("USD"),
Monetary.getCurrency("INR"));
assertTrue(Objects.nonNull(exchangeRate));
assertTrue(exchangeRate.isDerived());
// Test rate provided by ECB
exchangeRate = prov.getExchangeRate(Monetary.getCurrency("EUR"),
Monetary.getCurrency("CHF"));
assertTrue(Objects.nonNull(exchangeRate));
assertTrue(exchangeRate.isDerived());
}
开发者ID:JavaMoney,项目名称:jsr354-ri,代码行数:20,代码来源:MonetaryConversionTest.java
示例8: main
import javax.money.convert.MonetaryConversions; //导入依赖的package包/类
public static void main(String[] args) {
ExchangeRateProvider imfRateProvider = MonetaryConversions
.getExchangeRateProvider("IMF");
ExchangeRateProvider ecbRateProvider = MonetaryConversions
.getExchangeRateProvider("ECB");
CurrencyUnit real = Monetary.getCurrency("BRL");
CurrencyUnit dollar = Monetary.getCurrency(Locale.US);
CurrencyConversion ecbDollarConvertion = ecbRateProvider
.getCurrencyConversion(dollar);
CurrencyConversion imfDollarConvertion = imfRateProvider
.getCurrencyConversion(dollar);
MonetaryAmount money = Money.of(10, real);
System.out.println(money.with(ecbDollarConvertion));
System.out.println(money.with(imfDollarConvertion));
}
开发者ID:JavaMoney,项目名称:javamoney-examples,代码行数:20,代码来源:ExchangeExample.java
示例9: main
import javax.money.convert.MonetaryConversions; //导入依赖的package包/类
public static void main(String... args){
System.out.println("Default conversion chain -> " + MonetaryConversions.getDefaultConversionProviderChain());
ExchangeRateProvider provider = MonetaryConversions.getExchangeRateProvider("IDENT");
System.out.println("IDENT provider -> " + provider);
provider = MonetaryConversions.getExchangeRateProvider("IDENT", "ECB");
System.out.println("IDENT, ECB provider -> " + provider);
System.out.println(provider.getExchangeRate("CHF", "EUR"));
System.out.println(provider.getExchangeRate("CHF", "CHF"));
provider = MonetaryConversions.getExchangeRateProvider("IDENT", "IMF");
System.out.println(provider.getExchangeRate("TND", "BRL"));
provider = MonetaryConversions.getExchangeRateProvider("IDENT", "ECB", "ECB-HIST");
System.out.println("CHF -> EUR (today) -> " + provider.getExchangeRate(ConversionQueryBuilder.of()
.setBaseCurrency("EUR").setTermCurrency("CHF")
//.set(new Date() LocalDate.of(2008, 1, 8))
.build()));
System.out.println("CHF -> EUR (1.8.2008) -> " + provider.getExchangeRate(ConversionQueryBuilder.of()
.setBaseCurrency("EUR").setTermCurrency("CHF")
//.set(LocalDate.of(2008, 1, 8))
.build()));
}
开发者ID:JavaMoney,项目名称:javamoney-examples,代码行数:25,代码来源:ExchangeRateAccess.java
示例10: main
import javax.money.convert.MonetaryConversions; //导入依赖的package包/类
public static void main(String... args) {
String termCurrencyCode = DEFAULT_TERM_CURRENCY_CODE;
if (args.length > 0) {
termCurrencyCode = args[0];
}
final MonetaryAmount amt = Money.of(2000, "EUR");
CurrencyConversion conv= MonetaryConversions.getConversion(termCurrencyCode, "ECB");
System.out.println(MessageFormat.format("2000 EUR (ECB)-> {0} = {1}",
termCurrencyCode, amt.with(conv)));
conv= MonetaryConversions.getConversion(termCurrencyCode, "IMF");
System.out.println(MessageFormat.format("2000 EUR (IMF)-> {0} = {1}",
termCurrencyCode, amt.with(conv)));
System.out.println(MessageFormat.format(
"2000 EUR (ECB, at 5th Jan 2015)-> {0} = {1}",
termCurrencyCode, amt.with(MonetaryConversions
.getConversion(ConversionQueryBuilder.of()
.setTermCurrency(termCurrencyCode)
//.set(LocalDate.of(2015, 01, 05))
.build()))));
}
开发者ID:JavaMoney,项目名称:javamoney-examples,代码行数:22,代码来源:ConversionExample.java
示例11: testGetExchangeRateProvider_Chained
import javax.money.convert.MonetaryConversions; //导入依赖的package包/类
@Test
public void testGetExchangeRateProvider_Chained()
throws InterruptedException {
ExchangeRateProvider prov = MonetaryConversions
.getExchangeRateProvider("ECB", "IMF");
assertTrue(prov != null);
assertEquals(CompoundRateProvider.class, prov.getClass());
// Test rate provided by IMF (derived)
Thread.sleep(5000L); // wait for provider to load...
ExchangeRate r = prov.getExchangeRate(Monetary.getCurrency("USD"),
Monetary.getCurrency("INR"));
assertTrue(r != null);
assertTrue(r.isDerived());
// Test rate provided by ECB
r = prov.getExchangeRate(Monetary.getCurrency("EUR"),
Monetary.getCurrency("CHF"));
assertTrue(r != null);
assertFalse(r.isDerived());
}
开发者ID:JavaMoney,项目名称:javamoney-examples,代码行数:20,代码来源:MonetaryConversionTest.java
示例12: main
import javax.money.convert.MonetaryConversions; //导入依赖的package包/类
public static void main(String... args){
System.out.println("Default conversion chain -> " + MonetaryConversions.getDefaultConversionProviderChain());
ExchangeRateProvider provider = MonetaryConversions.getExchangeRateProvider("IDENT");
System.out.println("IDENT provider -> " + provider);
provider = MonetaryConversions.getExchangeRateProvider("IDENT", "ECB");
System.out.println("IDENT, ECB provider -> " + provider);
System.out.println(provider.getExchangeRate("CHF", "EUR"));
System.out.println(provider.getExchangeRate("CHF", "CHF"));
provider = MonetaryConversions.getExchangeRateProvider("IDENT", "IMF");
System.out.println(provider.getExchangeRate("TND", "BRL"));
provider = MonetaryConversions.getExchangeRateProvider("IDENT", "ECB", "ECB-HIST");
System.out.println("CHF -> EUR (today) -> " + provider.getExchangeRate(ConversionQueryBuilder.of()
.setBaseCurrency("EUR").setTermCurrency("CHF")
.set(LocalDate.of(2008, 1, 8)).build()));
System.out.println("CHF -> EUR (1.8.2008) -> " + provider.getExchangeRate(ConversionQueryBuilder.of()
.setBaseCurrency("EUR").setTermCurrency("CHF")
.set(LocalDate.of(2008, 1, 8)).build()));
}
开发者ID:JavaMoney,项目名称:javamoney-examples,代码行数:23,代码来源:ExchangeRateAccess.java
示例13: main
import javax.money.convert.MonetaryConversions; //导入依赖的package包/类
public static void main(String... args) {
String termCurrencyCode = DEFAULT_TERM_CURRENCY_CODE;
if (args.length > 0) {
termCurrencyCode = args[0];
}
final MonetaryAmount amt = Money.of(2000, "EUR");
CurrencyConversion conv= MonetaryConversions.getConversion(termCurrencyCode, "ECB");
System.out.println(MessageFormat.format("2000 EUR (ECB)-> {0} = {1}",
termCurrencyCode, amt.with(conv)));
conv= MonetaryConversions.getConversion(termCurrencyCode, "IMF");
System.out.println(MessageFormat.format("2000 EUR (IMF)-> {0} = {1}",
termCurrencyCode, amt.with(conv)));
System.out.println(MessageFormat.format(
"2000 EUR (ECB, at 5th Jan 2015)-> {0} = {1}",
termCurrencyCode, amt.with(MonetaryConversions
.getConversion(ConversionQueryBuilder.of()
.setTermCurrency(termCurrencyCode)
.set(LocalDate.of(2015, 01, 05)).build()))));
}
开发者ID:JavaMoney,项目名称:javamoney-examples,代码行数:21,代码来源:ConversionExample.java
示例14: testGetExchangeRateProvider_Chained
import javax.money.convert.MonetaryConversions; //导入依赖的package包/类
@Test
public void testGetExchangeRateProvider_Chained()
throws InterruptedException {
ExchangeRateProvider prov = MonetaryConversions
.getExchangeRateProvider("ECB", "IMF");
assertTrue(Objects.nonNull(prov));
assertEquals(CompoundRateProvider.class, prov.getClass());
// Test rate provided by IMF (derived)
Thread.sleep(5000L); // wait for provider to load...
ExchangeRate r = prov.getExchangeRate(Monetary.getCurrency("USD"),
Monetary.getCurrency("INR"));
assertTrue(Objects.nonNull(r));
assertTrue(r.isDerived());
// Test rate provided by ECB
r = prov.getExchangeRate(Monetary.getCurrency("EUR"),
Monetary.getCurrency("CHF"));
assertTrue(Objects.nonNull(r));
assertFalse(r.isDerived());
}
开发者ID:JavaMoney,项目名称:javamoney-examples,代码行数:20,代码来源:MonetaryConversionTest.java
示例15: computeNextHopLocalTransferAmount
import javax.money.convert.MonetaryConversions; //导入依赖的package包/类
/**
* Given a source transfer, compute the amount (in local units of the destination ledger) that should be transferred
* to the next-hop local ledger.
*
* @param sourceTransfer A {@link Transfer} with information from the incoming source transfer delivered to
* this connector as part of a broader Interledger payment.
* @param destinationLedgerPrefix An {@link InterledgerAddress} prefix for the destination ledger that the next-hop
* tranfser will be delivered on.
*/
@VisibleForTesting
protected BigInteger computeNextHopLocalTransferAmount(
final Transfer sourceTransfer,
final InterledgerAddress destinationLedgerPrefix
) {
Objects.requireNonNull(sourceTransfer);
InterledgerAddress.requireAddressPrefix(destinationLedgerPrefix);
final CurrencyUnit baseCurrencyUnit = this.ledgerPluginManager.getLedgerPlugin(sourceTransfer.getLedgerPrefix())
.map(LedgerPlugin::getLedgerInfo)
.map(LedgerInfo::getCurrencyUnit)
.orElseThrow(() -> new LedgerPluginNotConnectedException(sourceTransfer.getLedgerPrefix()));
final CurrencyUnit terminatingCurrencyUnit = this.ledgerPluginManager.getLedgerPlugin(destinationLedgerPrefix)
.map(LedgerPlugin::getLedgerInfo)
.map(LedgerInfo::getCurrencyUnit)
.orElseThrow(() -> new LedgerPluginNotConnectedException(destinationLedgerPrefix));
// This method does not catch the CurrencyConversionException because there's nothing to be done if that occurs. It
// means that FX is not configured between the source/destination ledgers.
return Optional.ofNullable(this.fxEngine.getExchangeRate(baseCurrencyUnit, terminatingCurrencyUnit))
.map(fxRate -> {
final MonetaryAmount sourceTransferMonetaryAmount = Money.of(sourceTransfer.getAmount(), baseCurrencyUnit);
final CurrencyConversion conversion = MonetaryConversions.getConversion(terminatingCurrencyUnit);
final MonetaryAmount terminatingMonetaryAmount = sourceTransferMonetaryAmount.with(conversion);
return terminatingMonetaryAmount;
})
// Convert from a MonetaryAmount back to an Integer...
.map(MonetaryAmount::getNumber)
.map(numberValue -> numberValue.numberValueExact(BigInteger.class))
// This is allowed because if fxEngine.getExchangeRate can't find a rate, it will throw an exception!
.get();
}
开发者ID:interledger,项目名称:java-ilp-connector,代码行数:43,代码来源:AbstractLedgerPluginEventHandler.java
示例16: main
import javax.money.convert.MonetaryConversions; //导入依赖的package包/类
public static void main(String[] args) {
CurrencyUnit dollar = Monetary.getCurrency("USD");
CurrencyUnit real = Monetary.getCurrency("BRL");
MonetaryAmount money = FastMoney.of(10, dollar);
MonetaryAmount money2 = FastMoney.of(10, real);
ExchangeRateProvider provider = MonetaryConversions.getExchangeRateProvider(ExchangeRateType.ECB);
CurrencyConversion currencyConversion = provider.getCurrencyConversion(dollar);
MonetaryAmount result = currencyConversion.apply(money2);
MonetaryAmount monetaryAmount = money.add(result);
}
开发者ID:otaviojava,项目名称:money-api-book-samples,代码行数:11,代码来源:ExchangeRateProviderExample.java
示例17: shouldReturnsECBCurrentRateProvider
import javax.money.convert.MonetaryConversions; //导入依赖的package包/类
@Test
public void shouldReturnsECBCurrentRateProvider() {
ExchangeRateProvider prov = MonetaryConversions
.getExchangeRateProvider(ExchangeRateType.ECB);
assertNotNull(prov);
assertEquals(ECBCurrentRateProvider.class, prov.getClass());
}
开发者ID:JavaMoney,项目名称:jsr354-ri-bp,代码行数:8,代码来源:ExchangeRateTypeTest.java
示例18: shouldReturnsECBHistoricRateProvider
import javax.money.convert.MonetaryConversions; //导入依赖的package包/类
@Test
public void shouldReturnsECBHistoricRateProvider() {
ExchangeRateProvider prov = MonetaryConversions
.getExchangeRateProvider(ExchangeRateType.ECB_HIST);
assertNotNull(prov);
assertEquals(ECBHistoricRateProvider.class, prov.getClass());
}
开发者ID:JavaMoney,项目名称:jsr354-ri-bp,代码行数:8,代码来源:ExchangeRateTypeTest.java
示例19: shouldReturnsECBHistoric90RateProvider
import javax.money.convert.MonetaryConversions; //导入依赖的package包/类
@Test
public void shouldReturnsECBHistoric90RateProvider() {
ExchangeRateProvider prov = MonetaryConversions
.getExchangeRateProvider(ExchangeRateType.ECB_HIST90);
assertNotNull(prov);
assertEquals(ECBHistoric90RateProvider.class, prov.getClass());
}
开发者ID:JavaMoney,项目名称:jsr354-ri-bp,代码行数:8,代码来源:ExchangeRateTypeTest.java
示例20: shouldReturnsIMFRateProvider
import javax.money.convert.MonetaryConversions; //导入依赖的package包/类
@Test
public void shouldReturnsIMFRateProvider() {
ExchangeRateProvider prov = MonetaryConversions
.getExchangeRateProvider(ExchangeRateType.IMF);
assertNotNull(prov);
assertEquals(IMFRateProvider.class, prov.getClass());
}
开发者ID:JavaMoney,项目名称:jsr354-ri-bp,代码行数:8,代码来源:ExchangeRateTypeTest.java
注:本文中的javax.money.convert.MonetaryConversions类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论