/** * Computes and returns the sum of two cardinalities. If an overflow occurs, the maximum Long * value is returned (Long.MAX_VALUE). */ public static long addCardinalities(long a, long b) { try { return LongMath.checkedAdd(a, b); } catch (ArithmeticException e) { LOG.warn("overflow when adding cardinalities: " + a + ", " + b); return Long.MAX_VALUE; } }
@Override public boolean noAddOverflow(long a, long b) { try { LongMath.checkedAdd(a, b); return true; } catch (ArithmeticException e) { return false; } }
public Fiat add(final Fiat value) { checkArgument(value.currencyCode.equals(currencyCode)); return new Fiat(currencyCode, LongMath.checkedAdd(this.value, value.value)); }
public Coin add(final Coin value) { return new Coin(LongMath.checkedAdd(this.value, value.value)); }