Value implements Monetary, Comparable<Value>, Serializable { Value(final ValueType type, final long units) { this.type = checkNotNull(type); this.value = units; } 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 parseCoin() { assertEquals(13370000, BTC.value("0.1337").value); assertEquals(13370000, BTC.value(".1337").value); assertEquals(133700000, BTC.value("1.337").value); assertEquals(133700, BTC.value("0.001337").value); assertEquals(1337000, PPC.value("1.337").value); assertEquals(1337, PPC.value("0.001337").value); assertEquals(13370, NBT.value("1.337").value); assertEquals(13, NBT.value("0.0013").value); }
@Test(expected = ArithmeticException.class) public void parseCoinErrorBitcoin() { BTC.value("3.141592653589793"); }
@Test(expected = ArithmeticException.class) public void parseCoinErrorPeercoin() { PPC.value("3.14159265"); }