本文整理汇总了Java中javax.money.convert.ConversionContext类的典型用法代码示例。如果您正苦于以下问题:Java ConversionContext类的具体用法?Java ConversionContext怎么用?Java ConversionContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ConversionContext类属于javax.money.convert包,在下文中一共展示了ConversionContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testNumberInsignificanceForRates
import javax.money.convert.ConversionContext; //导入依赖的package包/类
@Test
public void testNumberInsignificanceForRates(){
ExchangeRate rateFromString = new ExchangeRateBuilder(ConversionContext.HISTORIC_CONVERSION)
.setBase(Monetary.getCurrency("USD"))
.setTerm(Monetary.getCurrency("EUR"))
.setFactor(DefaultNumberValue.of(new BigDecimal("1.1")))
.build();
ExchangeRate rateFromDouble = new ExchangeRateBuilder(ConversionContext.HISTORIC_CONVERSION)
.setBase(Monetary.getCurrency("USD"))
.setTerm(Monetary.getCurrency("EUR"))
.setFactor(DefaultNumberValue.of(1.1))
.build();
assertEquals(rateFromDouble, rateFromString, "Rates are not equal for same factor.");
}
示例2: getCurrencyConversion
import javax.money.convert.ConversionContext; //导入依赖的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));
}
示例3: LazyBoundCurrencyConversion
import javax.money.convert.ConversionContext; //导入依赖的package包/类
public LazyBoundCurrencyConversion(ConversionQuery conversionQuery, ExchangeRateProvider rateProvider,
ConversionContext conversionContext) {
super(conversionQuery.getCurrency(), conversionContext);
this.conversionQuery = conversionQuery;
this.rateProvider = rateProvider;
}
示例4: shouldCreateExchangeRate
import javax.money.convert.ConversionContext; //导入依赖的package包/类
@Test
public void shouldCreateExchangeRate() {
ExchangeRate rate = new ExchangeRateBuilder(ConversionContext.ANY_CONVERSION).setBase(CURRENCY)
.setTerm(CURRENCY).setFactor(NUMBER_FACTOR).build();
assertEquals(rate.getContext(), ConversionContext.ANY_CONVERSION);
assertEquals(rate.getBaseCurrency(), CURRENCY);
assertEquals(rate.getFactor(), NUMBER_FACTOR);
}
示例5: shouldCreateExchangeRateFromExchangeRate
import javax.money.convert.ConversionContext; //导入依赖的package包/类
@Test
public void shouldCreateExchangeRateFromExchangeRate() {
ExchangeRate rate = new ExchangeRateBuilder(ConversionContext.ANY_CONVERSION).setBase(CURRENCY)
.setTerm(CURRENCY).setFactor(NUMBER_FACTOR).build();
ExchangeRate rate2 = new ExchangeRateBuilder(rate).build();
assertEquals(rate.getContext(), rate2.getContext());
assertEquals(rate.getBaseCurrency(), rate2.getBaseCurrency());
assertEquals(rate.getFactor(), rate2.getFactor());
}
示例6: getExchangeContext
import javax.money.convert.ConversionContext; //导入依赖的package包/类
@Override
protected ConversionContext getExchangeContext(String key) {
int scale = getScale(key);
if(scale < 0) {
return ConversionContext.of(this.context.getProviderName(), RateType.HISTORIC);
} else {
return ConversionContext.of(this.context.getProviderName(), RateType.HISTORIC).toBuilder().set(KEY_SCALE, scale).build();
}
}
示例7: getExchangeContext
import javax.money.convert.ConversionContext; //导入依赖的package包/类
protected ConversionContext getExchangeContext(String key) {
int scale = getScale(key);
if(scale < 0) {
return ConversionContext.of(this.context.getProviderName(), RateType.HISTORIC);
} else {
return ConversionContext.of(this.context.getProviderName(), RateType.HISTORIC).toBuilder().set(KEY_SCALE, scale).build();
}
}
示例8: getCurrencyConversion
import javax.money.convert.ConversionContext; //导入依赖的package包/类
@Override
public CurrencyConversion getCurrencyConversion(ConversionQuery conversionQuery) {
return new LazyBoundCurrencyConversion(conversionQuery, this, ConversionContext
.of(getContext().getProviderName(), getContext().getRateTypes().iterator().next()));
}
示例9: AbstractCurrencyConversion
import javax.money.convert.ConversionContext; //导入依赖的package包/类
public AbstractCurrencyConversion(CurrencyUnit termCurrency, ConversionContext conversionContext) {
Objects.requireNonNull(termCurrency);
Objects.requireNonNull(conversionContext);
this.termCurrency = termCurrency;
this.conversionContext = conversionContext;
}
示例10: with
import javax.money.convert.ConversionContext; //导入依赖的package包/类
@Override
public CurrencyConversion with(ConversionContext conversionContext) {
return new LazyBoundCurrencyConversion(conversionQuery, rateProvider,
conversionContext);
}
示例11: getExchangeRate
import javax.money.convert.ConversionContext; //导入依赖的package包/类
@Override
public ExchangeRate getExchangeRate(ConversionQuery conversionQuery) {
try {
if (loadLock.await(30, TimeUnit.SECONDS)) {
if (currencyToSdr.isEmpty()) {
return null;
}
if (!isAvailable(conversionQuery)) {
return null;
}
CurrencyUnit base = conversionQuery.getBaseCurrency();
CurrencyUnit term = conversionQuery.getCurrency();
Calendar timestamp = conversionQuery.get(Calendar.class);
if (timestamp == null) {
timestamp = conversionQuery.get(GregorianCalendar.class);
}
ExchangeRate rate1;
ExchangeRate rate2;
LocalDate localDate;
if (timestamp == null) {
localDate = LocalDate.yesterday();
rate1 = lookupRate(currencyToSdr.get(base), localDate);
rate2 = lookupRate(sdrToCurrency.get(term), localDate);
if(rate1==null || rate2==null){
localDate = LocalDate.beforeDays(2);
}
rate1 = lookupRate(currencyToSdr.get(base), localDate);
rate2 = lookupRate(sdrToCurrency.get(term), localDate);
if(rate1==null || rate2==null){
localDate = LocalDate.beforeDays(3);
rate1 = lookupRate(currencyToSdr.get(base), localDate);
rate2 = lookupRate(sdrToCurrency.get(term), localDate);
}
}
else{
localDate = LocalDate.from(timestamp);
rate1 = lookupRate(currencyToSdr.get(base), localDate);
rate2 = lookupRate(sdrToCurrency.get(term), localDate);
}
if(rate1==null || rate2==null){
return null;
}
if (base.equals(SDR)) {
return rate2;
} else if (term.equals(SDR)) {
return rate1;
}
ExchangeRateBuilder builder =
new ExchangeRateBuilder(ConversionContext.of(CONTEXT.getProviderName(), RateType.HISTORIC));
builder.setBase(base);
builder.setTerm(term);
builder.setFactor(multiply(rate1.getFactor(), rate2.getFactor()));
builder.setRateChain(rate1, rate2);
return builder.build();
}else{
// Lets wait for a successful load only once, then answer requests as data is present.
loadLock.countDown();
throw new MonetaryException("Failed to load currency conversion data: " + loadState);
}
}
catch(InterruptedException e){
throw new MonetaryException("Failed to load currency conversion data: Load task has been interrupted.", e);
}
}
示例12: getContext
import javax.money.convert.ConversionContext; //导入依赖的package包/类
@Override
public ConversionContext getContext() {
return null;
}
示例13: shouldReturnNPEWhenConversionContextIsNull
import javax.money.convert.ConversionContext; //导入依赖的package包/类
@Test(expectedExceptions = NullPointerException.class)
public void shouldReturnNPEWhenConversionContextIsNull() {
ConversionContext context = null;
new ExchangeRateBuilder(context).setBase(CURRENCY)
.setTerm(CURRENCY).setFactor(NUMBER_FACTOR).build();
}
示例14: shouldReturnNPEWhenTermIsNull
import javax.money.convert.ConversionContext; //导入依赖的package包/类
@Test(expectedExceptions = NullPointerException.class)
public void shouldReturnNPEWhenTermIsNull() {
new ExchangeRateBuilder(ConversionContext.ANY_CONVERSION).setBase(CURRENCY)
.setTerm(null).setFactor(NUMBER_FACTOR).build();
}
示例15: shouldReturnNPEWhenBaseIsNull
import javax.money.convert.ConversionContext; //导入依赖的package包/类
@Test(expectedExceptions = NullPointerException.class)
public void shouldReturnNPEWhenBaseIsNull() {
new ExchangeRateBuilder(ConversionContext.ANY_CONVERSION).setBase(null)
.setTerm(CURRENCY).setFactor(NUMBER_FACTOR).build();
}