import java.io.*; import java.util.*; public class CandidateList extends Object { private Candidate theCandidate = new Candidate(); public ArrayList theList; /** Construct a new candidate with the given information. **/ public CandidateList() { theList = new ArrayList(); } /******************************************************************************/ /* Accessors */ /******************************************************************************/ /******************************************************************************/ /* Mutators */ /******************************************************************************/ /******************************************************************************/ /* Utilities */ /******************************************************************************/ /******************************************************************************/ public int getListLength() { return this.theList.size(); } /******************************************************************************/ public void getTheList(Scanner dataFile) { System.out.println("File input processing beginning"); while(true == dataFile.hasNext()) { theCandidate = new Candidate(); // System.out.println("get data"); theCandidate.getData(dataFile); // System.out.println("got data"); this.theList.add(theCandidate); // System.out.println("added to list"); } // while(true == dataFile.hasNext()) System.out.println("File input processing ended"); } // public void getTheList(Scanner dataFile) /******************************************************************************/ public void printTheList() { for(int i = 0; i < this.getListLength(); ++i) { System.out.printf("%2d %s%n",i,this.theList.get(i).toString()); } } // public void printTheList() /******************************************************************************/ public void printByParty(String matchString) { for(int i = 0; i < this.getListLength(); ++i) { if(this.theList.get(i).getParty().equals(matchString)) System.out.printf("%2d %s%n",i,this.theList.get(i).toString()); } } // public void printByParty(String matchString) /******************************************************************************/ public void printByState(String matchString) { for(int i = 0; i < this.getListLength(); ++i) { if(this.theList.get(i).getState().equals(matchString)) System.out.printf("%2d %s%n",i,this.theList.get(i).toString()); } } // public void printByState(String matchString) /******************************************************************************/ public void printWithMatch(Fields which, String matchString) { boolean printIt; for(int i = 0; i < this.getListLength(); ++i) { printIt = false; if(Fields.ANYRECORD == which) { printIt = true; } if(Fields.FIRSTNAME == which) { if(this.theList.get(i).getFirstName().equals(matchString)) printIt = true; } else if(Fields.LASTNAME == which) { if(this.theList.get(i).getLastName().equals(matchString)) printIt = true; } else if(Fields.PARTY == which) { if(this.theList.get(i).getParty().equals(matchString)) printIt = true; } else if(Fields.STATE == which) { if(this.theList.get(i).getState().equals(matchString)) printIt = true; } else if(Fields.BIRTHPLACE == which) { if(this.theList.get(i).getBirthPlace().equals(matchString)) printIt = true; } if(printIt) { System.out.printf("%2d %s%n",i,this.theList.get(i).toString()); } } } // public void printByState(String matchString) } // public class CandidateList extends Object