当前位置: 首页>>代码示例>>Java>>正文


Java MonetaryConversions.getExchangeRateProvider方法代码示例

本文整理汇总了Java中javax.money.convert.MonetaryConversions.getExchangeRateProvider方法的典型用法代码示例。如果您正苦于以下问题:Java MonetaryConversions.getExchangeRateProvider方法的具体用法?Java MonetaryConversions.getExchangeRateProvider怎么用?Java MonetaryConversions.getExchangeRateProvider使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.money.convert.MonetaryConversions的用法示例。


在下文中一共展示了MonetaryConversions.getExchangeRateProvider方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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

示例9: 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

示例10: 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

示例11: 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

示例12: 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

示例13: 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

示例14: 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

示例15: 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.getExchangeRateProvider方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。