FileDocCategorySizeDatePackage
Account_Impl2.javaAPI DocExample2352Thu Nov 08 00:23:50 GMT 2001com.ora.rmibook.chapter8

Account_Impl2

public class Account_Impl2 extends Object implements Account

Fields Summary
private Money
_balance
Constructors Summary
public Account_Impl2(Money startingBalance)

        _balance = startingBalance;
    
Methods Summary
private voidcheckForNegativeAmount(Money amount)

        int cents = amount.getCents();

        if (0 > cents) {
            throw new NegativeAmountException();
        }
    
private voidcheckForOverdraft(Money amount)

        if (amount.greaterThan(_balance)) {
            throw new OverdraftException(false);
        }
        return;
    
public booleanequals(java.lang.Object object)

        // three cases. Either it's us, or it's our stub, or it's
        // not equal.

        if (object instanceof Account_Impl2) {
            return (object == this);
        }
        if (object instanceof RemoteStub) {
            try {
                RemoteStub ourStub = (RemoteStub) RemoteObject.toStub(this);

                return ourStub.equals(object);
            } catch (NoSuchObjectException e) {
                // we're not listening on a port, therefore it's not our
                // stub
            }
        }
        return false;
    
public MoneygetBalance()

        return _balance;
    
public inthashCode()

        try {
            Remote ourStub = RemoteObject.toStub(this);

            return ourStub.hashCode();
        } catch (NoSuchObjectException e) {
        }
        return super.hashCode();
    
public voidmakeDeposit(Money amount)

        checkForNegativeAmount(amount);
        _balance.add(amount);
        return;
    
public voidmakeWithdrawal(Money amount)

        checkForNegativeAmount(amount);
        checkForOverdraft(amount);
        _balance.subtract(amount);
        return;