Example #1
0
    @Override
    public boolean equals(Object o) {
      if (this == o) return true;
      if (o == null || getClass() != o.getClass()) return false;

      Pair pair = (Pair) o;

      return day.equals(pair.day) && unit.equals(pair.unit);
    }
 @Override
 public Long toNonNullValue(Money value) {
   if (!currencyUnit.equals(value.getCurrencyUnit())) {
     throw new IllegalStateException(
         "Expected currency "
             + currencyUnit.getCurrencyCode()
             + " but was "
             + value.getCurrencyUnit());
   }
   return value.getAmountMinorLong();
 }
  @Override
  public void open(Serializable serializable) throws Exception {
    if (null == serializable) {
      logger.trace("Starting a new checkpoint");
      checkpoint = new BasicBatchCheckpoint();
    } else {
      checkpoint = (BasicBatchCheckpoint) serializable;
      logger.trace("Checkpoint available: {}", checkpoint);
    }

    CurrencyUnit fromCurrency = CurrencyUnit.of(from);

    logger.trace("Building http client");

    logger.trace("Listing currently registered currencies");
    List<CurrencyUnit> registeredCurrencies = CurrencyUnit.registeredCurrencies();
    StringBuilder conversionsToAsk = new StringBuilder();
    int current = 0;
    for (CurrencyUnit to : registeredCurrencies) {
      if (fromCurrency.equals(to)) {
        continue;
      }
      logger.debug("Would ask the provider from convert {} into {}", fromCurrency, to);

      if (current > 0) {
        conversionsToAsk.append("+");
      }

      conversionsToAsk.append(fromCurrency).append(to).append("=X");
      current++;
    }
    String url = BASE_URL + conversionsToAsk.toString();
    logger.trace("URL to call: {}", url);

    logger.trace("Preparing reader");
    reader = new BufferedReader(new InputStreamReader(new URL(url).openStream()));
  }