#PLEASE DO NOT EDIT THIS CODE #This code was generated using the UMPLE 1.35.0.7523.c616a4dce modeling language! # line 9 "../OptionalOneToOptionalNTest.ump" import os class Student(): #------------------------ # MEMBER VARIABLES #------------------------ #Student Attributes #Student Associations #------------------------ # CONSTRUCTOR #------------------------ def __init__(self, aNumber): self._mentor = None self._number = None self._number = aNumber #------------------------ # INTERFACE #------------------------ def setNumber(self, aNumber): wasSet = False self._number = aNumber wasSet = True return wasSet def getNumber(self): return self._number # Code from template association_GetOne def getMentor(self): return self._mentor def hasMentor(self): has = not (self._mentor is None) return has # Code from template association_SetOptionalOneToOptionalN def setMentor(self, aMentor): from Mentor import Mentor wasSet = False if not (aMentor is None) and aMentor.numberOfStudents() >= Mentor.maximumNumberOfStudents() : return wasSet existingMentor = self._mentor self._mentor = aMentor if not (existingMentor is None) and not existingMentor == aMentor : existingMentor.removeStudent(self) if not (aMentor is None) : aMentor.addStudent(self) wasSet = True return wasSet def delete(self): if not (self._mentor is None) : placeholderMentor = self._mentor self._mentor = None placeholderMentor.removeStudent(self) def __str__(self): return str(super().__str__()) + "[" + "number" + ":" + str(self.getNumber()) + "]" + str(os.linesep) + " " + "mentor = " + ((format(id(self.getMentor()), "x")) if not (self.getMentor() is None) else "null") #PLEASE DO NOT EDIT THIS CODE #This code was generated using the UMPLE 1.35.0.7523.c616a4dce modeling language! # line 3 "../OptionalOneToOptionalNTest.ump" class Mentor(): #------------------------ # MEMBER VARIABLES #------------------------ #Mentor Attributes #Mentor Associations #------------------------ # CONSTRUCTOR #------------------------ def __init__(self, aName): self._students = None self._name = None self._name = aName self._students = [] #------------------------ # INTERFACE #------------------------ def setName(self, aName): wasSet = False self._name = aName wasSet = True return wasSet def getName(self): return self._name # Code from template association_GetMany def getStudent(self, index): aStudent = self._students[index] return aStudent def getStudents(self): newStudents = tuple(self._students) return newStudents def numberOfStudents(self): number = len(self._students) return number def hasStudents(self): has = len(self._students) > 0 return has def indexOfStudent(self, aStudent): index = (-1 if not aStudent in self._students else self._students.index(aStudent)) return index # Code from template association_MinimumNumberOfMethod @staticmethod def minimumNumberOfStudents(): return 0 # Code from template association_MaximumNumberOfMethod @staticmethod def maximumNumberOfStudents(): return 5 # Code from template association_AddOptionalNToOptionalOne def addStudent(self, aStudent): wasAdded = False if (aStudent) in self._students : return False if self.numberOfStudents() >= Mentor.maximumNumberOfStudents() : return wasAdded existingMentor = aStudent.getMentor() if existingMentor is None : aStudent.setMentor(self) elif not self == existingMentor : existingMentor.removeStudent(aStudent) self.addStudent(aStudent) else : self._students.append(aStudent) wasAdded = True return wasAdded def removeStudent(self, aStudent): wasRemoved = False if (aStudent) in self._students : self._students.remove(aStudent) aStudent.setMentor(None) wasRemoved = True return wasRemoved # Code from template association_AddIndexControlFunctions def addStudentAt(self, aStudent, index): wasAdded = False if self.addStudent(aStudent) : if index < 0 : index = 0 if index > self.numberOfStudents() : index = self.numberOfStudents() - 1 self._students.remove(aStudent) self._students.insert(index, aStudent) wasAdded = True return wasAdded def addOrMoveStudentAt(self, aStudent, index): wasAdded = False if (aStudent) in self._students : if index < 0 : index = 0 if index > self.numberOfStudents() : index = self.numberOfStudents() - 1 self._students.remove(aStudent) self._students.insert(index, aStudent) wasAdded = True else : wasAdded = self.addStudentAt(aStudent, index) return wasAdded def delete(self): while not self._students.isEmpty() : self._students[0].setMentor(None) def __str__(self): return str(super().__str__()) + "[" + "name" + ":" + str(self.getName()) + "]"