/* Util */ import java.util.Vector; /* IO */ import java.io.FileReader; import java.io.BufferedReader; import java.io.IOException; import java.io.FileWriter; import java.io.BufferedWriter; import java.io.PrintWriter; /* Beans */ import beans.jw.Customer; /* CustomerManager.java ==================== This class loads all the Customer data from persistent memory. However it does NOT load Customer related data such as Accounts and Cards, such data is loaded by other 'Manager' classes. Other 'Manager' classes are triggered from this class to load data that the Customer object depends on, such as Account details, Card types etc. Therefore the loading of other 'Manager' classes must be done BEFORE the actual Customer objects can be created. */ class CustomerManager { private final static String CUSTOMERS = "database/CUSTOMERS.txt"; /* The order of customer data in the database. */ private static final int NAME = 0; private static final int ACCOUNTS = 1; /* Vector stores all customers in database. */ private static Vector customers = new Vector(); /* Use a temp object when populating the Vector. */ private static Customer tmpCustomer = new Customer(); /* Stores the location in the vector of the Customer object being viewed. If no Customer is being viewed then it's -1.*/ private static int inUse = -1; public CustomerManager() { } public static void open() { /* Before we can create Customers, we must load the Accounts database. */ AccountsManager.open(); /* Now we can load the Customer data (it uses the previously loaded Accounts. */ loadCustomers(); } /* Used to flag a specific Customer in the vector, as 'currently being viewed' by the user. */ public static void use(int x) { inUse = x; } /* Used when no Customers are being viewed, such as when the user is viewing the full customer list. */ public static void release() { inUse = -1; } /* Used to remove a spefifc customer form the Vector */ public static void expunge(int x) { customers.removeElementAt(x); } /* Return the index position of the current Customer in use. */ public static int currentCustomer() { return inUse; } /* Return the Customer object of the current Customer in used by the user. */ public static Customer getActiveCustomer() { if (inUse >= 0) return (Customer) customers.elementAt(inUse); return null; } /* Return the total number of customers loaded from the database. Tis figure is 'live' and will be 1 less, if, for example the user deletes a customer. */ public static int getNumberCustomers() { return customers.size(); } /* Return the Customer object of any customer. Used when loaded the initial Customer list. */ public static Customer getCustomer(int x) { return (Customer) customers.elementAt(x); } /* Convert the vector of customers into a 2 dimensional array for Table (list of Customers). */ public static String[][] getNamesArray() { String[][] data = new String[customers.size()][2]; for (int i=0;i