#PLEASE DO NOT EDIT THIS CODE
#This code was generated using the UMPLE 1.35.0.7523.c616a4dce modeling language!
# line 3 "../SingletonToOneTest.ump"
import os

class Student():
    #------------------------
    # MEMBER VARIABLES
    #------------------------
    #Student Attributes
    #Student Associations
    #------------------------
    # CONSTRUCTOR
    #------------------------
    def __init__(self, aNumber, aMentor):
        self._mentor = None
        self._number = None
        self._number = aNumber
        didAddMentor = self.setMentor(aMentor)
        if not didAddMentor :
            raise RuntimeError ("Unable to create student due to mentor. See https://manual.umple.org?RE002ViolationofAssociationMultiplicity.html")

    #------------------------
    # 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

    # Code from template association_SetOneToOptionalOne 
    def setMentor(self, aNewMentor):
        wasSet = False
        if aNewMentor is None :
            #Unable to setMentor to null, as student must always be associated to a mentor
            return wasSet
        existingStudent = aNewMentor.getStudent()
        if not (existingStudent is None) and not self == existingStudent :
            #Unable to setMentor, the current mentor already has a student, which would be orphaned if it were re-assigned
            return wasSet
        anOldMentor = self._mentor
        self._mentor = aNewMentor
        self._mentor.setStudent(self)
        if not (anOldMentor is None) :
            anOldMentor.setStudent(None)
        wasSet = True
        return wasSet

    def delete(self):
        existingMentor = self._mentor
        self._mentor = None
        if not (existingMentor is None) :
            existingMentor.setStudent(None)

    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 8 "../SingletonToOneTest.ump"
import os

class Mentor():
    theInstance = None
    #------------------------
    # STATIC VARIABLES
    #------------------------
    #------------------------
    # MEMBER VARIABLES
    #------------------------
    #Mentor Attributes
    #Mentor Associations
    #------------------------
    # CONSTRUCTOR
    #------------------------
    def __init__(self):
        self._student = None
        self._name = None
        self._name = None

    @staticmethod
    def getInstance():
        if Mentor.theInstance is None :
            Mentor.theInstance = Mentor()
        return Mentor.theInstance

    #------------------------
    # INTERFACE
    #------------------------
    def setName(self, aName):
        wasSet = False
        self._name = aName
        wasSet = True
        return wasSet

    def getName(self):
        return self._name

    # Code from template association_GetOne 
    def getStudent(self):
        return self._student

    def hasStudent(self):
        has = not (self._student is None)
        return has

    # Code from template association_SetOptionalOneToOne 
    def setStudent(self, aNewStudent):
        wasSet = False
        if not (self._student is None) and not self._student == aNewStudent and self == self._student.getMentor() :
            #Unable to setStudent, as existing student would become an orphan
            return wasSet
        self._student = aNewStudent
        anOldMentor = (aNewStudent.getMentor()) if not (aNewStudent is None) else None
        if not self == anOldMentor :
            if not (anOldMentor is None) :
                anOldMentor.student = None
            if not (self._student is None) :
                self._student.setMentor(self)
        wasSet = True
        return wasSet

    def delete(self):
        existingStudent = self._student
        self._student = None
        if not (existingStudent is None) :
            existingStudent.delete()

    def __str__(self):
        return str(super().__str__()) + "[" + "name" + ":" + str(self.getName()) + "]" + str(os.linesep) + "  " + "student = " + ((format(id(self.getStudent()), "x")) if not (self.getStudent() is None) else "null")