{@inheritdoc}

@throws UnsupportedDateException
@throws UnsupportedCurrencyPairException
342872
protected function getHistoricalExchangeRate(HistoricalExchangeRateQuery $exchangeQuery): ExchangeRateContract
    {
        $currencyPair = $exchangeQuery->getCurrencyPair();
        $baseCurrency = $currencyPair->getBaseCurrency();
        $date = $exchangeQuery->getDate();
        $formattedDate = $date->format('Ymd');

        $content = $this->request(self::URL.'?'.http_build_query(['date' => $formattedDate]));
        $element = StringUtil::xmlToElement($content);

        $elements = $element->xpath('./currency[cc="'.$baseCurrency.'"]');

        if (empty($elements)) {
            if ($element->xpath('./error')) {
                throw new UnsupportedDateException($date, $this);
            }

            throw new UnsupportedCurrencyPairException($currencyPair, $this);
        }

        $item = $elements[0];

        $rate = (float) str_replace(',', '.', (string) $item->rate);

        return $this->createRate($currencyPair, $rate, $date);
    }
685218
@Override
	public BaseDateTimeType setValue(Date theValue) {
		if (myTimeZoneZulu == false && myTimeZone == null) {
			myTimeZone = TimeZone.getDefault();
		}
		myPrecision = getDefaultPrecisionForDatatype();
		BaseDateTimeType retVal = (BaseDateTimeType) super.setValue(theValue);
		return retVal;
	}
556740
protected function isValidCurrency(string $value): void
    {
        $allowedCurrency = $this->getAllowedCurrency();

        $regex = '/^' . implode('|', $allowedCurrency) . '$/';
        if (!preg_match($regex, $value)) {
            throw new InvalidCurrencyException(sprintf(
                '%s is not a valid currency. Currency must be in ISO-4217-3 format.',
                $value
            ));
        }
    }
1207576
public CurrencyDateCalculatorBuilder<E> ccy2Calendar(final HolidayCalendar<E> ccy2Calendar) {
        if (ccy2Calendar != null) {
            this.ccy2Calendar = ccy2Calendar;
        }
        return this;
    }
665871
public function serialize()
    {
        $this->transactionModifier = TransactionModifier::HOSTEDREQUEST;
        parent::execute();

        $client = ServicesContainer::instance()->getClient();

        if ($client->supportsHostedPayments()) {
            return $client->serializeRequest($this);
        }
        throw new UnsupportedTransactionException("Your current gateway does not support hosted payments.");
    }
15693
public void toBinDate(TimeZone tz, byte[] bytes, Date value) throws PSQLException {
    long millis = value.getTime();

    if (tz == null) {
      tz = getDefaultTz();
    }
    // It "getOffset" is UNTESTED
    // See org.postgresql.jdbc.AbstractJdbc2Statement.setDate(int, java.sql.Date,
    // java.util.Calendar)
    // The problem is we typically do not know for sure what is the exact required date/timestamp
    // type
    // Thus pgjdbc sticks to text transfer.
    millis += tz.getOffset(millis);

    long secs = toPgSecs(millis / 1000);
    ByteConverter.int4(bytes, 0, (int) (secs / 86400));
  }
784919
@Override
  public String requestDepositAddress(Currency currency, String... arguments) throws IOException {
    if (currency.equals(Currency.BTC)) {
      return getBitstampBitcoinDepositAddress().getDepositAddress();
    } else if (currency.equals(Currency.LTC)) {
      return getBitstampLitecoinDepositAddress().getDepositAddress();
    } else if (currency.equals(Currency.XRP)) {
      return getRippleDepositAddress().getAddressAndDt();
    } else if (currency.equals(Currency.BCH)) {
      return getBitstampBitcoinCashDepositAddress().getDepositAddress();
    } else if (currency.equals(Currency.ETH)) {
      return getBitstampEthereumDepositAddress().getDepositAddress();
    } else {
      throw new IllegalStateException("Unsupported currency " + currency);
    }
  }
