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


Java ConversionContext类代码示例

本文整理汇总了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.");
}
 
开发者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


注:本文中的javax.money.convert.ConversionContext类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。