本文整理汇总了Java中javax.money.convert.ConversionContext类的典型用法代码示例。如果您正苦于以下问题:Java ConversionContext类的具体用法?Java ConversionContext怎么用?Java ConversionContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ConversionContext类属于javax.money.convert包,在下文中一共展示了ConversionContext类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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.");
}
开发者ID:JavaMoney,项目名称:jsr354-ri-bp,代码行数:17,代码来源:ExchangeRateBuilderTest.java
示例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));
}
开发者ID:JavaMoney,项目名称:jsr354-ri-bp,代码行数:10,代码来源:AbstractRateProvider.java
示例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;
}
开发者ID:JavaMoney,项目名称:jsr354-ri-bp,代码行数:8,代码来源:LazyBoundCurrencyConversion.java
示例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);
}
开发者ID:JavaMoney,项目名称:jsr354-ri-bp,代码行数:10,代码来源:ExchangeRateBuilderTest.java
示例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());
}
开发者ID:JavaMoney,项目名称:jsr354-ri-bp,代码行数:12,代码来源:ExchangeRateBuilderTest.java
示例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();
}
}
开发者ID:JavaMoney,项目名称:javamoney-lib,代码行数:10,代码来源:YahooAbstractRateProvider.java
示例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();
}
}
开发者ID:JavaMoney,项目名称:jsr354-ri,代码行数:9,代码来源:AbstractRateProvider.java
示例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()));
}
开发者ID:ConsensusJ,项目名称:consensusj,代码行数:6,代码来源:BaseXChangeExchangeRateProvider.java
示例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;
}
开发者ID:JavaMoney,项目名称:jsr354-ri-bp,代码行数:7,代码来源:AbstractCurrencyConversion.java
示例10: with
import javax.money.convert.ConversionContext; //导入依赖的package包/类
@Override
public CurrencyConversion with(ConversionContext conversionContext) {
return new LazyBoundCurrencyConversion(conversionQuery, rateProvider,
conversionContext);
}
开发者ID:JavaMoney,项目名称:jsr354-ri-bp,代码行数:6,代码来源:LazyBoundCurrencyConversion.java
示例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);
}
}
开发者ID:JavaMoney,项目名称:jsr354-ri-bp,代码行数:65,代码来源:IMFRateProvider.java
示例12: getContext
import javax.money.convert.ConversionContext; //导入依赖的package包/类
@Override
public ConversionContext getContext() {
return null;
}
开发者ID:JavaMoney,项目名称:jsr354-ri-bp,代码行数:5,代码来源:CurrencyConversionMock.java
示例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();
}
开发者ID:JavaMoney,项目名称:jsr354-ri-bp,代码行数:7,代码来源:ExchangeRateBuilderTest.java
示例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();
}
开发者ID:JavaMoney,项目名称:jsr354-ri-bp,代码行数:6,代码来源:ExchangeRateBuilderTest.java
示例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();
}
开发者ID:JavaMoney,项目名称:jsr354-ri-bp,代码行数:6,代码来源:ExchangeRateBuilderTest.java
示例16: shouldReturnNPEWhenFactorIsNull
import javax.money.convert.ConversionContext; //导入依赖的package包/类
@Test(expectedExceptions = NullPointerException.class)
public void shouldReturnNPEWhenFactorIsNull() {
new ExchangeRateBuilder(ConversionContext.ANY_CONVERSION).setBase(CURRENCY)
.setTerm(CURRENCY).setFactor(null).build();
}
开发者ID:JavaMoney,项目名称:jsr354-ri-bp,代码行数:6,代码来源:ExchangeRateBuilderTest.java
示例17: 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();
LocalDate[] times = getQueryDates(conversionQuery);
ExchangeRate rate1 = getExchangeRate(currencyToSdr.get(base), times);
ExchangeRate rate2 = getExchangeRate(sdrToCurrency.get(term), times);
if (base.equals(SDR)) {
return rate2;
} else if (term.equals(SDR)) {
return rate1;
}
if (Objects.isNull(rate1) || Objects.isNull(rate2)) {
return null;
}
ConversionContext context = getExchangeContext("imf.digit.fraction");
ExchangeRateBuilder builder =
new ExchangeRateBuilder(context);
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);
}
}
开发者ID:JavaMoney,项目名称:jsr354-ri,代码行数:45,代码来源:IMFAbstractRateProvider.java
示例18: 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));
}
开发者ID:JavaMoney,项目名称:jsr354-ri-bp,代码行数:9,代码来源:ExchangeRateBuilder.java
示例19: setContext
import javax.money.convert.ConversionContext; //导入依赖的package包/类
/**
* Sets the provider to be applied.
*
* @param conversionContext the {@link javax.money.convert.ConversionContext}, not null.
* @return The builder.
*/
public ExchangeRateBuilder setContext(ConversionContext conversionContext) {
Objects.requireNonNull(conversionContext);
this.conversionContext = conversionContext;
return this;
}
开发者ID:JavaMoney,项目名称:jsr354-ri-bp,代码行数:12,代码来源:ExchangeRateBuilder.java
示例20: getContext
import javax.money.convert.ConversionContext; //导入依赖的package包/类
/**
* Access the {@link javax.money.convert.ConversionContext} of {@link javax.money.convert.ExchangeRate}.
*
* @return the conversion context, never null.
*/
public final ConversionContext getContext() {
return this.conversionContext;
}
开发者ID:JavaMoney,项目名称:jsr354-ri-bp,代码行数:9,代码来源:DefaultExchangeRate.java
注:本文中的javax.money.convert.ConversionContext类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论