Value implements Monetary, Comparable<Value>, Serializable { @Override public boolean equals(final Object o) { if (o == this) return true; if (o == null || o.getClass() != getClass()) return false; final Value other = (Value) o; if (this.value != other.value || !this.type.equals(other.type)) return false; return true; } Value(final ValueType type, final long units); static Value valueOf(final ValueType type, final long units); @Nullable static Value valueOf(final ValueType type, @Nullable final Coin coin); static Value valueOf(final ValueType type, BigInteger units); static Value valueOf(final ValueType type, String unitsStr); @Override int smallestUnitExponent(); @Override long getValue(); Coin toCoin(); static Value valueOf(final ValueType type, final int coins, final int cents); static Value parse(final ValueType type, final String str); static Value parse(final ValueType type, final BigDecimal decimal); Value add(final Value value); Value add(final Coin value); Value add(final long value); Value subtract(final Value value); Value subtract(final Coin value); Value subtract(String str); Value subtract(long value); Value multiply(final long factor); Value divide(final long divisor); Value[] divideAndRemainder(final long divisor); long divide(final Value divisor); boolean isPositive(); boolean isNegative(); boolean isZero(); boolean isGreaterThan(Value other); boolean isLessThan(Value other); Value shiftLeft(final int n); Value shiftRight(final int n); @Override int signum(); Value negate(); String toFriendlyString(); String toPlainString(); @Override String toString(); String toUnitsString(); @Override boolean equals(final Object o); @Override int hashCode(); @Override int compareTo(@Nonnull final Value other); boolean isDust(); boolean isOfType(ValueType otherType); boolean isOfType(Value otherValue); boolean within(Value min, Value max); static Value max(Value value1, Value value2); static Value min(Value value1, Value value2); boolean canCompare(Value other); static boolean canCompare(@Nullable Value amount1, @Nullable Value amount2); final ValueType type; final long value; }
@Test public void testEquals() { Value btcSatoshi = Value.valueOf(BitcoinMain.get(), 1); Value btcSatoshi2 = Value.valueOf(BitcoinMain.get(), 1); Value btcValue = Value.parse(BitcoinMain.get(), "3.14159"); Value ltcSatoshi = Value.valueOf(LitecoinMain.get(), 1); Value ppcValue = Value.parse(PeercoinMain.get(), "3.14159"); assertTrue(btcSatoshi.equals(btcSatoshi2)); assertFalse(btcSatoshi.equals(ltcSatoshi)); assertFalse(btcSatoshi.equals(btcValue)); assertFalse(btcSatoshi.equals(ppcValue)); assertFalse(btcValue.equals(ppcValue)); }