本文整理汇总了Java中javax.money.convert.CurrencyConversion类的典型用法代码示例。如果您正苦于以下问题:Java CurrencyConversion类的具体用法?Java CurrencyConversion怎么用?Java CurrencyConversion使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CurrencyConversion类属于javax.money.convert包,在下文中一共展示了CurrencyConversion类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: testProviderComparison
import javax.money.convert.CurrencyConversion; //导入依赖的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: shouldSetTimeInLocalDateTime
import javax.money.convert.CurrencyConversion; //导入依赖的package包/类
@Test
public void shouldSetTimeInLocalDateTime() {
Calendar localDate = GregorianCalendar.getInstance();
localDate.add(Calendar.DAY_OF_YEAR, -80);
localDate.set(Calendar.DAY_OF_WEEK, Calendar.FRIDAY);
ConversionQuery conversionQuery = ConversionQueryBuilder.of()
.setTermCurrency(EURO).set(localDate).build();
CurrencyConversion currencyConversion = provider
.getCurrencyConversion(conversionQuery);
assertNotNull(currencyConversion);
MonetaryAmount money = Money.of(BigDecimal.TEN, DOLLAR);
MonetaryAmount result = currencyConversion.apply(money);
assertEquals(result.getCurrency(), EURO);
assertTrue(result.getNumber().doubleValue() > 0);
}
开发者ID:JavaMoney,项目名称:jsr354-ri-bp,代码行数:20,代码来源:ECBHistoric90RateProviderTest.java
示例3: shouldSetTimeInLocalDateTime
import javax.money.convert.CurrencyConversion; //导入依赖的package包/类
@Test
public void shouldSetTimeInLocalDateTime() {
Calendar localDate = new GregorianCalendar(2014, Calendar.JANUARY, 9);
ConversionQuery conversionQuery = ConversionQueryBuilder.of()
.setTermCurrency(EURO).set(localDate).build();
CurrencyConversion currencyConversion = provider
.getCurrencyConversion(conversionQuery);
assertNotNull(currencyConversion);
MonetaryAmount money = Money.of(BigDecimal.TEN, DOLLAR);
MonetaryAmount result = currencyConversion.apply(money);
assertEquals(result.getCurrency(), EURO);
assertTrue(result.getNumber().doubleValue() > 0);
}
开发者ID:JavaMoney,项目名称:jsr354-ri-bp,代码行数:18,代码来源:ECBHistoricRateProviderTest.java
示例4: shouldSetTimeInLocalDateTime2
import javax.money.convert.CurrencyConversion; //导入依赖的package包/类
@Test
public void shouldSetTimeInLocalDateTime2() {
LocalDate localDate = YearMonth.of(2014, Month.JANUARY).atDay(9);
ConversionQuery conversionQuery = HistoricConversionQueryBuilder
.of(EURO).withDay(localDate).build();
CurrencyConversion currencyConversion = provider
.getCurrencyConversion(conversionQuery);
assertNotNull(currencyConversion);
MonetaryAmount money = Money.of(BigDecimal.TEN, DOLLAR);
MonetaryAmount result = currencyConversion.apply(money);
assertEquals(result.getCurrency(), EURO);
assertTrue(result.getNumber().doubleValue() > 0);
}
开发者ID:JavaMoney,项目名称:javamoney-shelter,代码行数:17,代码来源:HistoricRateProviderTest.java
示例5: shouldFindFromHistoricalUsingPeriod
import javax.money.convert.CurrencyConversion; //导入依赖的package包/类
@Test
public void shouldFindFromHistoricalUsingPeriod() {
LocalDate localDate = YearMonth.of(2011, Month.JANUARY).atDay(9);
ConversionQuery conversionQuery = HistoricConversionQueryBuilder
.of(EURO).withDaysBetween(localDate, localDate.plusDays(10)).build();
CurrencyConversion currencyConversion = provider
.getCurrencyConversion(conversionQuery);
assertNotNull(currencyConversion);
MonetaryAmount money = Money.of(BigDecimal.TEN, DOLLAR);
MonetaryAmount result = currencyConversion.apply(money);
assertEquals(result.getCurrency(), EURO);
assertTrue(result.getNumber().doubleValue() > 0);
}
开发者ID:JavaMoney,项目名称:javamoney-shelter,代码行数:17,代码来源:HistoricRateProviderTest.java
示例6: shouldHaveExchangeRates
import javax.money.convert.CurrencyConversion; //导入依赖的package包/类
@Test
public void shouldHaveExchangeRates() {
CurrencyConversion currencyConversion = provider.getCurrencyConversion(DOLLAR);
assertNotNull(currencyConversion);
int count = 0;
for (Currency currency : Currency.getAvailableCurrencies()) {
MonetaryAmount money = Money.of(BigDecimal.ONE, currency.getCurrencyCode());
try {
MonetaryAmount result = currencyConversion.apply(money);
assertTrue(result.getNumber().doubleValue() > 0);
count++;
} catch(Exception e) {
//not a supported currency
}
}
assertTrue(count >=24);
}
开发者ID:JavaMoney,项目名称:javamoney-lib,代码行数:18,代码来源:USFederalReserveRateProviderTest.java
示例7: shouldSetTimeInLocalDateTime2
import javax.money.convert.CurrencyConversion; //导入依赖的package包/类
@Test
public void shouldSetTimeInLocalDateTime2() {
LocalDate localDate = LocalDate.now().minusDays(90)
.with(TemporalAdjusters.next(DayOfWeek.FRIDAY));
ConversionQuery conversionQuery = ConversionQueryBuilder.of()
.setTermCurrency(EURO).set(localDate).build();
CurrencyConversion currencyConversion = provider
.getCurrencyConversion(conversionQuery);
assertNotNull(currencyConversion);
MonetaryAmount money = Money.of(BigDecimal.TEN, DOLLAR);
MonetaryAmount result = currencyConversion.apply(money);
assertEquals(result.getCurrency(), EURO);
assertTrue(result.getNumber().doubleValue() > 0);
}
开发者ID:JavaMoney,项目名称:jsr354-ri,代码行数:19,代码来源:ECBHistoric90RateProviderTest.java
示例8: shouldReturnErrorWhenFindFromHistoricalUsingPeriod
import javax.money.convert.CurrencyConversion; //导入依赖的package包/类
@Test(expectedExceptions = MonetaryException.class)
public void shouldReturnErrorWhenFindFromHistoricalUsingPeriod() {
LocalDate localDate = YearMonth.of(2011, Month.JANUARY).atDay(9);
ConversionQuery conversionQuery = ConversionQueryBuilder.of()
.setTermCurrency(EURO)
.set(withDaysBetween(localDate.minusDays(1), localDate))
.build();
CurrencyConversion currencyConversion = provider
.getCurrencyConversion(conversionQuery);
assertNotNull(currencyConversion);
MonetaryAmount money = Money.of(BigDecimal.TEN, DOLLAR);
currencyConversion.apply(money);
fail();
}
开发者ID:JavaMoney,项目名称:jsr354-ri,代码行数:18,代码来源:ECBHistoric90RateProviderTest.java
示例9: shouldSetTimeInLocalDateTime
import javax.money.convert.CurrencyConversion; //导入依赖的package包/类
@Test(expectedExceptions = MonetaryException.class)
public void shouldSetTimeInLocalDateTime() {
LocalDate localDate = YearMonth.of(2014, Month.JANUARY).atDay(9);
ConversionQuery conversionQuery = ConversionQueryBuilder.of()
.setTermCurrency(EURO).set(localDate).build();
CurrencyConversion currencyConversion = provider
.getCurrencyConversion(conversionQuery);
assertNotNull(currencyConversion);
MonetaryAmount money = Money.of(BigDecimal.TEN, DOLLAR);
MonetaryAmount result = currencyConversion.apply(money);
assertEquals(result.getCurrency(), EURO);
assertTrue(result.getNumber().doubleValue() > 0);
}
开发者ID:JavaMoney,项目名称:jsr354-ri,代码行数:17,代码来源:ECBHistoric90RateProviderTest.java
示例10: shouldSetTimeInLocalDateTime
import javax.money.convert.CurrencyConversion; //导入依赖的package包/类
@Test
public void shouldSetTimeInLocalDateTime() {
LocalDate localDate = YearMonth.of(2014, Month.JANUARY).atDay(9);
ConversionQuery conversionQuery = ConversionQueryBuilder.of()
.setTermCurrency(EURO).set(localDate).build();
CurrencyConversion currencyConversion = provider
.getCurrencyConversion(conversionQuery);
assertNotNull(currencyConversion);
MonetaryAmount money = Money.of(BigDecimal.TEN, DOLLAR);
MonetaryAmount result = currencyConversion.apply(money);
assertEquals(result.getCurrency(), EURO);
assertTrue(result.getNumber().doubleValue() > 0);
}
开发者ID:JavaMoney,项目名称:jsr354-ri,代码行数:17,代码来源:IMFHistoricRateProviderTest.java
示例11: main
import javax.money.convert.CurrencyConversion; //导入依赖的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
示例12: main
import javax.money.convert.CurrencyConversion; //导入依赖的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
示例13: main
import javax.money.convert.CurrencyConversion; //导入依赖的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: computeNextHopLocalTransferAmount
import javax.money.convert.CurrencyConversion; //导入依赖的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
示例15: main
import javax.money.convert.CurrencyConversion; //导入依赖的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
示例16: sortValuable
import javax.money.convert.CurrencyConversion; //导入依赖的package包/类
/**
* comparator to sort the {@link MonetaryAmount} considering the
* {@link ExchangeRate}
* @param provider the rate provider to be used.
* @return the sort of {@link MonetaryAmount} using {@link ExchangeRate}
*/
public static Comparator<? super MonetaryAmount> sortValuable(
final ExchangeRateProvider provider) {
return new Comparator<MonetaryAmount>() {
@Override
public int compare(MonetaryAmount m1, MonetaryAmount m2) {
CurrencyConversion conversor = provider.getCurrencyConversion(m1
.getCurrency());
return m1.compareTo(conversor.apply(m2));
}
};
}
开发者ID:JavaMoney,项目名称:jsr354-ri-bp,代码行数:18,代码来源:MonetaryFunctions.java
示例17: to
import javax.money.convert.CurrencyConversion; //导入依赖的package包/类
@Override
public MonetarySummaryStatistics to(CurrencyUnit unit) {
CurrencyConversion currencyConversion = provider.getCurrencyConversion(unit);
ExchangeRateMonetarySummaryStatistics another = new ExchangeRateMonetarySummaryStatistics(
unit, provider);
another.average = currencyConversion.apply(average);
another.count = count;
another.max = currencyConversion.apply(max);
another.min = currencyConversion.apply(min);
another.sum = currencyConversion.apply(sum);
return another;
}
开发者ID:JavaMoney,项目名称:jsr354-ri-bp,代码行数:13,代码来源:ExchangeRateMonetarySummaryStatistics.java
示例18: getCurrencyConversion
import javax.money.convert.CurrencyConversion; //导入依赖的package包/类
@Override
public CurrencyConversion getCurrencyConversion(ConversionQuery conversionQuery) {
if (getContext().getRateTypes().size() == 1) {
return new LazyBoundCurrencyConversion(conversionQuery, this, ConversionContext
.of(getContext().getProviderName(), getContext().getRateTypes().iterator().next()));
}
return new LazyBoundCurrencyConversion(conversionQuery, this,
ConversionContext.of(getContext().getProviderName(), RateType.ANY));
}
开发者ID:JavaMoney,项目名称:jsr354-ri-bp,代码行数:10,代码来源:AbstractRateProvider.java
示例19: getCurrencyConversion
import javax.money.convert.CurrencyConversion; //导入依赖的package包/类
@Override
public CurrencyConversion getCurrencyConversion(
ConversionQuery conversionQuery) {
CurrencyUnit currencyUnit = conversionQuery.get("Query.termCurrency",
CurrencyUnit.class);
return new CurrencyConversionMock(currencyUnit);
}
开发者ID:JavaMoney,项目名称:jsr354-ri-bp,代码行数:8,代码来源:ExchangeRateProviderMock.java
示例20: shouldReturnsSameDollarValue
import javax.money.convert.CurrencyConversion; //导入依赖的package包/类
@Test
public void shouldReturnsSameDollarValue() {
CurrencyConversion currencyConversion = provider.getCurrencyConversion(DOLLAR);
assertNotNull(currencyConversion);
MonetaryAmount money = Money.of(BigDecimal.TEN, DOLLAR);
MonetaryAmount result = currencyConversion.apply(money);
assertEquals(result.getCurrency(), DOLLAR);
assertEquals(result.getNumber().numberValue(BigDecimal.class),
BigDecimal.TEN);
}
开发者ID:JavaMoney,项目名称:jsr354-ri-bp,代码行数:13,代码来源:ECBHistoric90RateProviderTest.java
注:本文中的javax.money.convert.CurrencyConversion类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论