public IMoney addMoneyBag(MoneyBag s) {
return s.addMoney(this);
}
public int amount() {
return fAmount;
}
public String currency() {
return fCurrency;
}
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;
}
public int hashCode() {
return fCurrency.hashCode()+fAmount;
}
public boolean isZero() {
return amount() == 0;
}
public IMoney multiply(int factor) {
return new Money(amount()*factor, currency());
}
public IMoney negate() {
return new Money(-amount(), currency());
}
public IMoney subtract(IMoney m) {
return add(m.negate());
}
public String toString() {
StringBuffer buffer = new StringBuffer();
buffer.append("["+amount()+" "+currency()+"]");
return buffer.toString();
}
文章来源于领测软件测试网 https://www.ltesting.net/