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

class MySubordinate():
    #------------------------
    # MEMBER VARIABLES
    #------------------------
    #MySubordinate Attributes
    #MySubordinate Associations
    #------------------------
    # CONSTRUCTOR
    #------------------------
    def __init__(self, aNumber, aMyDriver):
        self._myDriver = None
        self._number = None
        self._number = aNumber
        didAddMyDriver = self.setMyDriver(aMyDriver)
        if not didAddMyDriver :
            raise RuntimeError ("Unable to create mySubordinate due to myDriver. 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 getMyDriver(self):
        return self._myDriver

    # Code from template association_SetOneToOptionalOne 
    def setMyDriver(self, aNewMyDriver):
        wasSet = False
        if aNewMyDriver is None :
            #Unable to setMyDriver to null, as mySubordinate must always be associated to a myDriver
            return wasSet
        existingMySubordinate = aNewMyDriver.getMySubordinate()
        if not (existingMySubordinate is None) and not self == existingMySubordinate :
            #Unable to setMyDriver, the current myDriver already has a mySubordinate, which would be orphaned if it were re-assigned
            return wasSet
        anOldMyDriver = self._myDriver
        self._myDriver = aNewMyDriver
        self._myDriver.setMySubordinate(self)
        if not (anOldMyDriver is None) :
            anOldMyDriver.setMySubordinate(None)
        wasSet = True
        return wasSet

    def delete(self):
        existingMyDriver = self._myDriver
        self._myDriver = None
        if not (existingMyDriver is None) :
            existingMyDriver.setMySubordinate(None)

    def __str__(self):
        return str(super().__str__()) + "[" + "number" + ":" + str(self.getNumber()) + "]" + str(os.linesep) + "  " + "myDriver = " + ((format(id(self.getMyDriver()), "x")) if not (self.getMyDriver() 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 "../OneToOptionalOneTest.ump"
import os

class MyDriver():
    #------------------------
    # MEMBER VARIABLES
    #------------------------
    #MyDriver Attributes
    #MyDriver Associations
    #------------------------
    # CONSTRUCTOR
    #------------------------
    def __init__(self, aName):
        self._mySubordinate = None
        self._name = None
        self._name = aName

    #------------------------
    # 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 getMySubordinate(self):
        return self._mySubordinate

    def hasMySubordinate(self):
        has = not (self._mySubordinate is None)
        return has

    # Code from template association_SetOptionalOneToOne 
    def setMySubordinate(self, aNewMySubordinate):
        wasSet = False
        if not (self._mySubordinate is None) and not self._mySubordinate == aNewMySubordinate and self == self._mySubordinate.getMyDriver() :
            #Unable to setMySubordinate, as existing mySubordinate would become an orphan
            return wasSet
        self._mySubordinate = aNewMySubordinate
        anOldMyDriver = (aNewMySubordinate.getMyDriver()) if not (aNewMySubordinate is None) else None
        if not self == anOldMyDriver :
            if not (anOldMyDriver is None) :
                anOldMyDriver.mySubordinate = None
            if not (self._mySubordinate is None) :
                self._mySubordinate.setMyDriver(self)
        wasSet = True
        return wasSet

    def delete(self):
        existingMySubordinate = self._mySubordinate
        self._mySubordinate = None
        if not (existingMySubordinate is None) :
            existingMySubordinate.delete()

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