/*This code was generated using the UMPLE modeling language! Date of generation: 2008/07/29 14:51:25*/ /*This class drives: Topic*/ package University.core; import java.util.*; import University.*; import University.json.*; public class PrerequisiteReason { //Class datatypes //Class association variables private List materialNeededBySuccessors; private Course successor; private Course prerequisite; //Registry of our system. UniversityRegistry registry = UniversityRegistry.getInstance(); //Constructor public PrerequisiteReason(Course aSuccessor, Course aPrerequisite) { materialNeededBySuccessors = new ArrayList(); registry.add(materialNeededBySuccessors); successor = aSuccessor; successor.addSuccessorReason(this); prerequisite = aPrerequisite; prerequisite.addSuccessorReason(this); } public List getMaterialNeededBySuccessors() { return materialNeededBySuccessors; } public Course getSuccessor() { return successor; } public Course getPrerequisite() { return prerequisite; } public Topic addMaterialNeededBySuccessor() { Topic newTopic; newTopic = new Topic(); if (!materialNeededBySuccessors.contains(newTopic)) { registry.add(newTopic); materialNeededBySuccessors.add(newTopic); } return newTopic; } public Topic addMaterialNeededBySuccessor(Topic aMaterialNeededBySuccessor) { if (!materialNeededBySuccessors.contains(aMaterialNeededBySuccessor)) materialNeededBySuccessors.add(aMaterialNeededBySuccessor); return aMaterialNeededBySuccessor; } /* This class does not drive Course and therefore sets the association unidirectionally.*/ public void setSuccessor(Course aSuccessor) { successor = aSuccessor; } /* This class does not drive Course and therefore sets the association unidirectionally.*/ public void setPrerequisite(Course aPrerequisite) { prerequisite = aPrerequisite; } public void delete() { //Delete all many ends first. for (Topic aTopic : materialNeededBySuccessors) { aTopic.delete(); } materialNeededBySuccessors.clear(); //Delete all 1 ends. successor.deleteSuccessorReason(this); prerequisite.deleteSuccessorReason(this); } public void deleteMaterialNeededBySuccessor(Topic aTopic) { if (materialNeededBySuccessors.contains(aTopic)) { materialNeededBySuccessors.remove(aTopic); //registry.removeObj(registry.getKey(aTopic)); } else //Throw an UmpleException .. to be implemented. { } } public boolean areManyEndsNull() { if (materialNeededBySuccessors.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)); return obj; } }