970966
public void setFMDate(String value) {
        final long multiplier = 100000000;
        Calendar cal = Calendar.getInstance();
        double val = Double.parseDouble(value);
        
        if (val < 1000000D || val > 9999999D) {
            throw new IllegalArgumentException();
        }
        
        long date = (long) Math.floor(val * multiplier);
        hasTime = date % multiplier != 0;
        date = setCalendar(cal, Calendar.MILLISECOND, date, 100);
        date = setCalendar(cal, Calendar.SECOND, date, 100);
        date = setCalendar(cal, Calendar.MINUTE, date, 100);
        date = setCalendar(cal, Calendar.HOUR_OF_DAY, date, 100);
        date = setCalendar(cal, Calendar.DAY_OF_MONTH, date, 100);
        date = setCalendar(cal, Calendar.MONTH, date - 1, 100);
        date = setCalendar(cal, Calendar.YEAR, date + 1700, 10000);
        setTime(cal.getTimeInMillis());
    }
1051932
@Override
    public void unimportTransaction(String globalId) throws SystemException {

        DistributableTransaction tx = _threadImportedTran.get();

        // In the case of the in-process http channel, where no WS-AT
        // context is being propagated, we get the situation where there is a global tran
        // on the thread at this point but it is not imported
        if (tx != null) {
            if (!globalId.equals(tx.getGlobalId())) {
                // ???
                final SystemException e = new SystemException();
                throw e;
            }

            final Transaction suspendedTx = _tm.suspend();
            // If zOS and isSupportWSAT=false then there is no tx to suspend
            if ((suspendedTx != null) && (!tx.equals(suspendedTx))) {
                // Something is badly wrong
                final SystemException e = new SystemException();
                throw e;
            }
        }

        _threadImportedTran.set(null);

        // d238113 - check for null although with defect 235471.2 we should not get this problem
        if (tx != null) {
            tx.removeAssociation();
        }

        final UOWCoordinator suspendedUOW = _threadUOWCoord.get();
        // ? Should null be forced back ? - shouldn't happen anyway, LTC must have been on the thread
        if (suspendedUOW != null && !suspendedUOW.isGlobal()) {
            LocalTranCurrentSet.instance().resume((LocalTransactionCoordinator) suspendedUOW);
        }

        _threadUOWCoord.set(null);
    }
1153142
@Override
    public boolean supportsTransactionIsolationLevel(int level) throws SQLException
    {
        checkClosed();
        if (level == Connection.TRANSACTION_SERIALIZABLE)
            return true;
        return false;
    }
1035337
public GlobalizationPreferences setCalendar(Calendar calendar) {
        if (isFrozen()) {
            throw new UnsupportedOperationException("Attempt to modify immutable object");
        }
        this.calendar = (Calendar) calendar.clone(); // clone for safety
        return this;
    }
482780
@Override
    public void readExternal(ObjectInput in)
        throws IOException, ClassNotFoundException {

        byte header = in.readByte();

        switch ((header & 0xFF) >> 4) {
            case FALLBACK_TIMEZONE_TYPE:
                this.obj = this.readFallback(in, header);
                break;
            case TRANSITION_RESOLVER_TYPE:
                this.obj = this.readStrategy(header);
                break;
            case HISTORIZED_TIMEZONE_TYPE:
                this.obj = this.readZone(in, header);
                break;
            case ZONAL_OFFSET_TYPE:
                this.obj = this.readOffset(in, header);
                break;
            default:
                throw new StreamCorruptedException("Unknown serialized type.");
        }

    }
806607
public function setAllowedCurrencies($currencies)
    {
        if (empty($currencies)) {
            $currencies = [];
        } elseif (is_string($currencies)) {
            $currencies = [
                $currencies => $currencies
            ];
        } elseif (!is_array($currencies)) {
            throw new InvalidArgumentException("Invalid currency list");
        } elseif (!ArrayLib::is_associative($currencies)) {
            $currencies = array_combine($currencies, $currencies);
        }

        $this->allowedCurrencies = $currencies;

        // Rebuild currency field
        $this->buildCurrencyField();
        return $this;
    }
