#PLEASE DO NOT EDIT THIS CODE #This code was generated using the UMPLE 1.35.0.7523.c616a4dce modeling language! # line 3 "../MNToMNTest.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_IsNumberOfValidMethod def isNumberOfStudentsValid(self): isValid = self.numberOfStudents() >= Mentor.minimumNumberOfStudents() and self.numberOfStudents() <= Mentor.maximumNumberOfStudents() return isValid # Code from template association_MinimumNumberOfMethod @staticmethod def minimumNumberOfStudents(): return 3 # Code from template association_MaximumNumberOfMethod @staticmethod def maximumNumberOfStudents(): return 6 # Code from template association_AddManyToManyMethod def addStudent(self, aStudent): wasAdded = False if (aStudent) in self._students : return False if self.numberOfStudents() >= Mentor.maximumNumberOfStudents() : return wasAdded self._students.append(aStudent) if aStudent.indexOfMentor(self) != -1 : wasAdded = True else : wasAdded = aStudent.addMentor(self) if not wasAdded : self._students.remove(aStudent) return wasAdded # Code from template association_AddMNToMany def removeStudent(self, aStudent): wasRemoved = False if not (aStudent) in self._students : return wasRemoved if self.numberOfStudents() <= Mentor.minimumNumberOfStudents() : return wasRemoved oldIndex = (-1 if not aStudent in self._students else self._students.index(aStudent)) self._students.remove(oldIndex) if aStudent.indexOfMentor(self) == -1 : wasRemoved = True else : wasRemoved = aStudent.removeMentor(self) if not wasRemoved : self._students.insert(oldIndex, aStudent) return wasRemoved # Code from template association_SetMNToMany def setStudents(self, *newStudents): newStudents = list(newStudents) wasSet = False verifiedStudents = [] for aStudent in newStudents: if (aStudent) in verifiedStudents : continue verifiedStudents.append(aStudent) if len(verifiedStudents) != len(newStudents) or len(verifiedStudents) < Mentor.minimumNumberOfStudents() or len(verifiedStudents) > Mentor.maximumNumberOfStudents() : return wasSet oldStudents = self._students.copy() self._students.clear() for aNewStudent in verifiedStudents: self._students.append(aNewStudent) if (aNewStudent) in oldStudents : oldStudents.remove(aNewStudent) else : aNewStudent.addMentor(self) for anOldStudent in oldStudents: anOldStudent.removeMentor(self) wasSet = True return wasSet # 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): from Student import Student copyOfStudents = self._students.copy() self._students.clear() for aStudent in copyOfStudents: if aStudent.numberOfMentors() <= Student.minimumNumberOfMentors() : aStudent.delete() else : aStudent.removeMentor(self) def __str__(self): return str(super().__str__()) + "[" + "name" + ":" + str(self.getName()) + "]" #PLEASE DO NOT EDIT THIS CODE #This code was generated using the UMPLE 1.35.0.7523.c616a4dce modeling language! # line 9 "../MNToMNTest.ump" class Student(): #------------------------ # MEMBER VARIABLES #------------------------ #Student Attributes #Student Associations #------------------------ # CONSTRUCTOR #------------------------ def __init__(self, aNumber): self._mentors = None self._number = None self._number = aNumber self._mentors = [] #------------------------ # INTERFACE #------------------------ def setNumber(self, aNumber): wasSet = False self._number = aNumber wasSet = True return wasSet def getNumber(self): return self._number # Code from template association_GetMany def getMentor(self, index): aMentor = self._mentors[index] return aMentor def getMentors(self): newMentors = tuple(self._mentors) return newMentors def numberOfMentors(self): self._number = len(self._mentors) return self._number def hasMentors(self): has = len(self._mentors) > 0 return has def indexOfMentor(self, aMentor): index = (-1 if not aMentor in self._mentors else self._mentors.index(aMentor)) return index # Code from template association_IsNumberOfValidMethod def isNumberOfMentorsValid(self): isValid = self.numberOfMentors() >= Student.minimumNumberOfMentors() and self.numberOfMentors() <= Student.maximumNumberOfMentors() return isValid # Code from template association_MinimumNumberOfMethod @staticmethod def minimumNumberOfMentors(): return 2 # Code from template association_MaximumNumberOfMethod @staticmethod def maximumNumberOfMentors(): return 4 # Code from template association_AddManyToManyMethod def addMentor(self, aMentor): wasAdded = False if (aMentor) in self._mentors : return False if self.numberOfMentors() >= Student.maximumNumberOfMentors() : return wasAdded self._mentors.append(aMentor) if aMentor.indexOfStudent(self) != -1 : wasAdded = True else : wasAdded = aMentor.addStudent(self) if not wasAdded : self._mentors.remove(aMentor) return wasAdded # Code from template association_AddMNToMany def removeMentor(self, aMentor): wasRemoved = False if not (aMentor) in self._mentors : return wasRemoved if self.numberOfMentors() <= Student.minimumNumberOfMentors() : return wasRemoved oldIndex = (-1 if not aMentor in self._mentors else self._mentors.index(aMentor)) self._mentors.remove(oldIndex) if aMentor.indexOfStudent(self) == -1 : wasRemoved = True else : wasRemoved = aMentor.removeStudent(self) if not wasRemoved : self._mentors.insert(oldIndex, aMentor) return wasRemoved # Code from template association_SetMNToMany def setMentors(self, *newMentors): newMentors = list(newMentors) wasSet = False verifiedMentors = [] for aMentor in newMentors: if (aMentor) in verifiedMentors : continue verifiedMentors.append(aMentor) if len(verifiedMentors) != len(newMentors) or len(verifiedMentors) < Student.minimumNumberOfMentors() or len(verifiedMentors) > Student.maximumNumberOfMentors() : return wasSet oldMentors = self._mentors.copy() self._mentors.clear() for aNewMentor in verifiedMentors: self._mentors.append(aNewMentor) if (aNewMentor) in oldMentors : oldMentors.remove(aNewMentor) else : aNewMentor.addStudent(self) for anOldMentor in oldMentors: anOldMentor.removeStudent(self) wasSet = True return wasSet # Code from template association_AddIndexControlFunctions def addMentorAt(self, aMentor, index): wasAdded = False if self.addMentor(aMentor) : if index < 0 : index = 0 if index > self.numberOfMentors() : index = self.numberOfMentors() - 1 self._mentors.remove(aMentor) self._mentors.insert(index, aMentor) wasAdded = True return wasAdded def addOrMoveMentorAt(self, aMentor, index): wasAdded = False if (aMentor) in self._mentors : if index < 0 : index = 0 if index > self.numberOfMentors() : index = self.numberOfMentors() - 1 self._mentors.remove(aMentor) self._mentors.insert(index, aMentor) wasAdded = True else : wasAdded = self.addMentorAt(aMentor, index) return wasAdded def delete(self): from Mentor import Mentor copyOfMentors = self._mentors.copy() self._mentors.clear() for aMentor in copyOfMentors: if aMentor.numberOfStudents() <= Mentor.minimumNumberOfStudents() : aMentor.delete() else : aMentor.removeStudent(self) def __str__(self): return str(super().__str__()) + "[" + "number" + ":" + str(self.getNumber()) + "]"