本文整理汇总了Java中javax.money.convert.RateType类的典型用法代码示例。如果您正苦于以下问题:Java RateType类的具体用法?Java RateType怎么用?Java RateType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RateType类属于javax.money.convert包,在下文中一共展示了RateType类的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: createContext
import javax.money.convert.RateType; //导入依赖的package包/类
private static ProviderContext createContext(Iterable<ExchangeRateProvider> providers) {
Set<RateType> rateTypeSet = new HashSet<>();
StringBuilder providerName = new StringBuilder("Compound: ");
List<ProviderContext> childContextList = new ArrayList<>();
for (ExchangeRateProvider exchangeRateProvider : providers) {
childContextList.add(exchangeRateProvider.getContext());
providerName.append(exchangeRateProvider.getContext().getProviderName());
providerName.append(',');
rateTypeSet.addAll(exchangeRateProvider.getContext().getRateTypes());
}
providerName.setLength(providerName.length() - 1);
ProviderContextBuilder builder = ProviderContextBuilder.of(providerName.toString(), rateTypeSet);
builder.set(CHILD_PROVIDER_CONTEXTS_KEY, childContextList);
return builder.build();
}
开发者ID:JavaMoney,项目名称:jsr354-ri-bp,代码行数:17,代码来源:CompoundRateProvider.java
示例2: addRate
import javax.money.convert.RateType; //导入依赖的package包/类
private void addRate(CurrencyUnit term, LocalDate localDate, Number rate, boolean inverse) {
RateType rateType = RateType.HISTORIC;
ExchangeRateBuilder builder =
new ExchangeRateBuilder(ConversionContextBuilder.create(context, rateType).set(localDate).build());
builder.setBase(inverse ? term : USFederalReserveRateProvider.BASE_CURRENCY);
builder.setTerm(inverse ? USFederalReserveRateProvider.BASE_CURRENCY : term);
builder.setFactor(DefaultNumberValue.of(rate));
ExchangeRate exchangeRate = builder.build();
if(inverse) {
exchangeRate = USFederalReserveRateProvider.reverse(exchangeRate);
}
Map<String, ExchangeRate> rateMap = this.historicRates.get(localDate);
if (Objects.isNull(rateMap)) {
synchronized (this.historicRates) {
rateMap = Optional.ofNullable(this.historicRates.get(localDate)).orElse(new ConcurrentHashMap<>());
this.historicRates.putIfAbsent(localDate, rateMap);
}
}
rateMap.put(term.getCurrencyCode(), exchangeRate);
}
开发者ID:JavaMoney,项目名称:javamoney-lib,代码行数:21,代码来源:USFederalReserveRateReadingHandler.java
示例3: addRate
import javax.money.convert.RateType; //导入依赖的package包/类
private void addRate(YahooQuoteItemInformation information) {
final ExchangeRateBuilder builder = new ExchangeRateBuilder(
ConversionContextBuilder.create(context, RateType.DEFERRED).build());
builder.setBase(YahooAbstractRateProvider.BASE_CURRENCY);
builder.setTerm(information.getCurrency());
builder.setFactor(DefaultNumberValue.of(information.getValue()));
final ExchangeRate exchangeRate = builder.build();
Map<String, ExchangeRate> rateMap = this.excangeRates.get(information.getLocalDate());
if (Objects.isNull(rateMap)) {
synchronized (this.excangeRates) {
rateMap = Optional.ofNullable(this.excangeRates.get(information.getLocalDate())).orElse(new ConcurrentHashMap<>());
this.excangeRates.putIfAbsent(information.getLocalDate(), rateMap);
}
}
rateMap.put(information.getCurrency().getCurrencyCode(), exchangeRate);
}
开发者ID:JavaMoney,项目名称:javamoney-lib,代码行数:20,代码来源:YahooRateReadingHandler.java
示例4: createContext
import javax.money.convert.RateType; //导入依赖的package包/类
private static ProviderContext createContext(Iterable<ExchangeRateProvider> providers) {
Set<RateType> rateTypeSet = new HashSet<>();
StringBuilder providerName = new StringBuilder("Compound: ");
List<ProviderContext> childContextList = new ArrayList<>();
for (ExchangeRateProvider exchangeRateProvider : providers) {
childContextList.add(exchangeRateProvider.getContext());
providerName.append(exchangeRateProvider.getContext().getProviderName());
providerName.append(',' );
rateTypeSet.addAll(exchangeRateProvider.getContext().getRateTypes());
}
providerName.setLength(providerName.length() - 1);
ProviderContextBuilder builder = ProviderContextBuilder.of(providerName.toString(), rateTypeSet);
builder.set(CHILD_PROVIDER_CONTEXTS_KEY, childContextList);
return builder.build();
}
开发者ID:JavaMoney,项目名称:jsr354-ri,代码行数:17,代码来源:CompoundRateProvider.java
示例5: BaseXChangeExchangeRateProvider
import javax.money.convert.RateType; //导入依赖的package包/类
/**
* Construct using an XChange Exchange class object for a set of currencies
* @param exchangeClassName Classname of XChange exchange we are wrapping
* @param scheduledExecutorService Executor service for running polling task
* @param pairs pairs to monitor
*/
protected BaseXChangeExchangeRateProvider(String exchangeClassName,
ScheduledExecutorService scheduledExecutorService,
CurrencyUnitPair... pairs) {
exchange = ExchangeFactory.INSTANCE.createExchange(exchangeClassName);
stpe = (scheduledExecutorService != null) ? scheduledExecutorService : Executors.newScheduledThreadPool(1);
name = exchange.getExchangeSpecification().getExchangeName();
providerContext = ProviderContext.of(name, RateType.DEFERRED);
marketDataService = exchange.getMarketDataService();
for (CurrencyUnitPair pair : pairs) {
MonitoredCurrency monitoredCurrency = new MonitoredCurrency(pair, xchangePair(pair));
monitoredCurrencies.put(pair, monitoredCurrency);
}
start(); // starting here causes first ticker to be read before observers can be registered!!!
}
开发者ID:ConsensusJ,项目名称:consensusj,代码行数:21,代码来源:BaseXChangeExchangeRateProvider.java
示例6: buildExchangeRate
import javax.money.convert.RateType; //导入依赖的package包/类
private ExchangeRate buildExchangeRate(CurrencyUnitPair pair, Ticker ticker) {
return new ExchangeRateBuilder(name, RateType.DEFERRED)
.setBase(pair.getBase())
.setTerm(pair.getTarget())
.setFactor(DefaultNumberValue.of(ticker.getLast()))
.build();
}
开发者ID:ConsensusJ,项目名称:consensusj,代码行数:8,代码来源:BaseXChangeExchangeRateProvider.java
示例7: getCurrencyConversion
import javax.money.convert.RateType; //导入依赖的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
示例8: getExchangeRate
import javax.money.convert.RateType; //导入依赖的package包/类
@Override
public ExchangeRate getExchangeRate(ConversionQuery query) {
if (query.getBaseCurrency().getCurrencyCode().equals(query.getCurrency().getCurrencyCode())) {
ExchangeRateBuilder builder = new ExchangeRateBuilder(getContext().getProviderName(), RateType.OTHER)
.setBase(query.getBaseCurrency());
builder.setTerm(query.getCurrency());
builder.setFactor(DefaultNumberValue.of(BigDecimal.ONE));
return builder.build();
}
return null;
}
开发者ID:JavaMoney,项目名称:jsr354-ri-bp,代码行数:12,代码来源:IdentityRateProvider.java
示例9: getBuilder
import javax.money.convert.RateType; //导入依赖的package包/类
private ExchangeRateBuilder getBuilder(ConversionQuery query, LocalDate localDate) {
ExchangeRateBuilder builder = new ExchangeRateBuilder(
ConversionContextBuilder.create(getContext(), RateType.HISTORIC)
.set(localDate).set("LocalDate", localDate.toString()).build());
builder.setBase(query.getBaseCurrency());
builder.setTerm(query.getCurrency());
return builder;
}
开发者ID:JavaMoney,项目名称:jsr354-ri-bp,代码行数:9,代码来源:ECBAbstractRateProvider.java
示例10: equalsTest
import javax.money.convert.RateType; //导入依赖的package包/类
@Test
public void equalsTest() {
DefaultNumberValue factor = new DefaultNumberValue(1.1);
DefaultNumberValue bigDecimalFactor = new DefaultNumberValue(new BigDecimal("1.1"));
ExchangeRate rate1 = new ExchangeRateBuilder("myprovider", RateType.ANY)
.setBase(EUR)
.setTerm(GBP)
.setFactor(factor)
.build();
ExchangeRate rate2 = new ExchangeRateBuilder("myprovider", RateType.ANY)
.setBase(EUR)
.setTerm(GBP)
.setFactor(factor)
.build();
ExchangeRate rate3 = new ExchangeRateBuilder("myprovider", RateType.ANY)
.setBase(EUR)
.setTerm(GBP)
.setFactor(bigDecimalFactor)
.build();
assertEquals(rate1, rate2, "Rates with same factor");
assertEquals(rate1, rate3, "Rates with numerically equal factor");
assertEquals(rate1.hashCode(), rate2.hashCode(), "Hashes with same factor");
assertEquals(rate1.hashCode(), rate3.hashCode(), "Hashes with numerically equal factor");
}
开发者ID:JavaMoney,项目名称:jsr354-ri-bp,代码行数:29,代码来源:ExchangeRateSimpleTest.java
示例11: equalsTest
import javax.money.convert.RateType; //导入依赖的package包/类
@Test
public void equalsTest() {
DefaultNumberValue factor = new DefaultNumberValue(1.1);
DefaultNumberValue bigDecimalFactor = new DefaultNumberValue(new BigDecimal("1.1"));
CurrencyUnit EUR = Monetary.getCurrency("EUR");
CurrencyUnit GBP = Monetary.getCurrency("GBP");
ExchangeRate rate1 = new ExchangeRateBuilder("myprovider", RateType.ANY)
.setBase(EUR)
.setTerm(GBP)
.setFactor(factor)
.build();
ExchangeRate rate2 = new ExchangeRateBuilder("myprovider", RateType.ANY)
.setBase(EUR)
.setTerm(GBP)
.setFactor(factor)
.build();
ExchangeRate rate3 = new ExchangeRateBuilder("myprovider", RateType.ANY)
.setBase(EUR)
.setTerm(GBP)
.setFactor(bigDecimalFactor)
.build();
assertEquals(rate1, rate2, "Rates with same factor");
assertEquals(rate1, rate3, "Rates with numerically equal factor");
assertEquals(rate1.hashCode(), rate2.hashCode(), "Hashes with same factor");
assertEquals(rate1.hashCode(), rate3.hashCode(), "Hashes with numerically equal factor");
}
开发者ID:JavaMoney,项目名称:jsr354-ri-bp,代码行数:30,代码来源:ExchangeRateBuilderTest.java
示例12: getExchangeContext
import javax.money.convert.RateType; //导入依赖的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
示例13: getExchangeContext
import javax.money.convert.RateType; //导入依赖的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
示例14: getExchangeRate
import javax.money.convert.RateType; //导入依赖的package包/类
@Override
public ExchangeRate getExchangeRate(ConversionQuery conversionQuery) {
if (conversionQuery.getBaseCurrency().getCurrencyCode().equals(conversionQuery.getCurrency().getCurrencyCode())) {
ExchangeRateBuilder builder = new ExchangeRateBuilder(getContext().getProviderName(), RateType.OTHER)
.setBase(conversionQuery.getBaseCurrency());
builder.setTerm(conversionQuery.getCurrency());
builder.setFactor(DefaultNumberValue.of(BigDecimal.ONE));
return builder.build();
}
return null;
}
开发者ID:JavaMoney,项目名称:jsr354-ri,代码行数:12,代码来源:IdentityRateProvider.java
示例15: getRateType
import javax.money.convert.RateType; //导入依赖的package包/类
private RateType getRateType(LocalDate fromTS) {
RateType rateType = RateType.HISTORIC;
if (fromTS.equals(LocalDate.now())) {
rateType = RateType.DEFERRED;
}
return rateType;
}
开发者ID:JavaMoney,项目名称:jsr354-ri,代码行数:8,代码来源:IMFRateReadingHandler.java
示例16: getExchangeRate
import javax.money.convert.RateType; //导入依赖的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
示例17: getRateType
import javax.money.convert.RateType; //导入依赖的package包/类
public RateType getRateType() {
return RATE_TYPE;
}
开发者ID:JavaMoney,项目名称:javamoney-shelter,代码行数:4,代码来源:BitcoinDeRateProvider.java
示例18: ExchangeRateBuilder
import javax.money.convert.RateType; //导入依赖的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
注:本文中的javax.money.convert.RateType类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论