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

class Mentor
{

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

  //Mentor Attributes
  private $name;
  private $myStudentsPriority;

  //Mentor Associations
  private $myStudents;

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

  public function __construct($aName)
  {
    $this->name = $aName;
    $this->myStudentsPriority = 
      function($x, $y)
      {
        return $x->getId() -
               $y->getId();
      };
    $this->myStudents = array();
  }

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

  public function setName($aName)
  {
    $wasSet = false;
    $this->name = $aName;
    $wasSet = true;
    return $wasSet;
  }

  public function setMyStudentsPriority($aMyStudentsPriority)
  {
    $wasSet = false;
    $this->myStudentsPriority = $aMyStudentsPriority;
    $wasSet = true;
    return $wasSet;
  }

  public function getName()
  {
    return $this->name;
  }

  public function getMyStudentsPriority()
  {
    return $this->myStudentsPriority;
  }

  public function getMyStudent_index($index)
  {
    $aMyStudent = $this->myStudents[$index];
    return $aMyStudent;
  }

  public function getMyStudents()
  {
    $newMyStudents = $this->myStudents;
    return $newMyStudents;
  }

  public function numberOfMyStudents()
  {
    $number = count($this->myStudents);
    return $number;
  }

  public function hasMyStudents()
  {
    $has = $this->numberOfMyStudents() > 0;
    return $has;
  }

  public function indexOfMyStudent($aMyStudent)
  {
    $wasFound = false;
    $index = 0;
    foreach($this->myStudents as $myStudent)
    {
      if ($myStudent->equals($aMyStudent))
      {
        $wasFound = true;
        break;
      }
      $index += 1;
    }
    $index = $wasFound ? $index : -1;
    return $index;
  }

  public static function minimumNumberOfMyStudents()
  {
    return 0;
  }

  public function addMyStudent($aMyStudent)
  {
    $wasAdded = false;
    if ($this->indexOfMyStudent($aMyStudent) !== -1) { return false; }
    $this->myStudents[] = $aMyStudent;
    if ($aMyStudent->indexOfProf($this) != -1)
    {
      $wasAdded = true;
    }
    else
    {
      $wasAdded = $aMyStudent->addProf($this);
      if (!$wasAdded)
      {
        array_pop($this->myStudents);
      }
    }
      if(wasAdded)
          usort($this->myStudents, $this->myStudentsPriority);
      
    return $wasAdded;
  }

  public function removeMyStudent($aMyStudent)
  {
    $wasRemoved = false;
    if ($this->indexOfMyStudent($aMyStudent) == -1)
    {
      return $wasRemoved;
    }

    $oldIndex = $this->indexOfMyStudent($aMyStudent);
    unset($this->myStudents[$oldIndex]);
    if ($aMyStudent->indexOfProf($this) == -1)
    {
      $wasRemoved = true;
    }
    else
    {
      $wasRemoved = $aMyStudent->removeProf($this);
      if (!$wasRemoved)
      {
        $this->myStudents[$oldIndex] = $aMyStudent;
        ksort($this->myStudents);
      }
    }
    $this->myStudents = array_values($this->myStudents);
    return $wasRemoved;
  }

  public function equals($compareTo)
  {
    return $this == $compareTo;
  }

  public function delete()
  {
    $copyOfMyStudents = $this->myStudents;
    $this->myStudents = array();
    foreach ($copyOfMyStudents as $aMyStudent)
    {
      $aMyStudent->removeProf($this);
    }
  }

}
?>
