Codota Logo
CurrencyConversionException
Code IndexAdd Codota to your IDE (free)

How to use
CurrencyConversionException
in
javax.money.convert

Best Java code snippets using javax.money.convert.CurrencyConversionException (Showing top 5 results out of 315)

  • Add the Codota plugin to your IDE and get smart completions
private void myMethod () {
Gson g =
  • Codota Iconnew Gson()
  • Codota IconGsonBuilder gsonBuilder;gsonBuilder.create()
  • Codota Iconnew GsonBuilder().create()
  • Smart code suggestions by Codota
}
origin: javax.money/money-api

@Override
public String toString() {
  return "CurrencyConversionException [base=" + base + ", term=" + term
      + ", conversionContext=" + conversionContext + "]: "
      + getMessage();
}
origin: org.javamoney.moneta/moneta-core

@Override
public ExchangeRate getExchangeRate(ConversionQuery conversionQuery) {
  for (ExchangeRateProvider prov : this.providers) {
    try {
      if (prov.isAvailable(conversionQuery)) {
        ExchangeRate rate = prov.getExchangeRate(conversionQuery);
        if (Objects.nonNull(rate)) {
          return rate;
        }
      }
    } catch (Exception e) {
      Logger.getLogger(getClass().getName()).log(Level.WARNING,
          "Rate Provider did not return data though at check before data was flagged as available," +
              " provider=" + prov.getContext().getProviderName() + ", query=" + conversionQuery);
    }
  }
  throw new CurrencyConversionException(conversionQuery.getBaseCurrency(), conversionQuery.getCurrency(), null,
      "All delegate prov iders failed to deliver rate, providers=" + this.providers +
          ", query=" + conversionQuery);
}
origin: ConsensusJ/consensusj

@Override
public ExchangeRate getExchangeRate(ConversionQuery conversionQuery) {
  CurrencyUnitPair pair = new CurrencyUnitPair(conversionQuery.getBaseCurrency(), conversionQuery.getCurrency());
  MonitoredCurrency monitoredCurrency = monitoredCurrencies.get(pair);
  if (monitoredCurrency == null) {
    throw new CurrencyConversionException(pair.getBase(),
        pair.getTarget(),
        null,
        "Pair not found.");
  }
  ExchangeRate rate = null;
  try {
    rate = buildExchangeRate(pair, monitoredCurrency.getTicker());
  } catch (TimeoutException e) {
    throw new MonetaryException("Timeout loading exchange rate", e);
  } catch (InterruptedException e) {
    Thread.currentThread().interrupt(); // Restore interruption flag
  }
  return rate;
}
origin: org.javamoney.moneta/moneta-core

/**
 * Method that converts the source {@link MonetaryAmount} to an
 * {@link MonetaryAmount} based on the {@link ExchangeRate} of this
 * conversion.
 * @param amount The source amount
 * @return The converted amount, never null.
 * @throws CurrencyConversionException if conversion failed, or the required data is not available.
 * @see #getExchangeRate(MonetaryAmount)
 */
@Override
public MonetaryAmount apply(MonetaryAmount amount) {
  if (termCurrency.equals(Objects.requireNonNull(amount).getCurrency())) {
    return amount;
  }
  ExchangeRate rate = getExchangeRate(amount);
  if (Objects.isNull(rate) || !amount.getCurrency().equals(rate.getBaseCurrency())) {
    throw new CurrencyConversionException(amount.getCurrency(),
        this.termCurrency, null);
  }
  NumberValue factor = rate.getFactor();
  factor = roundFactor(amount, factor);
  Integer scale = rate.getContext().get(KEY_SCALE, Integer.class);
  if(Objects.isNull(scale) || scale < 0) {
    return amount.multiply(factor).getFactory().setCurrency(rate.getCurrency()).create();
  } else {
    return amount.multiply(factor).getFactory().setCurrency(rate.getCurrency()).create().with(MonetaryOperators.rounding(scale));
  }
}
origin: org.javamoney.moneta/moneta-convert-ecb

private ExchangeRate createExchangeRate(ConversionQuery query,
                    ExchangeRateBuilder builder, ExchangeRate sourceRate,
                    ExchangeRate target) {
  if (areBothBaseCurrencies(query)) {
    builder.setFactor(DefaultNumberValue.ONE);
    return builder.build();
  } else if (BASE_CURRENCY_CODE.equals(query.getCurrency().getCurrencyCode())) {
    if (Objects.isNull(sourceRate)) {
      return null;
    }
    return reverse(sourceRate);
  } else if (BASE_CURRENCY_CODE.equals(query.getBaseCurrency()
      .getCurrencyCode())) {
    return target;
  } else {
    ExchangeRate rate1 = getExchangeRate(
        query.toBuilder().setTermCurrency(Monetary.getCurrency(BASE_CURRENCY_CODE)).build());
    ExchangeRate rate2 = getExchangeRate(
        query.toBuilder().setBaseCurrency(Monetary.getCurrency(BASE_CURRENCY_CODE))
            .setTermCurrency(query.getCurrency()).build());
    if (Objects.nonNull(rate1) && Objects.nonNull(rate2)) {
      builder.setFactor(multiply(rate1.getFactor(), rate2.getFactor()));
      builder.setRateChain(rate1, rate2);
      return builder.build();
    }
    throw new CurrencyConversionException(query.getBaseCurrency(),
        query.getCurrency(), sourceRate.getContext());
  }
}
javax.money.convertCurrencyConversionException

Javadoc

Exception thrown when a monetary conversion operation fails.

Most used methods

  • <init>
    Constructs a new exception with the specified source and target currency, detail message and cause.
  • getMessage

Popular in Java

  • Updating database using SQL prepared statement
  • compareTo (BigDecimal)
  • scheduleAtFixedRate (Timer)
    Schedules the specified task for repeated fixed-rate execution, beginning after the specified delay.
  • requestLocationUpdates (LocationManager)
  • Table (com.google.common.collect)
    A collection that associates an ordered pair of keys, called a row key and a column key, with a sing
  • GridBagLayout (java.awt)
    The GridBagLayout class is a flexible layout manager that aligns components vertically and horizonta
  • IOException (java.io)
    Signals that an I/O exception of some sort has occurred. This class is the general class of exceptio
  • NumberFormat (java.text)
    The abstract base class for all number formats. This class provides the interface for formatting and
  • Locale (java.util)
    A Locale object represents a specific geographical, political, or cultural region. An operation that
  • Stack (java.util)
    The Stack class represents a last-in-first-out (LIFO) stack of objects. It extends class Vector with
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now