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

package example;
import java.util.*;

// line 3 "../ImmutableUnidirectionalNTest.ump"
public class Student
{

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

  //Student Attributes
  private String number;

  //Student Associations
  private List<Mentor> mentors;

  //Helper Variables
  private boolean canSetMentors;

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

  public Student(String aNumber, Mentor... allMentors)
  {
    number = aNumber;
    canSetMentors = true;
    mentors = new ArrayList<Mentor>();
    boolean didAddMentors = setMentors(allMentors);
    if (!didAddMentors)
    {
      throw new RuntimeException("Unable to create Student, must have 3 mentors. See https://manual.umple.org?RE002ViolationofAssociationMultiplicity.html");
    }
  }

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

  public String getNumber()
  {
    return number;
  }
  /* Code from template association_GetMany */
  public Mentor getMentor(int index)
  {
    Mentor aMentor = mentors.get(index);
    return aMentor;
  }

  public List<Mentor> getMentors()
  {
    List<Mentor> newMentors = Collections.unmodifiableList(mentors);
    return newMentors;
  }

  public int numberOfMentors()
  {
    int number = mentors.size();
    return number;
  }

  public boolean hasMentors()
  {
    boolean has = mentors.size() > 0;
    return has;
  }

  public int indexOfMentor(Mentor aMentor)
  {
    int index = mentors.indexOf(aMentor);
    return index;
  }
  /* Code from template association_RequiredNumberOfMethod */
  public static int requiredNumberOfMentors()
  {
    return 3;
  }
  /* Code from template association_MinimumNumberOfMethod */
  public static int minimumNumberOfMentors()
  {
    return 3;
  }
  /* Code from template association_MaximumNumberOfMethod */
  public static int maximumNumberOfMentors()
  {
    return 3;
  }
  /* Code from template association_SetUnidirectionalN */
  private boolean setMentors(Mentor... newMentors)
  {
    boolean wasSet = false;
    if (!canSetMentors) { return false; }
    canSetMentors = false;
    ArrayList<Mentor> verifiedMentors = new ArrayList<Mentor>();
    for (Mentor aMentor : newMentors)
    {
      if (verifiedMentors.contains(aMentor))
      {
        continue;
      }
      verifiedMentors.add(aMentor);
    }

    if (verifiedMentors.size() != newMentors.length || verifiedMentors.size() != requiredNumberOfMentors())
    {
      return wasSet;
    }

    mentors.clear();
    mentors.addAll(verifiedMentors);
    wasSet = true;
    return wasSet;
  }

  public void delete()
  {}


  public String toString()
  {
    return super.toString() + "["+
            "number" + ":" + getNumber()+ "]";
  }
}
/*PLEASE DO NOT EDIT THIS CODE*/
/*This code was generated using the UMPLE 1.35.0.7523.c616a4dce modeling language!*/

package example;

// line 9 "../ImmutableUnidirectionalNTest.ump"
public class Mentor
{

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

  //Mentor Attributes
  private String name;

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

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

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

  public String getName()
  {
    return name;
  }

  public void delete()
  {}


  public String toString()
  {
    return super.toString() + "["+
            "name" + ":" + getName()+ "]";
  }
}