import java.io.*;
import java.util.*;

//
// NOTE:  The commented lines are the old ArrayList code, and the
// lines immediately following is the code for using an array instead.
//

//public class CandidateList extends Object
public class CandidateArray extends Object
{
  private int candidateCount; // new variable to handle filled count
  private Candidate theCandidate = new Candidate();
//  public ArrayList<Candidate> theList;
  private Candidate[] theArray;

/** Construct a new candidate with the given information.
**/
//  public CandidateList()
  public CandidateArray(int howMany)
  {
//    this.theList = new ArrayList<Candidate>();
    this.theArray = new Candidate[howMany];
    this.candidateCount = 0; // new code
  }

/******************************************************************************/
/* Accessors                                                                  */
/******************************************************************************/
  public int getCandidateCount()  // new accessor for the new variable
  {
    return this.candidateCount;
  }

/******************************************************************************/
/* Mutators                                                                   */
/******************************************************************************/
  public void setCandidateCount(int theValue)  // new mutator for the new variable
  {
    this.candidateCount = theValue;
  }

/******************************************************************************/
/* Utilities                                                                  */
/******************************************************************************/
/******************************************************************************/
//  public int getListLength()
  public int getArrayLength()
  {
//    return this.theList.size();
//    return this.theArray.length;
    return this.candidateCount;
  }

/******************************************************************************/
//  public void getTheList(Scanner dataFile)
  public void getTheArray(Scanner dataFile)
  {
//
// NOTE that we are using 'candidateCount' as the actual count, but indexing
// zero-up so that a count of 10 would mean data stored in locations 0 through 9
//
    this.setCandidateCount(0);
    System.out.println("File input processing beginning");
    while(true == dataFile.hasNext())
    {
      theCandidate = new Candidate();

      theCandidate.getData(dataFile);
//      this.theList.add(theCandidate);
      this.theArray[this.getCandidateCount()] = theCandidate;
      this.setCandidateCount(this.getCandidateCount() + 1);

    } // while(true == dataFile.hasNext())

    System.out.println("File input processing ended");
//  } // public void getTheList(Scanner dataFile)
  } // public void getTheArray(Scanner dataFile)

/******************************************************************************/
//  public void printTheList()
  public void printTheArray()
  {
    for(int i = 0; i < this.getArrayLength(); ++i)
    {
//      System.out.printf("%2d %s%n",i,this.theList.get(i).toString());
      System.out.printf("%2d %s%n",i,this.theArray[i].toString());
    }
//  } // public void printTheList()
  } // public void printTheArray()

/******************************************************************************/
  public void printByParty(String matchString)
  {
//    for(int i = 0; i < this.getListLength(); ++i)
    for(int i = 0; i < this.getArrayLength(); ++i)
    {
//      if(this.theList.get(i).getParty().equals(matchString))
      if(this.theArray[i].getParty().equals(matchString))
//        System.out.printf("%2d %s%n",i,this.theList.get(i).toString());
        System.out.printf("%2d %s%n",i,this.theArray[i].toString());
    }
  } // public void printByParty(String matchString)

/******************************************************************************/
  public void printByState(String matchString)
  {
//    for(int i = 0; i < this.getListLength(); ++i)
    for(int i = 0; i < this.getArrayLength(); ++i)
    {
//      if(this.theList.get(i).getState().equals(matchString))
      if(this.theArray[i].getState().equals(matchString))
//        System.out.printf("%2d %s%n",i,this.theList.get(i).toString());
        System.out.printf("%2d %s%n",i,this.theArray[i].toString());
    }
  } // public void printByState(String matchString)

/******************************************************************************/
  public void printWithMatch(Fields which, String matchString)
  {
    boolean printIt;

//    for(int i = 0; i < this.getListLength(); ++i)
    for(int i = 0; i < this.getArrayLength(); ++i)
    {
      printIt = false;
      if(Fields.ANYRECORD == which)
      {
        printIt = true;
      }
      if(Fields.FIRSTNAME == which)
      {
//        if(this.theList.get(i).getFirstName().equals(matchString))
        if(this.theArray[i].getFirstName().equals(matchString))
        printIt = true;
      }
      else if(Fields.LASTNAME == which)
      {
//        if(this.theList.get(i).getLastName().equals(matchString))
        if(this.theArray[i].getLastName().equals(matchString))
        printIt = true;
      }
      else if(Fields.PARTY == which)
      {
//        if(this.theList.get(i).getParty().equals(matchString))
        if(this.theArray[i].getParty().equals(matchString))
        printIt = true;
      }
      else if(Fields.STATE == which)
      {
//        if(this.theList.get(i).getState().equals(matchString))
        if(this.theArray[i].getState().equals(matchString))
        printIt = true;
      }
      else if(Fields.BIRTHPLACE == which)
      {
//        if(this.theList.get(i).getBirthPlace().equals(matchString))
        if(this.theArray[i].getBirthPlace().equals(matchString))
        printIt = true;
      }

      if(printIt)
      {
//        System.out.printf("%2d %s%n",i,this.theList.get(i).toString());
        System.out.printf("%2d %s%n",i,this.theArray[i].toString());
      }
    }
  } // public void printByState(String matchString)

//} // public class CandidateList extends Object
} // public class CandidateArray extends Object

