/*PLEASE DO NOT EDIT THIS CODE*/
/*This code was generated using the UMPLE 1.26.1-33ee578d5-3609 modeling language!*/

package example;

// line 6 "../1161.ump"
public class C
{

  //------------------------
  // MEMBER VARIABLES
  //------------------------

  //C Associations
  private D myD;
  private B b;

  //------------------------
  // CONSTRUCTOR
  //------------------------

  public C(D aMyD, B aB)
  {
    if (aMyD == null || aMyD.getC() != null)
    {
      throw new RuntimeException("Unable to create C due to aMyD. See https://manual.umple.org?RE002ViolationofAssociationMultiplicity.html");
    }
    myD = aMyD;
    boolean didAddB = setB(aB);
    if (!didAddB)
    {
      throw new RuntimeException("Unable to create myC due to b. See https://manual.umple.org?RE002ViolationofAssociationMultiplicity.html");
    }
  }

  public C(B aB)
  {
    myD = new D(this);
    boolean didAddB = setB(aB);
    if (!didAddB)
    {
      throw new RuntimeException("Unable to create myC due to b. See https://manual.umple.org?RE002ViolationofAssociationMultiplicity.html");
    }
  }

  //------------------------
  // INTERFACE
  //------------------------

  public D getMyD()
  {
    return myD;
  }

  public B getB()
  {
    return b;
  }

  public boolean setB(B aB)
  {
    boolean wasSet = false;
    if (aB == null)
    {
      return wasSet;
    }

    B existingB = b;
    b = aB;
    if (existingB != null && !existingB.equals(aB))
    {
      existingB.removeMyC(this);
    }
    b.addMyC(this);
    wasSet = true;
    return wasSet;
  }

  public void delete()
  {
    D existingMyD = myD;
    myD = null;
    if (existingMyD != null)
    {
      existingMyD.delete();
    }
    B placeholderB = b;
    this.b = null;
    if(placeholderB != null)
    {
      placeholderB.removeMyC(this);
    }
  }

}