import java.util.*; import java.math.*; /** This class represents a conceptual "file" of all the accounts for a given bank. Normally, it would encapsulate the interface to a database containing records representing the accounts, which would be used to build Java BankAccount objects. Changes in the objects would be mapped back to record updates in the database. For this sample application, BankAccountFile just provides access to a very small collection of constructed test accounts. */ public class BankAccountFile { /** This class is a singleton, i.e., there can never be more than a single instance, in order to serialize access to accounts. The instance is held in currentInstance. */ private static BankAccountFile currentInstance; /** Holds the collection of all savings accounts. */ private static ArrayList savingsAccounts; /** Holds the collection of all checking accounts. */ private static ArrayList checkingAccounts; /** Holds an iterator over the collection of all savings accounts. */ private Iterator savingsAccountsIterator; /** Holds an iterator over the collection of all checking accounts. */ private Iterator checkingAccountsIterator; /* Static initializor to construct the test accounts. { BankAccount account; Address address; savingsAccounts = new ArrayList(2); checkingAccounts = new ArrayList(2); SavingsAccount.setInterestRate( 3.5 ); account = new SavingsAccount(); account.setAccountNumber("0001"); account.setName( new Name("Mr. Dave Collins") ); account.setAddress( address = new Address() ); address.setLine1( "1137 San Ildefonso Rd." ); address.setLine2( "Los Alamos, NM 87544" ); account.setBalance( new BigDecimal(10000.0) ); savingsAccounts.add(account); account = new SavingsAccount(); account.setAccountNumber("0002"); account.setName( new Name("Ms. Janet Smith") ); account.setAddress( address = new Address() ); address.setLine1( "1050 Trinity Blvd." ); address.setLine2( "Los Alamos, NM 87544" ); account.setBalance( new BigDecimal(10000.0) ); savingsAccounts.add(account); } */ /** Get the singleton instance of BankAccountFile. Create it if necessary. */ static BankAccountFile getCurrentInstance() { if (currentInstance == null) currentInstance = new BankAccountFile(); return currentInstance; } /** Create a BankAccountFile. */ BankAccountFile() { } Iterator getAccountsForType(String aTypeString) { if (aTypeString.equals("S")) return getSavingsAccounts(); else return getCheckingAccounts(); } /** Return the checking accounts collection iterator. */ Iterator getCheckingAccounts() { return checkingAccounts.iterator(); } /** Return the savings accounts collection iterator. */ Iterator getSavingsAccounts() { return savingsAccounts.iterator(); } }