<?php /*PLEASE DO NOT EDIT THIS CODE*/ /*This code was generated using the UMPLE 1.32.1.6535.66c005ced modeling language!*/ class Mentor { //------------------------ // MEMBER VARIABLES //------------------------ //Mentor Attributes private $name; private $studentsPriority; //Mentor Associations private $students; //------------------------ // CONSTRUCTOR //------------------------ public function __construct($aName) { $this->name = $aName; $this->studentsPriority = function($x, $y) { return $x->getId() - $y->getId(); }; $this->students = array(); } //------------------------ // INTERFACE //------------------------ public function setName($aName) { $wasSet = false; $this->name = $aName; $wasSet = true; return $wasSet; } public function setStudentsPriority($aStudentsPriority) { $wasSet = false; $this->studentsPriority = $aStudentsPriority; $wasSet = true; return $wasSet; } public function getName() { return $this->name; } public function getStudentsPriority() { return $this->studentsPriority; } public function getStudent_index($index) { $aStudent = $this->students[$index]; return $aStudent; } public function getStudents() { $newStudents = $this->students; return $newStudents; } public function numberOfStudents() { $number = count($this->students); return $number; } public function hasStudents() { $has = $this->numberOfStudents() > 0; return $has; } public function indexOfStudent($aStudent) { $wasFound = false; $index = 0; foreach($this->students as $student) { if ($student->equals($aStudent)) { $wasFound = true; break; } $index += 1; } $index = $wasFound ? $index : -1; return $index; } public static function minimumNumberOfStudents() { return 0; } public function addStudent($aStudent) { $wasAdded = false; if ($this->indexOfStudent($aStudent) !== -1) { return false; } $this->students[] = $aStudent; if ($aStudent->indexOfMentor($this) != -1) { $wasAdded = true; } else { $wasAdded = $aStudent->addMentor($this); if (!$wasAdded) { array_pop($this->students); } } if(wasAdded) usort($this->students, $this->studentsPriority); return $wasAdded; } public function removeStudent($aStudent) { $wasRemoved = false; if ($this->indexOfStudent($aStudent) == -1) { return $wasRemoved; } $oldIndex = $this->indexOfStudent($aStudent); unset($this->students[$oldIndex]); if ($aStudent->indexOfMentor($this) == -1) { $wasRemoved = true; } else { $wasRemoved = $aStudent->removeMentor($this); if (!$wasRemoved) { $this->students[$oldIndex] = $aStudent; ksort($this->students); } } $this->students = array_values($this->students); return $wasRemoved; } public function equals($compareTo) { return $this == $compareTo; } public function delete() { $copyOfStudents = $this->students; $this->students = array(); foreach ($copyOfStudents as $aStudent) { $aStudent->removeMentor($this); } } } ?> <?php /*PLEASE DO NOT EDIT THIS CODE*/ /*This code was generated using the UMPLE 1.32.1.6535.66c005ced modeling language!*/ class Student { //------------------------ // MEMBER VARIABLES //------------------------ //Student Attributes private $id; private $mentorsPriority; //Student Associations private $mentors; //------------------------ // CONSTRUCTOR //------------------------ public function __construct($aId) { $this->id = $aId; $this->mentorsPriority = function($x, $y) { return $x->getName() - $y->getName(); }; $this->mentors = array(); } //------------------------ // INTERFACE //------------------------ public function setId($aId) { $wasSet = false; $this->id = $aId; $wasSet = true; return $wasSet; } public function setMentorsPriority($aMentorsPriority) { $wasSet = false; $this->mentorsPriority = $aMentorsPriority; $wasSet = true; return $wasSet; } public function getId() { return $this->id; } public function getMentorsPriority() { return $this->mentorsPriority; } public function getMentor_index($index) { $aMentor = $this->mentors[$index]; return $aMentor; } public function getMentors() { $newMentors = $this->mentors; return $newMentors; } public function numberOfMentors() { $number = count($this->mentors); return $number; } public function hasMentors() { $has = $this->numberOfMentors() > 0; return $has; } public function indexOfMentor($aMentor) { $wasFound = false; $index = 0; foreach($this->mentors as $mentor) { if ($mentor->equals($aMentor)) { $wasFound = true; break; } $index += 1; } $index = $wasFound ? $index : -1; return $index; } public static function minimumNumberOfMentors() { return 0; } public function addMentor($aMentor) { $wasAdded = false; if ($this->indexOfMentor($aMentor) !== -1) { return false; } $this->mentors[] = $aMentor; if ($aMentor->indexOfStudent($this) != -1) { $wasAdded = true; } else { $wasAdded = $aMentor->addStudent($this); if (!$wasAdded) { array_pop($this->mentors); } } if(wasAdded) usort($this->mentors, $this->mentorsPriority); return $wasAdded; } public function removeMentor($aMentor) { $wasRemoved = false; if ($this->indexOfMentor($aMentor) == -1) { return $wasRemoved; } $oldIndex = $this->indexOfMentor($aMentor); unset($this->mentors[$oldIndex]); if ($aMentor->indexOfStudent($this) == -1) { $wasRemoved = true; } else { $wasRemoved = $aMentor->removeStudent($this); if (!$wasRemoved) { $this->mentors[$oldIndex] = $aMentor; ksort($this->mentors); } } $this->mentors = array_values($this->mentors); return $wasRemoved; } public function equals($compareTo) { return $this == $compareTo; } public function delete() { $copyOfMentors = $this->mentors; $this->mentors = array(); foreach ($copyOfMentors as $aMentor) { $aMentor->removeStudent($this); } } } ?>