/*This code was generated using the UMPLE modeling language! Date of generation: 2008/07/30 12:12:16*/ /*This class drives: Position*/ package ElectorialSystem.core; import java.util.*; import ElectorialSystem.*; import ElectorialSystem.json.*; public class ElectedBody { //Class datatypes private String description; //Class association variables private List positions; //Registry of our system. ElectorialSystemRegistry registry = ElectorialSystemRegistry.getInstance(); //Constructor public ElectedBody(String aDescription) { description = aDescription; positions = new ArrayList(); registry.add(positions); } public boolean setDescription(String aDescription) { description = aDescription; return true; } public String getDescription() { return description; } public List getPositions() { return positions; } public Position addPosition(String aDescription, ElectedBody aElectedBody) { Position newPosition; newPosition = new Position(aDescription, this); if (!positions.contains(newPosition)) { registry.add(newPosition); positions.add(newPosition); } return newPosition; } public Position addPosition(Position aPosition) { if (!positions.contains(aPosition)) positions.add(aPosition); return aPosition; } public void delete() { //Delete all many ends first. for (Position aPosition : positions) { aPosition.delete(); } positions.clear(); } public void deletePosition(Position aPosition) { if (positions.contains(aPosition)) { positions.remove(aPosition); //registry.removeObj(registry.getKey(aPosition)); } else //Throw an UmpleException .. to be implemented. { } } public boolean areManyEndsNull() { if (positions.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; } }