/*PLEASE DO NOT EDIT THIS CODE*/
/*This code was generated using the UMPLE 1.35.0.7523.c616a4dce modeling language!*/
package example;
// line 9 "../OneToOptionalOneTest.ump"
public class MySubordinate
{
//------------------------
// MEMBER VARIABLES
//------------------------
//MySubordinate Attributes
private String number;
//MySubordinate Associations
private MyDriver myDriver;
//------------------------
// CONSTRUCTOR
//------------------------
public MySubordinate(String aNumber, MyDriver aMyDriver)
{
number = aNumber;
boolean didAddMyDriver = setMyDriver(aMyDriver);
if (!didAddMyDriver)
{
throw new RuntimeException("Unable to create mySubordinate due to myDriver. See https://manual.umple.org?RE002ViolationofAssociationMultiplicity.html");
}
}
//------------------------
// INTERFACE
//------------------------
public boolean setNumber(String aNumber)
{
boolean wasSet = false;
number = aNumber;
wasSet = true;
return wasSet;
}
public String getNumber()
{
return number;
}
/* Code from template association_GetOne */
public MyDriver getMyDriver()
{
return myDriver;
}
/* Code from template association_SetOneToOptionalOne */
public boolean setMyDriver(MyDriver aNewMyDriver)
{
boolean wasSet = false;
if (aNewMyDriver == null)
{
//Unable to setMyDriver to null, as mySubordinate must always be associated to a myDriver
return wasSet;
}
MySubordinate existingMySubordinate = aNewMyDriver.getMySubordinate();
if (existingMySubordinate != null && !equals(existingMySubordinate))
{
//Unable to setMyDriver, the current myDriver already has a mySubordinate, which would be orphaned if it were re-assigned
return wasSet;
}
MyDriver anOldMyDriver = myDriver;
myDriver = aNewMyDriver;
myDriver.setMySubordinate(this);
if (anOldMyDriver != null)
{
anOldMyDriver.setMySubordinate(null);
}
wasSet = true;
return wasSet;
}
public void delete()
{
MyDriver existingMyDriver = myDriver;
myDriver = null;
if (existingMyDriver != null)
{
existingMyDriver.setMySubordinate(null);
}
}
public String toString()
{
return super.toString() + "["+
"number" + ":" + getNumber()+ "]" + System.getProperties().getProperty("line.separator") +
" " + "myDriver = "+(getMyDriver()!=null?Integer.toHexString(System.identityHashCode(getMyDriver())):"null");
}
}
/*PLEASE DO NOT EDIT THIS CODE*/
/*This code was generated using the UMPLE 1.35.0.7523.c616a4dce modeling language!*/
package example;
// line 3 "../OneToOptionalOneTest.ump"
public class MyDriver
{
//------------------------
// MEMBER VARIABLES
//------------------------
//MyDriver Attributes
private String name;
//MyDriver Associations
private MySubordinate mySubordinate;
//------------------------
// CONSTRUCTOR
//------------------------
public MyDriver(String aName)
{
name = aName;
}
//------------------------
// INTERFACE
//------------------------
public boolean setName(String aName)
{
boolean wasSet = false;
name = aName;
wasSet = true;
return wasSet;
}
public String getName()
{
return name;
}
/* Code from template association_GetOne */
public MySubordinate getMySubordinate()
{
return mySubordinate;
}
public boolean hasMySubordinate()
{
boolean has = mySubordinate != null;
return has;
}
/* Code from template association_SetOptionalOneToOne */
public boolean setMySubordinate(MySubordinate aNewMySubordinate)
{
boolean wasSet = false;
if (mySubordinate != null && !mySubordinate.equals(aNewMySubordinate) && equals(mySubordinate.getMyDriver()))
{
//Unable to setMySubordinate, as existing mySubordinate would become an orphan
return wasSet;
}
mySubordinate = aNewMySubordinate;
MyDriver anOldMyDriver = aNewMySubordinate != null ? aNewMySubordinate.getMyDriver() : null;
if (!this.equals(anOldMyDriver))
{
if (anOldMyDriver != null)
{
anOldMyDriver.mySubordinate = null;
}
if (mySubordinate != null)
{
mySubordinate.setMyDriver(this);
}
}
wasSet = true;
return wasSet;
}
public void delete()
{
MySubordinate existingMySubordinate = mySubordinate;
mySubordinate = null;
if (existingMySubordinate != null)
{
existingMySubordinate.delete();
}
}
public String toString()
{
return super.toString() + "["+
"name" + ":" + getName()+ "]" + System.getProperties().getProperty("line.separator") +
" " + "mySubordinate = "+(getMySubordinate()!=null?Integer.toHexString(System.identityHashCode(getMySubordinate())):"null");
}
}