public boolean equals(Object anObject) { if (isZero()) if (anObject instanceof IMoney) return ((IMoney) anObject).isZero(); if (anObject instanceof Money) { Money aMoney = (Money) anObject; return aMoney.currency().equals(currency()) && amount() == aMoney.amount(); } return false; }
/** * Specifies the price of the line item. Required. * * @param price of the line item, {@code price.amount() <= Integer.MAX_VALUE} * @throws IllegalStateException if the price is already set * @throws IllegalArgumentException if {@code price.amount() > Integer.MAX_VALUE} * @return this builder */ public Builder price(Money price) { if (this.price != null) alreadySet("price"); if (price.amount() > Integer.MAX_VALUE) { throw new IllegalArgumentException("price.amount() > Integer.MAX_VALUE"); } this.price = price; return this; }
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { in.defaultReadObject(); if (price == null) throw new AssertionError("missing price"); if (price.amount() > Integer.MAX_VALUE) { throw new AssertionError("price.amount() > Integer.MAX_VALUE"); } if (description != null && description.length() > MAX_DESCRIPTION_LENGTH) { throw new AssertionError("description.length() > 140"); } }
public IMoney addMoney(Money m) { if (m.currency().equals(currency())) return new Money(amount() + m.amount(), currency()); return MoneyBag.create(this, m); }