本文整理汇总了Java中javax.money.convert.RateType类的典型用法代码示例。如果您正苦于以下问题:Java RateType类的具体用法?Java RateType怎么用?Java RateType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RateType类属于javax.money.convert包,在下文中一共展示了RateType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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();
}
示例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);
}
示例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);
}
示例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();
}
示例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!!!
}
示例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();
}
示例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));
}
示例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;
}
示例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;
}
示例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");
}
示例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");
}
示例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();
}
}
示例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();
}
}
示例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;
}
示例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;
}