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

package example;

public class Registration
{

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

  //Registration Attributes
  private String grade;

  //Registration Associations
  private Student student;
  private CourseSection courseSection;

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

  public Registration(String aGrade, Student aStudent, CourseSection aCourseSection)
  {
    grade = aGrade;
    boolean didAddStudent = setStudent(aStudent);
    if (!didAddStudent)
    {
      throw new RuntimeException("Unable to create registration due to student");
    }
    boolean didAddCourseSection = setCourseSection(aCourseSection);
    if (!didAddCourseSection)
    {
      throw new RuntimeException("Unable to create registration due to courseSection");
    }
  }

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

  public boolean setGrade(String aGrade)
  {
    boolean wasSet = false;
    grade = aGrade;
    wasSet = true;
    return wasSet;
  }

  public String getGrade()
  {
    return grade;
  }

  public Student getStudent()
  {
    return student;
  }

  public CourseSection getCourseSection()
  {
    return courseSection;
  }

  public boolean setStudent(Student aStudent)
  {
    boolean wasSet = false;
    if (aStudent == null)
    {
      return wasSet;
    }

    Student existingStudent = student;
    student = aStudent;
    if (existingStudent != null && !existingStudent.equals(aStudent))
    {
      existingStudent.removeRegistration(this);
    }
    student.addRegistration(this);
    wasSet = true;
    return wasSet;
  }

  public boolean setCourseSection(CourseSection aCourseSection)
  {
    boolean wasSet = false;
    if (aCourseSection == null)
    {
      return wasSet;
    }

    CourseSection existingCourseSection = courseSection;
    courseSection = aCourseSection;
    if (existingCourseSection != null && !existingCourseSection.equals(aCourseSection))
    {
      existingCourseSection.removeRegistration(this);
    }
    courseSection.addRegistration(this);
    wasSet = true;
    return wasSet;
  }

  public void delete()
  {
    Student placeholderStudent = student;
    this.student = null;
    placeholderStudent.removeRegistration(this);
    CourseSection placeholderCourseSection = courseSection;
    this.courseSection = null;
    placeholderCourseSection.removeRegistration(this);
  }


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