/*This code was generated using the UMPLE modeling language! Date of generation: 2008/07/30 12:12:16*/ /*This class drives: Candidature*/ package ElectorialSystem.core; import java.util.*; import ElectorialSystem.*; import ElectorialSystem.json.*; public class Voter { //Class datatypes private String name; private String address; //Class association variables private PollInElection pollInElection; private List candidatures; private ElectoralDistrict electoralDistrict; //Registry of our system. ElectorialSystemRegistry registry = ElectorialSystemRegistry.getInstance(); //Constructor public Voter(String aName, String aAddress, PollInElection aPollInElection, ElectoralDistrict aElectoralDistrict) { name = aName; address = aAddress; pollInElection = aPollInElection; pollInElection.addVoter(this); candidatures = new ArrayList(); registry.add(candidatures); electoralDistrict = aElectoralDistrict; electoralDistrict.addVoter(this); } public boolean setName(String aName) { name = aName; return true; } public boolean setAddress(String aAddress) { address = aAddress; return true; } public String getName() { return name; } public String getAddress() { return address; } public PollInElection getPollInElection() { return pollInElection; } public List getCandidatures() { return candidatures; } public ElectoralDistrict getElectoralDistrict() { return electoralDistrict; } public Candidature addCandidature(String aIsIncumbent, ElectionForPosition aElectionForPosition, Candidate aCandidate) { Candidature newCandidature; newCandidature = new Candidature(aIsIncumbent, aElectionForPosition, aCandidate); if (!candidatures.contains(newCandidature)) { registry.add(newCandidature); candidatures.add(newCandidature); } return newCandidature; } public Candidature addCandidature(Candidature aCandidature) { if (!candidatures.contains(aCandidature)) candidatures.add(aCandidature); return aCandidature; } /* This class does not drive PollInElection and therefore sets the association unidirectionally.*/ public void setPollInElection(PollInElection aPollInElection) { pollInElection = aPollInElection; } /* This class does not drive ElectoralDistrict and therefore sets the association unidirectionally.*/ public void setElectoralDistrict(ElectoralDistrict aElectoralDistrict) { electoralDistrict = aElectoralDistrict; } public void delete() { //Delete all many ends first. for (Candidature aCandidature : candidatures) { aCandidature.delete(); } candidatures.clear(); //Delete all 1 ends. pollInElection.deleteVoter(this); electoralDistrict.deleteVoter(this); } public void deleteCandidature(Candidature aCandidature) { if (candidatures.contains(aCandidature)) { candidatures.remove(aCandidature); //registry.removeObj(registry.getKey(aCandidature)); } else //Throw an UmpleException .. to be implemented. { } } public boolean areManyEndsNull() { if (candidatures.size() == 0) { return true; } else return false; } /*********************************** * Returns the attribute list along with the * class ID in JSON format. ***********************************/ public JSONObject getAttributes() throws JSONException { JSONObject obj = new JSONObject(); obj.put("CLASS_ID", registry.getKey(this)); obj.put("name", getName()); obj.put("address", getAddress()); return obj; } }