@Test(expected = IllegalArgumentException.class) public void currencyCodeMismatch() throws Exception { ExchangeRate rate = new ExchangeRate(Fiat.parseFiat("EUR", "500")); rate.fiatToCoin(Fiat.parseFiat("USD", "1")); }
public Coin fiatToCoin(Fiat convertFiat) { checkArgument(convertFiat.currencyCode.equals(fiat.currencyCode), "Currency mismatch: %s vs %s", convertFiat.currencyCode, fiat.currencyCode); final BigInteger converted = BigInteger.valueOf(convertFiat.value).multiply(BigInteger.valueOf(coin.value)) .divide(BigInteger.valueOf(fiat.value)); if (converted.compareTo(BigInteger.valueOf(Long.MAX_VALUE)) > 0 || converted.compareTo(BigInteger.valueOf(Long.MIN_VALUE)) < 0) throw new ArithmeticException("Overflow"); try { return Coin.valueOf(converted.longValue()); } catch (IllegalArgumentException x) { throw new ArithmeticException("Overflow: " + x.getMessage()); } }
ExchangeRate implements Serializable { public Coin fiatToCoin(Fiat convertFiat) { checkArgument(convertFiat.currencyCode.equals(fiat.currencyCode), "Currency mismatch: %s vs %s", convertFiat.currencyCode, fiat.currencyCode); final BigInteger converted = BigInteger.valueOf(convertFiat.value).multiply(BigInteger.valueOf(coin.value)) .divide(BigInteger.valueOf(fiat.value)); if (converted.compareTo(BigInteger.valueOf(Long.MAX_VALUE)) > 0 || converted.compareTo(BigInteger.valueOf(Long.MIN_VALUE)) < 0) throw new ArithmeticException("Overflow"); try { return Coin.valueOf(converted.longValue()); } catch (IllegalArgumentException x) { throw new ArithmeticException("Overflow: " + x.getMessage()); } } }
ExchangeRate implements Serializable { public Coin fiatToCoin(Fiat convertFiat) { checkArgument(convertFiat.currencyCode.equals(fiat.currencyCode), "Currency mismatch: %s vs %s", convertFiat.currencyCode, fiat.currencyCode); final BigInteger converted = BigInteger.valueOf(convertFiat.value).multiply(BigInteger.valueOf(coin.value)) .divide(BigInteger.valueOf(fiat.value)); if (converted.compareTo(BigInteger.valueOf(Long.MAX_VALUE)) > 0 || converted.compareTo(BigInteger.valueOf(Long.MIN_VALUE)) < 0) throw new ArithmeticException("Overflow"); try { return Coin.valueOf(converted.longValue()); } catch (IllegalArgumentException x) { throw new ArithmeticException("Overflow: " + x.getMessage()); } } ExchangeRate(Coin coin, Fiat fiat);  ExchangeRate(Fiat fiat); }
ExchangeRate implements Serializable { public Coin fiatToCoin(Fiat convertFiat) { checkArgument(convertFiat.currencyCode.equals(fiat.currencyCode), "Currency mismatch: %s vs %s", convertFiat.currencyCode, fiat.currencyCode); final BigInteger converted = BigInteger.valueOf(convertFiat.value).multiply(BigInteger.valueOf(coin.value)) .divide(BigInteger.valueOf(fiat.value)); if (converted.compareTo(BigInteger.valueOf(Long.MAX_VALUE)) > 0 || converted.compareTo(BigInteger.valueOf(Long.MIN_VALUE)) < 0) throw new ArithmeticException("Overflow"); try { return Coin.valueOf(converted.longValue()); } catch (IllegalArgumentException x) { throw new ArithmeticException("Overflow: " + x.getMessage()); } } ExchangeRate(Coin coin, Fiat fiat);  ExchangeRate(Fiat fiat); Fiat coinToFiat(Coin convertCoin); Coin fiatToCoin(Fiat convertFiat); @Override boolean equals(Object o); @Override int hashCode(); }
ExchangeRate implements Serializable { public Coin fiatToCoin(Fiat convertFiat) { checkArgument(convertFiat.currencyCode.equals(fiat.currencyCode), "Currency mismatch: %s vs %s", convertFiat.currencyCode, fiat.currencyCode); final BigInteger converted = BigInteger.valueOf(convertFiat.value).multiply(BigInteger.valueOf(coin.value)) .divide(BigInteger.valueOf(fiat.value)); if (converted.compareTo(BigInteger.valueOf(Long.MAX_VALUE)) > 0 || converted.compareTo(BigInteger.valueOf(Long.MIN_VALUE)) < 0) throw new ArithmeticException("Overflow"); try { return Coin.valueOf(converted.longValue()); } catch (IllegalArgumentException x) { throw new ArithmeticException("Overflow: " + x.getMessage()); } } ExchangeRate(Coin coin, Fiat fiat);  ExchangeRate(Fiat fiat); Fiat coinToFiat(Coin convertCoin); Coin fiatToCoin(Fiat convertFiat); @Override boolean equals(Object o); @Override int hashCode(); final Coin coin; final Fiat fiat; }