/* Sample solution to SE304 Lab 2
** Author: Margaret McGaley
** Ammended by: Gareth Carter
** Questions 1 & 4 can be found within
*/
package dbcvote;

import java.util.LinkedList;

public class VoteReader {
       /* this class would read from a file,
        * but we want to avoid Java I/O */
       private Preference[][] voteList =
       {
           /* Question 1 (a)
             Good Full Ballot
             Good Partial Ballot
             Missing first Preference
             Missing other Preference
             Duplicate First Preference
             Duplicate other Preference
             Extra Preference Value
             Empty Ballot
             Non Candidate Preference
           */

           /* Question 1 (b) */
            { // Good Full Ballot
              new Preference("Abbott, Mary", 5),
              new Preference("Dingle, Sally", 1),
              new Preference("Flood, Jerry", 4),
              new Preference("Moody, Claire", 2),
              new Preference("Thompson, Pat", 3)
            },

            { // Good Partial Ballot
              new Preference("Dingle, Sally", 1),
              new Preference("Moody, Claire", 2),
              new Preference("Thompson, Pat", 3)
            },

            { // Missing first Preference
              new Preference("Byrne, Joseph", 5),
              new Preference("Flood, Jerry", 4),
              new Preference("Simpson, Dave", 3),
              new Preference("Thompson, Pat", 2)
            },

            { // Missing other Preference
              new Preference("Byrne, Joseph", 1),
              new Preference("Flood, Jerry", 4),
              new Preference("Simpson, Dave", 3),
              new Preference("Thompson, Pat", 2)
            },

            { // Duplicate First Preference
              new Preference("Abbott, Mary", 4),
              new Preference("Dingle, Sally", 1),
              new Preference("Flood, Jerry", 1),
              new Preference("Moody, Claire", 2),
              new Preference("Thompson, Pat", 3)
            },

            { // Duplicate other Preference
              new Preference("Byrne, Joseph", 3),
              new Preference("Dingle, Sally", 1),
              new Preference("Flood, Jerry", 4),
              new Preference("Simpson, Dave", 3),
              new Preference("Thompson, Pat", 2)
            },

            { // Extra Preference Value
              new Preference("Abbott, Mary", 6),
              new Preference("Abbott, Mary", 5),
              new Preference("Dingle, Sally", 4),
              new Preference("Flood, Jerry", 1),
              new Preference("Moody, Claire", 2),
              new Preference("Thompson, Pat", 3)
            },

            { // Empty Ballot

            },

            { // Non Candidate Preference
              new Preference("Locke, Joseph", 6),
              new Preference("Abbott, Mary", 5),
              new Preference("Dingle, Sally", 4),
              new Preference("Flood, Jerry", 1),
              new Preference("Moody, Claire", 2),
              new Preference("Thompson, Pat", 3)
            },
       };

       public Vote[] loadVotes() {
              Vote[] votes = new Vote[voteList.length];

              for (int i = 0; i < votes.length; i++) {
                 LinkedList prefs = new LinkedList();
                 for (int j = 0; j < voteList[i].length; j++) {
                     prefs.add(voteList[i][j]);
                 }

                 votes[i] = new Vote(prefs);
              }

              return votes;
       }

       public /*@ pure */ static String toString(/*@ non_null @*/ Vote[] votes) {
              String out = new String();

              for (int i = 0; i < votes.length; i++) {
                  out += votes[i].toString();
              }

              return out;
       }

       public static void main(String args[]) {
              VoteReader vr = new VoteReader();

              Vote[] votes = vr.loadVotes();

              for (int i = 0; i < votes.length; i++) {
                  System.out.println("Vote " + i);
                  System.out.println(votes[i].toString());

                  System.out.println("Vote " + i + ", validated");
                  try {
                      votes[i].validateVote();
                  }
                  catch (SpoiledVoteException e) {
                      System.out.println(e.getMessage());
                  }
                  System.out.println(votes[i].toString());
              }
       }
}

