/*This code was generated using the UMPLE modeling language!
 Date of generation: 2008/07/29 14:36:59*/
/*This class drives: Suspect*/

package Police.core;

import java.util.*;
import Police.*;
import Police.json.*;

public class SuspectDescription {
  //Class datatypes
  private String height;

  private String weight;

  private String build;

  private String colour;

  private String hairCharacteristics;

  private String facialCharacteristics;

  private String otherDetails;

  //Class association variables
  private List<Suspect> matchess;

  private Witness describedBy;

  //Registry of our system.
  PoliceRegistry registry = PoliceRegistry.getInstance();

  //Constructor
  public SuspectDescription(String aHeight, String aWeight, String aBuild,
    String aColour, String aHairCharacteristics, String aFacialCharacteristics,
    String aOtherDetails, Witness aDescribedBy) {
    height = aHeight;
    weight = aWeight;
    build = aBuild;
    colour = aColour;
    hairCharacteristics = aHairCharacteristics;
    facialCharacteristics = aFacialCharacteristics;
    otherDetails = aOtherDetails;
    matchess = new ArrayList<Suspect>();
    registry.add(matchess);

    describedBy = aDescribedBy;
    describedBy.addSuspectDescription(this);

  }

  public boolean setHeight(String aHeight) {
    height = aHeight;
    return true;
  }

  public boolean setWeight(String aWeight) {
    weight = aWeight;
    return true;
  }

  public boolean setBuild(String aBuild) {
    build = aBuild;
    return true;
  }

  public boolean setColour(String aColour) {
    colour = aColour;
    return true;
  }

  public boolean setHairCharacteristics(String aHairCharacteristics) {
    hairCharacteristics = aHairCharacteristics;
    return true;
  }

  public boolean setFacialCharacteristics(String aFacialCharacteristics) {
    facialCharacteristics = aFacialCharacteristics;
    return true;
  }

  public boolean setOtherDetails(String aOtherDetails) {
    otherDetails = aOtherDetails;
    return true;
  }

  public String getHeight() {
    return height;
  }

  public String getWeight() {
    return weight;
  }

  public String getBuild() {
    return build;
  }

  public String getColour() {
    return colour;
  }

  public String getHairCharacteristics() {
    return hairCharacteristics;
  }

  public String getFacialCharacteristics() {
    return facialCharacteristics;
  }

  public String getOtherDetails() {
    return otherDetails;
  }

  public List<Suspect> getMatchess() {
    return matchess;
  }

  public Witness getDescribedBy() {
    return describedBy;
  }

  public Suspect addMatches(String aName, String aPhone, String aSex,
    String aAddress, String aAge, String aStatement) {
    Suspect newSuspect;
    newSuspect = new Suspect(aName, aPhone, aSex, aAddress, aAge, aStatement);
    if (!matchess.contains(newSuspect)) {
      registry.add(newSuspect);
      matchess.add(newSuspect);
    }
    return newSuspect;
  }

  public Suspect addMatches(Suspect aMatches) {
    if (!matchess.contains(aMatches))
      matchess.add(aMatches);
    return aMatches;
  }

  /* This class does not drive Witness and therefore sets the association unidirectionally.*/
  public void setDescribedBy(Witness aDescribedBy) {
    describedBy = aDescribedBy;
  }

  public void delete() {
    //Delete all many ends first.
    for (Suspect aSuspect : matchess) {
      aSuspect.delete();
    }
    matchess.clear();

    //Delete all 1 ends.
    describedBy.deleteSuspectDescription(this);
  }

  public void deleteMatches(Suspect aSuspect) {

    if (matchess.contains(aSuspect)) {
      matchess.remove(aSuspect);

      //registry.removeObj(registry.getKey(aSuspect));
    } else
    //Throw an UmpleException .. to be implemented.
    {
    }
  }

  public boolean areManyEndsNull() {
    if (matchess.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("height", getHeight());
    obj.put("weight", getWeight());
    obj.put("build", getBuild());
    obj.put("colour", getColour());
    obj.put("hairCharacteristics", getHairCharacteristics());
    obj.put("facialCharacteristics", getFacialCharacteristics());
    obj.put("otherDetails", getOtherDetails());
    return obj;
  }

}