/** * Gets the country codes applicable to this currency. * <p> * A currency is typically valid in one or more countries. * The codes are typically defined by ISO-3166. * An empty set indicates that no the currency is not associated with a country code. * * @return the country codes, may be empty, not null */ public Set<String> getCountryCodes() { Set<String> countryCodes = new HashSet<String>(); for (Entry<String, CurrencyUnit> entry : currenciesByCountry.entrySet()) { if (this.equals(entry.getValue())) { countryCodes.add(entry.getKey()); } } return countryCodes; }
/** * Checks if this monetary value equals another. * <p> * Like BigDecimal, this method compares the scale of the amount. * Thus, 'USD 30.00' and 'USD 30' are not equal. * <p> * The compared values must be in the same currency. * * @param other the other object, null returns false * @return true if this instance equals the other instance * @see #isEqual */ @Override public boolean equals(Object other) { if (this == other) { return true; } if (other instanceof BigMoney) { BigMoney otherMoney = (BigMoney) other; return currency.equals(otherMoney.getCurrencyUnit()) && amount.equals(otherMoney.amount); } return false; }
/** * Checks if this instance and the specified instance have the same currency. * * @param money the money to check, not null * @return true if they have the same currency */ public boolean isSameCurrency(BigMoneyProvider money) { return (currency.equals(of(money).getCurrencyUnit())); }
@Override public Long toNonNullValue(Money value) { if (!currencyUnit.equals(value.getCurrencyUnit())) { throw new IllegalStateException("Expected currency " + currencyUnit.getCurrencyCode() + " but was " + value.getCurrencyUnit()); } return value.getAmountMajorLong(); }
@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 BigDecimal toNonNullValue(Money value) { if (!currencyUnit.equals(value.getCurrencyUnit())) { throw new IllegalStateException("Expected currency " + currencyUnit.getCurrencyCode() + " but was " + value.getCurrencyUnit()); } return value.getAmount(); }
@Override public Long toNonNullValue(BigMoney value) { if (!currencyUnit.equals(value.getCurrencyUnit())) { throw new IllegalStateException("Expected currency " + currencyUnit.getCurrencyCode() + " but was " + value.getCurrencyUnit()); } return value.toBigMoney().getAmountMajorLong(); }
@Override public Long toNonNullValue(BigMoney value) { if (!currencyUnit.equals(value.getCurrencyUnit())) { throw new IllegalStateException("Expected currency " + currencyUnit.getCurrencyCode() + " but was " + value.getCurrencyUnit()); } return value.toBigMoney().getAmountMinorLong(); }
/** * Compares this monetary value to another. * The compared values must be in the same currency. * * @param other the other monetary value, not null * @return -1 if this is less than , 0 if equal, 1 if greater than * @throws CurrencyMismatchException if the currencies differ */ @Override public int compareTo(BigMoneyProvider other) { BigMoney otherMoney = of(other); if (currency.equals(otherMoney.currency) == false) { throw new CurrencyMismatchException(getCurrencyUnit(), otherMoney.getCurrencyUnit()); } return amount.compareTo(otherMoney.amount); }
@Override public BigDecimal toNonNullValue(BigMoney value) { if (!currencyUnit.equals(value.getCurrencyUnit())) { throw new IllegalStateException("Expected currency " + currencyUnit.getCurrencyCode() + " but was " + value.getCurrencyUnit()); } return BigMoney.of(value).getAmount(); }
public BigMoney getBalance(CurrencyUnit currency) throws WalletNotFoundException{ refreshAccounts(); wallets = accountInfo.getWallets(); for(Wallet wallet : wallets){ BigMoney balance = wallet.getBalance(); CurrencyUnit unit = balance.getCurrencyUnit(); if(unit.equals(currency)){ return balance; } } log.error("ERROR: Could not find a {} wallet for the currency {}. Exiting now!",exchangeName,currency); throw new WalletNotFoundException(); }
endBal = balances.get(currency).get(balances.get(currency).size() - 1); if (currency.equals(CurrencyUnit.of("BTC"))) { equivBTCStartBal = equivBTCStartBal.plus(startBal); equivBTCEndBal = equivBTCEndBal.plus(endBal);