FileDocCategorySizeDatePackage
Account_Impl.javaAPI DocExample2363Thu Nov 08 00:23:04 GMT 2001com.ora.rmibook.chapter17.basic

Account_Impl

public class Account_Impl extends Object implements Account

Fields Summary
private Money
_balance
Constructors Summary
public Account_Impl(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_Impl) {
            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;