431207
public function set($key, $value, $expireResolution = null, $expireTTL = null, $flag = null)
    {
        $expireResolution = strtolower($expireResolution);
        $expireTTL = strtolower($expireTTL);

        $condition = null;
        $ttl = 0;
        if (in_array($expireResolution, array('nx', 'xx'))) {
            $condition = $expireResolution;
            if ($expireTTL === 'ex') {
                $ttl = $flag;
            } elseif ($expireTTL === 'px') {
                $ttl = ceil($flag / 1000);
            }
        } else {
            if ($expireResolution === 'ex') {
                $ttl = $expireTTL;
            } elseif ($expireResolution === 'px') {
                $ttl = ceil($expireTTL / 1000);
            }
        }

        if ($condition === 'nx' && $this->doExists($key)) {
            return null;
        }
        if ($condition === 'xx' && !$this->doExists($key)) {
            return null;
        }

        $this->data[$key] = $value;
        if ($ttl > 0) {
            $this->expiring[$key] = $this->getTimestamp() + $ttl;
        }

        return 'OK';
    }
367999
public function setDefault(CurrencyUpdateEvent $event, $eventName, EventDispatcherInterface $dispatcher)
    {
        if (null !== $currency = CurrencyQuery::create()->findPk($event->getCurrencyId())) {
            // Reset default status
            CurrencyQuery::create()->filterByByDefault(true)->update(array('ByDefault' => false));

            $currency
                ->setDispatcher($dispatcher)
                ->setVisible($event->getVisible())
                ->setByDefault($event->getIsDefault())
                ->save()
            ;

            // Update rates when setting a new default currency
            if ($event->getIsDefault()) {
                $updateRateEvent = new CurrencyUpdateRateEvent();

                $dispatcher->dispatch(TheliaEvents::CURRENCY_UPDATE_RATES, $updateRateEvent);
            }

            $event->setCurrency($currency);
        }
    }
476505
public static void runExample(AdManagerServices adManagerServices, AdManagerSession session)
      throws RemoteException {
    // Get the ExchangeRateService.
    ExchangeRateServiceInterface exchangeRateService =
        adManagerServices.get(session, ExchangeRateServiceInterface.class);

    // Create an exchange rate.
    ExchangeRate exchangeRate = new ExchangeRate();

    // Set the currency code.
    exchangeRate.setCurrencyCode("AUD");

    // Set the direction of the conversion (from the network currency).
    exchangeRate.setDirection(ExchangeRateDirection.FROM_NETWORK);

    // Set the conversion value as 1.5 (this value is multiplied by 10,000,000,000)
    exchangeRate.setExchangeRate(15000000000L);

    // Do not refresh exchange rate from Google data. Update manually only.
    exchangeRate.setRefreshRate(ExchangeRateRefreshRate.FIXED);

    // Create the exchange rate on the server.
    ExchangeRate[] exchangeRates =
        exchangeRateService.createExchangeRates(new ExchangeRate[] {exchangeRate});

    for (ExchangeRate createdExchangeRate : exchangeRates) {
      System.out.printf(
          "An exchange rate with ID %d, currency code '%s',"
              + " direction '%s', and exchange rate %.2f was created.%n",
          createdExchangeRate.getId(),
          createdExchangeRate.getCurrencyCode(),
          createdExchangeRate.getDirection().getValue(),
          (createdExchangeRate.getExchangeRate() / 10000000000f));
    }
  }
1117011
@Override
	public void cacheResult(CommerceCurrency commerceCurrency) {
		entityCache.putResult(CommerceCurrencyModelImpl.ENTITY_CACHE_ENABLED,
			CommerceCurrencyImpl.class, commerceCurrency.getPrimaryKey(),
			commerceCurrency);

		finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G,
			new Object[] {
				commerceCurrency.getUuid(), commerceCurrency.getGroupId()
			}, commerceCurrency);

		finderCache.putResult(FINDER_PATH_FETCH_BY_G_C,
			new Object[] {
				commerceCurrency.getGroupId(), commerceCurrency.getCode()
			}, commerceCurrency);

		commerceCurrency.resetOriginalValues();
	}