/*This code was generated using the UMPLE modeling language!
 Date of generation: 2008/07/30 10:05:36*/
/*This class drives: RobotAllocation*/

package MFP.core.red;

import java.util.*;
import java.sql.Time;
import MFP.*;
import MFP.core.green.*;
import MFP.core.black.*;
import MFP.core.blue.*;
import MFP.json.*;

public class Robot {
  //Class datatypes
  private String number;

  //Class association variables
  private List<RobotAllocation> robotAllocations;

  //Registry of our system.
  MFPRegistry registry = MFPRegistry.getInstance();

  //Constructor
  public Robot(String aNumber) {
    number = aNumber;
    robotAllocations = new ArrayList<RobotAllocation>();
    registry.add(robotAllocations);

  }

  public boolean setNumber(String aNumber) {
    number = aNumber;
    return true;
  }

  public String getNumber() {
    return number;
  }

  public List<RobotAllocation> getRobotAllocations() {
    return robotAllocations;
  }

  public RobotAllocation addRobotAllocation(String aTimePeriod,
    AssemblyStep aAssemblyStep, Robot aRobot) {
    RobotAllocation newRobotAllocation;
    newRobotAllocation = new RobotAllocation(aTimePeriod, aAssemblyStep, this);
    if (!robotAllocations.contains(newRobotAllocation)) {
      registry.add(newRobotAllocation);
      robotAllocations.add(newRobotAllocation);
    }
    return newRobotAllocation;
  }

  public RobotAllocation addRobotAllocation(RobotAllocation aRobotAllocation) {
    if (!robotAllocations.contains(aRobotAllocation))
      robotAllocations.add(aRobotAllocation);
    return aRobotAllocation;
  }

  public void delete() {
    //Delete all many ends first.
    for (RobotAllocation aRobotAllocation : robotAllocations) {
      aRobotAllocation.delete();
    }
    robotAllocations.clear();

  }

  public void deleteRobotAllocation(RobotAllocation aRobotAllocation) {

    if (robotAllocations.contains(aRobotAllocation)) {
      robotAllocations.remove(aRobotAllocation);

      //registry.removeObj(registry.getKey(aRobotAllocation));
    } else
    //Throw an UmpleException .. to be implemented.
    {
    }
  }

  public boolean areManyEndsNull() {
    if (robotAllocations.size() == 0) {
      return true;
    } else
      return false;
  }

  /***********************************
   * Returns the attribute list along with the  
   * class ID in JSON format.
   ***********************************/
  public JSONObject getAttributes() throws JSONException {
    JSONObject obj = new JSONObject();
    obj.put("CLASS_ID", registry.getKey(this));
    obj.put("number", getNumber());
    return obj;
  }

}