#PLEASE DO NOT EDIT THIS CODE #This code was generated using the UMPLE 1.35.0.7523.c616a4dce modeling language! # line 5 "AssociationBothSidesSorted.ump" import os import pickle class Mentor(): #------------------------ # MEMBER VARIABLES #------------------------ #Mentor Attributes #Mentor Associations #------------------------ # CONSTRUCTOR #------------------------ def __init__(self, aName, aStudentsPriority): self._students = None self._studentsPriority = None self._name = None self._name = aName self._studentsPriority = aStudentsPriority self._students = [] #------------------------ # INTERFACE #------------------------ def setName(self, aName): wasSet = False self._name = aName wasSet = True return wasSet def setStudentsPriority(self, aStudentsPriority): wasSet = False self._studentsPriority = aStudentsPriority wasSet = True return wasSet def getName(self): return self._name 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__()) + "[" + "name" + ":" + str(self.getName()) + "]" + 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 #PLEASE DO NOT EDIT THIS CODE #This code was generated using the UMPLE 1.35.0.7523.c616a4dce modeling language! # line 1 "AssociationBothSidesSorted.ump" import os import pickle class Student(): #------------------------ # MEMBER VARIABLES #------------------------ #Student Attributes #Student Associations #------------------------ # CONSTRUCTOR #------------------------ def __init__(self, aId, aMentorsPriority): self._mentors = None self._mentorsPriority = None self._id = None self._id = aId self._mentorsPriority = aMentorsPriority self._mentors = [] #------------------------ # INTERFACE #------------------------ def setId(self, aId): wasSet = False self._id = aId wasSet = True return wasSet def setMentorsPriority(self, aMentorsPriority): wasSet = False self._mentorsPriority = aMentorsPriority wasSet = True return wasSet def getId(self): return self._id def getMentorsPriority(self): return self._mentorsPriority # 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_sorted_serializable_readObject def readObject(self, input): self.__dict__.clear() self.__dict__.update(pickle.load(input).__dict__) self._mentorsPriority = None 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()) + "]" + str(os.linesep) + " " + "mentorsPriority" + "=" + (((self.getMentorsPriority().__str__().replaceAll(" ", " ")) if not self.getMentorsPriority() == self else "this") if not (self.getMentorsPriority() is None) else "null") def __getstate__(self): state = dict(self.__dict__) state.pop("_mentorsPriority") return state