/*This code was generated using the UMPLE modeling language! Date of generation: 2008/07/30 12:12:16*/ /*This class drives: ElectionForPosition*/ package ElectorialSystem.core; import java.util.*; import ElectorialSystem.*; import ElectorialSystem.json.*; public class Position { //Class datatypes private String description; //Class association variables private ElectedBody electedBody; private List electionForPositions; private ElectoralDistrict electoralDistrict; //Registry of our system. ElectorialSystemRegistry registry = ElectorialSystemRegistry.getInstance(); //Constructor public Position(String aDescription, ElectedBody aElectedBody) { description = aDescription; electedBody = aElectedBody; electedBody.addPosition(this); electionForPositions = new ArrayList(); registry.add(electionForPositions); } public boolean setDescription(String aDescription) { description = aDescription; return true; } public String getDescription() { return description; } public ElectedBody getElectedBody() { return electedBody; } public List getElectionForPositions() { return electionForPositions; } public ElectoralDistrict getElectoralDistrict() { return electoralDistrict; } public ElectionForPosition addElectionForPosition(Election aElection, Position aPosition) { ElectionForPosition newElectionForPosition; newElectionForPosition = new ElectionForPosition(aElection, this); if (!electionForPositions.contains(newElectionForPosition)) { registry.add(newElectionForPosition); electionForPositions.add(newElectionForPosition); } return newElectionForPosition; } public ElectionForPosition addElectionForPosition( ElectionForPosition aElectionForPosition) { if (!electionForPositions.contains(aElectionForPosition)) electionForPositions.add(aElectionForPosition); return aElectionForPosition; } /* This class does not drive ElectedBody and therefore sets the association unidirectionally.*/ public void setElectedBody(ElectedBody aElectedBody) { electedBody = aElectedBody; } /* 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 (ElectionForPosition aElectionForPosition : electionForPositions) { aElectionForPosition.delete(); } electionForPositions.clear(); //Delete all 1 ends. electedBody.deletePosition(this); electoralDistrict.deletePosition(this); } public void deleteElectionForPosition(ElectionForPosition aElectionForPosition) { if (electionForPositions.contains(aElectionForPosition)) { electionForPositions.remove(aElectionForPosition); //registry.removeObj(registry.getKey(aElectionForPosition)); } else //Throw an UmpleException .. to be implemented. { } } public void deleteElectoralDistrict(ElectoralDistrict aElectoralDistrict) { if (aElectoralDistrict.equals(electoralDistrict)) { electoralDistrict = null; registry.removeObj(registry.getKey(aElectoralDistrict)); } else //Throw an UmpleException .. to be implemented. { } } public boolean areManyEndsNull() { if (electionForPositions.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("description", getDescription()); return obj; } }