/*PLEASE DO NOT EDIT THIS CODE*/
/*This code was generated using the UMPLE 1.17.0.2716 modeling language!*/

package example.one;
import example.two.*;

public class Mentor
{

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

  //Mentor Attributes
  private String name;

  //Mentor Associations
  private Student student;

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

  public Mentor(String aName)
  {
    name = aName;
  }

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

  public boolean setName(String aName)
  {
    boolean wasSet = false;
    name = aName;
    wasSet = true;
    return wasSet;
  }

  public String getName()
  {
    return name;
  }

  public Student getStudent()
  {
    return student;
  }

  public boolean hasStudent()
  {
    boolean has = student != null;
    return has;
  }

  public boolean setStudent(Student aStudent)
  {
    //
    // This source of this source generation is association_SetOptionalOneToMandatoryMany.jet
    // This set file assumes the generation of a maximumNumberOfXXX method does not exist because 
    // it's not required (No upper bound)
    //   
    boolean wasSet = false;
    Student existingStudent = student;

    if (existingStudent == null)
    {
      if (aStudent != null)
      {
        if (aStudent.addMentor(this))
        {
          existingStudent = aStudent;
          wasSet = true;
        }
      }
    } 
    else if (existingStudent != null)
    {
      if (aStudent == null)
      {
        if (existingStudent.minimumNumberOfMentors() < existingStudent.numberOfMentors())
        {
          existingStudent.removeMentor(this);
          existingStudent = aStudent;  // aStudent == null
          wasSet = true;
        }
      } 
      else
      {
        if (existingStudent.minimumNumberOfMentors() < existingStudent.numberOfMentors())
        {
          existingStudent.removeMentor(this);
          aStudent.addMentor(this);
          existingStudent = aStudent;
          wasSet = true;
        }
      }
    }
    if (wasSet)
    {
      student = existingStudent;
    }
    return wasSet;
  }
  
  public void delete()
  {
    if (student != null)
    {
      if (student.numberOfMentors() <= 1)
      {
        student.delete();
      }
      else
      {
        Student placeholderStudent = student;
        this.student = null;
        placeholderStudent.removeMentor(this);
      }
    }
  }


  public String toString()
  {
    return super.toString() + "["+
            "name" + ":" + getName()+ "]" + System.getProperties().getProperty("line.separator") +
            "  " + "student = "+(getStudent()!=null?Integer.toHexString(System.identityHashCode(getStudent())):"null");
  }
}
