本文整理汇总了Java中javax.money.convert.ConversionContext.of方法的典型用法代码示例。如果您正苦于以下问题:Java ConversionContext.of方法的具体用法?Java ConversionContext.of怎么用?Java ConversionContext.of使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.money.convert.ConversionContext
的用法示例。
在下文中一共展示了ConversionContext.of方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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));
}
示例2: 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();
}
}
示例3: 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();
}
}
示例4: 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()));
}
示例5: 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);
}
}
示例6: ExchangeRateBuilder
import javax.money.convert.ConversionContext; //导入方法依赖的package包/类
/**
* Sets the exchange rate type
*
* @param rateType the {@link javax.money.convert.RateType} contained
*/
public ExchangeRateBuilder(String provider, RateType rateType) {
this(ConversionContext.of(provider, rateType));
}