本文整理汇总了Java中javax.money.MonetaryException类的典型用法代码示例。如果您正苦于以下问题:Java MonetaryException类的具体用法?Java MonetaryException怎么用?Java MonetaryException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MonetaryException类属于javax.money包,在下文中一共展示了MonetaryException类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: getExchangeRateProviders
import javax.money.MonetaryException; //导入依赖的package包/类
/**
* Access the current registered {@link javax.money.convert.ExchangeRateProvider} instances. If no provider
* names are passed ALL current registered providers are returned in undefined order.
*
* @param providers the provider names of hte providers to be accessed
* @return the list of providers, in the same order as requested.
* @throws javax.money.MonetaryException if a provider could not be resolved.
*/
public List<ExchangeRateProvider> getExchangeRateProviders(String... providers) {
List<ExchangeRateProvider> provInstances = new ArrayList<>();
Collection<String> providerNames = Arrays.asList(providers);
if (providerNames.isEmpty()) {
providerNames = getProviderNames();
}
for (String provName : providerNames) {
ExchangeRateProvider provider = getExchangeRateProvider(provName);
if(provider==null){
throw new MonetaryException("Unsupported conversion/rate provider: " + provName);
}
provInstances.add(provider);
}
return provInstances;
}
开发者ID:JavaMoney,项目名称:jsr354-ri-bp,代码行数:24,代码来源:BaseMonetaryConversionsSingletonSpi.java
示例2: setContext
import javax.money.MonetaryException; //导入依赖的package包/类
@Override
public MonetaryAmountFactory<T> setContext(MonetaryContext monetaryContext) {
Objects.requireNonNull(monetaryContext);
int maxScale = getMaximalMonetaryContext().getMaxScale();
if (maxScale != -1 && maxScale < monetaryContext.getMaxScale()) {
throw new MonetaryException(
"Context exceeds maximal capabilities (scale) of this type: " + monetaryContext);
}
int precision = getMaximalMonetaryContext().getPrecision();
if (precision != 0 && precision < monetaryContext.getPrecision()) {
throw new MonetaryException(
"Contexts exceeds maximal capabilities (precision) of this type: " + monetaryContext);
}
this.monetaryContext = monetaryContext.toBuilder()
.setAmountType(getAmountType()).build();
return this;
}
开发者ID:JavaMoney,项目名称:jsr354-ri-bp,代码行数:18,代码来源:AbstractAmountBuilder.java
示例3: getExchangeRateProvider
import javax.money.MonetaryException; //导入依赖的package包/类
@Override
public ExchangeRateProvider getExchangeRateProvider(ConversionQuery query) {
Collection<String> providers = getProvidersToUse(query);
List<ExchangeRateProvider> provInstances = new ArrayList<>();
for (String provName : providers) {
ExchangeRateProvider prov = this.conversionProviders.get(provName);
if(prov==null) {
throw new MonetaryException(
"Unsupported conversion/rate provider: "
+ provName);
}
provInstances.add(prov);
}
if (provInstances.isEmpty()) {
throw new MonetaryException("No such providers: " + query);
}
if (provInstances.size() == 1) {
return provInstances.get(0);
}
return new CompoundRateProvider(provInstances);
}
开发者ID:JavaMoney,项目名称:jsr354-ri-bp,代码行数:22,代码来源:DefaultMonetaryConversionsSingletonSpi.java
示例4: getProvidersToUse
import javax.money.MonetaryException; //导入依赖的package包/类
private Collection<String> getProvidersToUse(ConversionQuery query) {
List<String> providersToUse = new ArrayList<>();
List<String> providers = query.getProviderNames();
if (providers.isEmpty()) {
providers = getDefaultProviderChain();
if (providers.isEmpty()) {
throw new IllegalStateException("No default provider chain available.");
}
}
for (String provider : providers) {
ExchangeRateProvider prov = this.conversionProviders.get(provider);
if (prov == null) {
throw new MonetaryException("Invalid ExchangeRateProvider (not found): " + provider);
}
providersToUse.add(provider);
}
return providersToUse;
}
开发者ID:JavaMoney,项目名称:jsr354-ri-bp,代码行数:19,代码来源:DefaultMonetaryConversionsSingletonSpi.java
示例5: BuildableCurrencyUnit
import javax.money.MonetaryException; //导入依赖的package包/类
/**
* Constructor, called from the Builder.
*
* @param builder the builder, never null.
*/
BuildableCurrencyUnit(CurrencyUnitBuilder builder) {
Objects.requireNonNull(builder.currencyCode, "currencyCode required");
if (builder.numericCode < -1) {
throw new MonetaryException("numericCode must be >= -1");
}
if (builder.defaultFractionDigits < 0) {
throw new MonetaryException("defaultFractionDigits must be >= 0");
}
if (builder.currencyContext == null) {
throw new MonetaryException("currencyContext must be != null");
}
this.defaultFractionDigits = builder.defaultFractionDigits;
this.numericCode = builder.numericCode;
this.currencyCode = builder.currencyCode;
this.currencyContext = builder.currencyContext;
}
开发者ID:JavaMoney,项目名称:jsr354-ri-bp,代码行数:22,代码来源:BuildableCurrencyUnit.java
示例6: getExchangeRate
import javax.money.MonetaryException; //导入依赖的package包/类
@Override
public ExchangeRate getExchangeRate(ConversionQuery conversionQuery) {
Objects.requireNonNull(conversionQuery);
try {
if (loadLock.await(30, TimeUnit.SECONDS)) {
if (rates.isEmpty()) {
return null;
}
RateResult result = findExchangeRate(conversionQuery);
ExchangeRateBuilder builder = getBuilder(conversionQuery, result.date);
ExchangeRate sourceRate = result.targets.get(conversionQuery.getBaseCurrency().getCurrencyCode());
ExchangeRate target = result.targets.get(conversionQuery.getCurrency().getCurrencyCode());
return createExchangeRate(conversionQuery, builder, sourceRate, target);
}else{
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,项目名称:javamoney-lib,代码行数:22,代码来源:USFederalReserveRateProvider.java
示例7: startElement
import javax.money.MonetaryException; //导入依赖的package包/类
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
if ("description".equals(qName)) {
descriptionNode = true;
} else if ("dc:date".equals(qName)) {
dcDateNode = true;
} else if ("cb:value".equals(qName)) {
cbValueNode = true;
String units = attributes.getValue("units");
if (attributes.getValue("units") != null) {
Matcher matcher = unitsPattern.matcher(units);
if (matcher.find()) {
try {
this.currencyCode = matcher.group(1);
} catch (MonetaryException me) {
// ignore...currency index not an actual currency
}
}
}
}
super.startElement(uri, localName, qName, attributes);
}
开发者ID:JavaMoney,项目名称:javamoney-lib,代码行数:23,代码来源:USFederalReserveRateReadingHandler.java
示例8: getExchangeRate
import javax.money.MonetaryException; //导入依赖的package包/类
@Override
public ExchangeRate getExchangeRate(ConversionQuery conversionQuery) {
Objects.requireNonNull(conversionQuery);
try {
if (loadLock.await(30, TimeUnit.SECONDS)) {
if (rates.isEmpty()) {
return null;
}
RateResult result = findExchangeRate(conversionQuery);
ExchangeRateBuilder builder = getBuilder(conversionQuery, result.date);
ExchangeRate sourceRate = result.targets.get(conversionQuery.getBaseCurrency()
.getCurrencyCode());
ExchangeRate target = result.targets
.get(conversionQuery.getCurrency().getCurrencyCode());
return createExchangeRate(conversionQuery, builder, sourceRate, target);
}else{
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,项目名称:javamoney-lib,代码行数:25,代码来源:YahooAbstractRateProvider.java
示例9: findExchangeRate
import javax.money.MonetaryException; //导入依赖的package包/类
private RateResult findExchangeRate(ConversionQuery conversionQuery) {
LocalDate[] dates = getQueryDates(conversionQuery);
if (dates == null) {
Comparator<LocalDate> comparator = Comparator.naturalOrder();
LocalDate date = this.rates.keySet().stream().sorted(comparator.reversed()).findFirst().orElseThrow(() -> new MonetaryException("There is not more recent exchange rate to rate on ECBRateProvider."));
return new RateResult(date, this.rates.get(date));
} else {
for (LocalDate localDate : dates) {
Map<String, ExchangeRate> targets = this.rates.get(localDate);
if(Objects.nonNull(targets)) {
return new RateResult(localDate, targets);
}
}
String datesOnErros = Stream.of(dates).map(date -> date.format(DateTimeFormatter.ISO_LOCAL_DATE)).collect(Collectors.joining(","));
throw new MonetaryException("There is not exchange on day " + datesOnErros + " to rate to rate on ECBRateProvider.");
}
}
开发者ID:JavaMoney,项目名称:javamoney-lib,代码行数:21,代码来源:YahooAbstractRateProvider.java
示例10: BuildableCurrencyUnit
import javax.money.MonetaryException; //导入依赖的package包/类
/**
* Constructor, called from the Builder.
*
* @param builder the builder, never null.
*/
BuildableCurrencyUnit(CurrencyUnitBuilder builder) {
Objects.requireNonNull(builder.currencyCode, "currencyCode required");
if (builder.numericCode < -1) {
throw new MonetaryException("numericCode must be >= -1");
}
if (builder.defaultFractionDigits < 0) {
throw new MonetaryException("defaultFractionDigits must be >= 0");
}
if (builder.currencyContext == null) {
throw new MonetaryException("currencyContext must be != null");
}
this.defaultFractionDigits = builder.defaultFractionDigits;
this.numericCode = builder.numericCode;
this.currencyCode = builder.currencyCode;
this.currencyContext = builder.currencyContext;
}
开发者ID:JavaMoney,项目名称:jsr354-ri,代码行数:22,代码来源:BuildableCurrencyUnit.java
示例11: getExchangeRateProvider
import javax.money.MonetaryException; //导入依赖的package包/类
@Override
public ExchangeRateProvider getExchangeRateProvider(ConversionQuery conversionQuery) {
Collection<String> providers = getProvidersToUse(conversionQuery);
List<ExchangeRateProvider> provInstances = new ArrayList<>();
for (String provName : providers) {
ExchangeRateProvider prov = Optional.ofNullable(
this.conversionProviders.get(provName))
.orElseThrow(
() -> new MonetaryException(
"Unsupported conversion/rate provider: "
+ provName));
provInstances.add(prov);
}
if (provInstances.isEmpty()) {
throw new MonetaryException("No such providers: " + conversionQuery);
}
if (provInstances.size() == 1) {
return provInstances.get(0);
}
return new CompoundRateProvider(provInstances);
}
开发者ID:JavaMoney,项目名称:jsr354-ri,代码行数:22,代码来源:DefaultMonetaryConversionsSingletonSpi.java
示例12: getProvidersToUse
import javax.money.MonetaryException; //导入依赖的package包/类
private Collection<String> getProvidersToUse(ConversionQuery query) {
List<String> providersToUse = new ArrayList<>();
List<String> providerNames = query.getProviderNames();
if (providerNames.isEmpty()) {
providerNames = getDefaultProviderChain();
if (providerNames.isEmpty()) {
throw new IllegalStateException("No default provider chain available.");
}
}
for (String provider : providerNames) {
ExchangeRateProvider prov = this.conversionProviders.get(provider);
if (prov == null) {
throw new MonetaryException("Invalid ExchangeRateProvider (not found): " + provider);
}
providersToUse.add(provider);
}
return providersToUse;
}
开发者ID:JavaMoney,项目名称:jsr354-ri,代码行数:19,代码来源:DefaultMonetaryConversionsSingletonSpi.java
示例13: getExchangeRate
import javax.money.MonetaryException; //导入依赖的package包/类
@Override
public ExchangeRate getExchangeRate(ConversionQuery conversionQuery) {
Objects.requireNonNull(conversionQuery);
try {
if (loadLock.await(30, TimeUnit.SECONDS)) {
if (rates.isEmpty()) {
return null;
}
RateResult result = findExchangeRate(conversionQuery);
ExchangeRateBuilder builder = getBuilder(conversionQuery, result.date);
ExchangeRate sourceRate = result.targets.get(conversionQuery.getBaseCurrency()
.getCurrencyCode());
ExchangeRate target = result.targets
.get(conversionQuery.getCurrency().getCurrencyCode());
return createExchangeRate(conversionQuery, builder, sourceRate, target);
}else{
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,代码行数:25,代码来源:ECBAbstractRateProvider.java
示例14: findExchangeRate
import javax.money.MonetaryException; //导入依赖的package包/类
private RateResult findExchangeRate(ConversionQuery conversionQuery) {
LocalDate[] dates = getQueryDates(conversionQuery);
if (dates == null) {
Comparator<LocalDate> comparator = Comparator.naturalOrder();
LocalDate date = this.rates.keySet().stream().sorted(comparator.reversed()).findFirst().orElseThrow(() -> new MonetaryException("There is not more recent exchange rate to rate on ECBRateProvider."));
return new RateResult(date, this.rates.get(date));
} else {
for (LocalDate localDate : dates) {
Map<String, ExchangeRate> targets = this.rates.get(localDate);
if(Objects.nonNull(targets)) {
return new RateResult(localDate, targets);
}
}
String datesOnErros = Stream.of(dates).map(date -> date.format(DateTimeFormatter.ISO_LOCAL_DATE)).collect(Collectors.joining(","));
throw new MonetaryException("There is not exchange on day " + datesOnErros + " to rate to rate on ECBRateProvider.");
}
}
开发者ID:JavaMoney,项目名称:jsr354-ri,代码行数:22,代码来源:ECBAbstractRateProvider.java
示例15: shouldReturnErrorWhenFindFromHistoricalUsingPeriod
import javax.money.MonetaryException; //导入依赖的package包/类
@Test(expectedExceptions = MonetaryException.class)
public void shouldReturnErrorWhenFindFromHistoricalUsingPeriod() {
LocalDate localDate = YearMonth.of(2011, Month.JANUARY).atDay(9);
ConversionQuery conversionQuery = ConversionQueryBuilder.of()
.setTermCurrency(EURO)
.set(withDaysBetween(localDate.minusDays(1), localDate))
.build();
CurrencyConversion currencyConversion = provider
.getCurrencyConversion(conversionQuery);
assertNotNull(currencyConversion);
MonetaryAmount money = Money.of(BigDecimal.TEN, DOLLAR);
currencyConversion.apply(money);
fail();
}
开发者ID:JavaMoney,项目名称:jsr354-ri,代码行数:18,代码来源:ECBHistoric90RateProviderTest.java
示例16: shouldSetTimeInLocalDateTime
import javax.money.MonetaryException; //导入依赖的package包/类
@Test(expectedExceptions = MonetaryException.class)
public void shouldSetTimeInLocalDateTime() {
LocalDate localDate = YearMonth.of(2014, Month.JANUARY).atDay(9);
ConversionQuery conversionQuery = ConversionQueryBuilder.of()
.setTermCurrency(EURO).set(localDate).build();
CurrencyConversion currencyConversion = provider
.getCurrencyConversion(conversionQuery);
assertNotNull(currencyConversion);
MonetaryAmount money = Money.of(BigDecimal.TEN, DOLLAR);
MonetaryAmount result = currencyConversion.apply(money);
assertEquals(result.getCurrency(), EURO);
assertTrue(result.getNumber().doubleValue() > 0);
}
开发者ID:JavaMoney,项目名称:jsr354-ri,代码行数:17,代码来源:ECBHistoric90RateProviderTest.java
示例17: getExchangeRate
import javax.money.MonetaryException; //导入依赖的package包/类
private ExchangeRate getExchangeRate(List<ExchangeRate> rates,final LocalDate[] dates) {
if (Objects.isNull(rates) ) {
return null;
}
if (Objects.isNull(dates)) {
return rates.stream().sorted(COMPARATOR_EXCHANGE_BY_LOCAL_DATE.reversed()).findFirst().orElseThrow(() -> new MonetaryException("There is not more recent exchange rate to rate on IMFRateProvider."));
} else {
for (LocalDate localDate : dates) {
Predicate<ExchangeRate> filter = rate -> rate.getContext().get(LocalDate.class).equals(localDate);
Optional<ExchangeRate> exchangeRateOptional = rates.stream().filter(filter).findFirst();
if(exchangeRateOptional.isPresent()) {
return exchangeRateOptional.get();
}
}
String datesOnErros = Stream.of(dates).map(date -> date.format(DateTimeFormatter.ISO_LOCAL_DATE)).collect(Collectors.joining(","));
throw new MonetaryException("There is not exchange on day " + datesOnErros + " to rate to rate on IFMRateProvider.");
}
}
开发者ID:JavaMoney,项目名称:jsr354-ri,代码行数:19,代码来源:IMFAbstractRateProvider.java
示例18: getCurrency
import javax.money.MonetaryException; //导入依赖的package包/类
/**
* Access a new instance based on the currency code. Currencies are
* available as provided by {@link javax.money.spi.CurrencyProviderSpi} instances registered
* with the {@link javax.money.spi.Bootstrap}.
*
* @param currencyCode the ISO currency code, not {@code null}.
* @param providers the (optional) specification of providers to consider. If not set (empty) the providers
* as defined by #getDefaultRoundingProviderChain() should be used.
* @return the corresponding {@link javax.money.CurrencyUnit} instance.
* @throws javax.money.UnknownCurrencyException if no such currency exists.
*/
public CurrencyUnit getCurrency(String currencyCode, String... providers) {
Objects.requireNonNull(currencyCode, "Currency Code may not be null");
Collection<CurrencyUnit> found =
getCurrencies(CurrencyQueryBuilder.of().setCurrencyCodes(currencyCode).setProviderNames(providers).build());
if (found.isEmpty()) {
throw new UnknownCurrencyException(currencyCode);
}
if (found.size() > 1) {
throw new MonetaryException("Ambiguous CurrencyUnit for code: " + currencyCode + ": " + found);
}
return found.iterator().next();
}
开发者ID:JavaMoney,项目名称:jsr354-ri-bp,代码行数:24,代码来源:BaseMonetaryCurrenciesSingletonSpi.java
示例19: create
import javax.money.MonetaryException; //导入依赖的package包/类
/**
* Creates a new instance of {@link MonetaryAmount}, using the default {@link MonetaryContext}.
*
* @return a {@code MonetaryAmount} combining the numeric value and currency unit.
* @throws ArithmeticException If the number exceeds the capabilities of the default {@link MonetaryContext}
* used.
*/
@Override
public T create() {
if (currency == null) {
throw new MonetaryException("Cannot create an instance of '"+this.getAmountType().getName()+"': missing currency.");
}
if (number == null) {
throw new MonetaryException("Cannot create an instance of '"+this.getAmountType().getName()+"': missing number.");
}
if (monetaryContext == null) {
throw new MonetaryException("Cannot create an instance of '"+this.getAmountType().getName()+"': missing context.");
}
return create(number, currency, monetaryContext);
}
开发者ID:JavaMoney,项目名称:jsr354-ri-bp,代码行数:21,代码来源:AbstractAmountBuilder.java
示例20: read
import javax.money.MonetaryException; //导入依赖的package包/类
@Override
public byte[] read(String resourceId) {
File f = this.cachedResources.get(resourceId);
if (f==null) {
return null;
}
try {
return Files.readAllBytes(f.toPath());
} catch (IOException exception) {
throw new MonetaryException("An error on retrieve the resource id: " + resourceId, exception);
}
}
开发者ID:JavaMoney,项目名称:jsr354-ri-bp,代码行数:13,代码来源:DefaultResourceCache.java
注:本文中的javax.money.MonetaryException类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论