#PLEASE DO NOT EDIT THIS CODE #This code was generated using the UMPLE 1.35.0.7523.c616a4dce modeling language! # line 1 "AssociationSorting.ump" import pickle class Student(): #------------------------ # MEMBER VARIABLES #------------------------ #Student Attributes #Student Associations #------------------------ # CONSTRUCTOR #------------------------ def __init__(self, aId): self._mentors = None self._id = None self._id = aId self._mentors = [] #------------------------ # INTERFACE #------------------------ def setId(self, aId): wasSet = False self._id = aId wasSet = True return wasSet def getId(self): return self._id # 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): number = len(self._mentors) return 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_MinimumNumberOfMethod @staticmethod def minimumNumberOfMentors(): return 0 # Code from template association_AddManyToManyMethod def addMentor(self, aMentor): wasAdded = False if (aMentor) in self._mentors : return False 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_RemoveMany def removeMentor(self, aMentor): wasRemoved = False if not (aMentor) in self._mentors : 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_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): copyOfMentors = self._mentors.copy() self._mentors.clear() for aMentor in copyOfMentors: aMentor.removeStudent(self) def __str__(self): return str(super().__str__()) + "[" + "id" + ":" + str(self.getId()) + "]" #PLEASE DO NOT EDIT THIS CODE #This code was generated using the UMPLE 1.35.0.7523.c616a4dce modeling language! # line 5 "AssociationSorting.ump" import os import pickle class Mentor(): #------------------------ # MEMBER VARIABLES #------------------------ #Mentor Attributes #Mentor Associations #------------------------ # CONSTRUCTOR #------------------------ def __init__(self, aStudentsPriority): self._students = None self._studentsPriority = None self._studentsPriority = aStudentsPriority self._students = [] #------------------------ # INTERFACE #------------------------ def setStudentsPriority(self, aStudentsPriority): wasSet = False self._studentsPriority = aStudentsPriority wasSet = True return wasSet def getStudentsPriority(self): return self._studentsPriority # 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_AddManyToManyMethod def addStudent(self, aStudent): wasAdded = False if (aStudent) in self._students : return False 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_RemoveMany def removeStudent(self, aStudent): wasRemoved = False if not (aStudent) in self._students : 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_sorted_serializable_readObject def readObject(self, input): self.__dict__.clear() self.__dict__.update(pickle.load(input).__dict__) self._studentsPriority = None def delete(self): copyOfStudents = self._students.copy() self._students.clear() for aStudent in copyOfStudents: aStudent.removeMentor(self) def __str__(self): return str(super().__str__()) + "[" + "]" + str(os.linesep) + " " + "studentsPriority" + "=" + (((self.getStudentsPriority().__str__().replaceAll(" ", " ")) if not self.getStudentsPriority() == self else "this") if not (self.getStudentsPriority() is None) else "null") def __getstate__(self): state = dict(self.__dict__) state.pop("_studentsPriority") return state