/*This code was generated using the UMPLE modeling language!
 Date of generation: 2008/07/29 14:36:59*/
/*This class drives: ChargeOccurrence*/

package Police.core;

import java.util.*;
import java.sql.Time;
import java.sql.Date;
import Police.*;
import Police.json.*;

public class Suspect extends Person {
  //Class datatypes
  private String statement;

  //Class association variables
  private List<CrimeOccurrence> crimeOccurrences;

  private List<ChargeOccurrence> chargeOccurrences;

  private List<SuspectDescription> suspectDescriptions;

  //Registry of our system.
  PoliceRegistry registry = PoliceRegistry.getInstance();

  //Constructor
  public Suspect(String aName, String aPhone, String aSex, String aAddress,
    String aAge, String aStatement) {
    super(aName, aPhone, aSex, aAddress, aAge);
    statement = aStatement;
    crimeOccurrences = new ArrayList<CrimeOccurrence>();
    registry.add(crimeOccurrences);

    chargeOccurrences = new ArrayList<ChargeOccurrence>();
    registry.add(chargeOccurrences);

    suspectDescriptions = new ArrayList<SuspectDescription>();
    registry.add(suspectDescriptions);

  }

  public boolean setStatement(String aStatement) {
    statement = aStatement;
    return true;
  }

  public String getStatement() {
    return statement;
  }

  public List<CrimeOccurrence> getCrimeOccurrences() {
    return crimeOccurrences;
  }

  public List<ChargeOccurrence> getChargeOccurrences() {
    return chargeOccurrences;
  }

  public List<SuspectDescription> getSuspectDescriptions() {
    return suspectDescriptions;
  }

  public CrimeOccurrence addCrimeOccurrence(String aLocation, String aDate,
    String aTime, String aDescription) {
    CrimeOccurrence newCrimeOccurrence;
    newCrimeOccurrence =
      new CrimeOccurrence(aLocation, aDate, aTime, aDescription);
    if (!crimeOccurrences.contains(newCrimeOccurrence)) {
      registry.add(newCrimeOccurrence);
      crimeOccurrences.add(newCrimeOccurrence);
    }
    return newCrimeOccurrence;
  }

  public CrimeOccurrence addCrimeOccurrence(CrimeOccurrence aCrimeOccurrence) {
    if (!crimeOccurrences.contains(aCrimeOccurrence))
      crimeOccurrences.add(aCrimeOccurrence);
    return aCrimeOccurrence;
  }

  public ChargeOccurrence addChargeOccurrence(String aDateEntered,
    String aDisposition, String aPenalty, OffenseType aOffenseType) {
    ChargeOccurrence newChargeOccurrence;
    newChargeOccurrence =
      new ChargeOccurrence(aDateEntered, aDisposition, aPenalty, aOffenseType,
        this);
    if (!chargeOccurrences.contains(newChargeOccurrence)) {
      registry.add(newChargeOccurrence);
      chargeOccurrences.add(newChargeOccurrence);
    }
    return newChargeOccurrence;
  }

  public ChargeOccurrence addChargeOccurrence(ChargeOccurrence aChargeOccurrence) {
    if (!chargeOccurrences.contains(aChargeOccurrence))
      chargeOccurrences.add(aChargeOccurrence);
    return aChargeOccurrence;
  }

  public SuspectDescription addSuspectDescription(String aHeight,
    String aWeight, String aBuild, String aColour, String aHairCharacteristics,
    String aFacialCharacteristics, String aOtherDetails, Witness aDescribedBy) {
    SuspectDescription newSuspectDescription;
    newSuspectDescription =
      new SuspectDescription(aHeight, aWeight, aBuild, aColour,
        aHairCharacteristics, aFacialCharacteristics, aOtherDetails,
        aDescribedBy);
    if (!suspectDescriptions.contains(newSuspectDescription)) {
      registry.add(newSuspectDescription);
      suspectDescriptions.add(newSuspectDescription);
    }
    return newSuspectDescription;
  }

  public SuspectDescription addSuspectDescription(
    SuspectDescription aSuspectDescription) {
    if (!suspectDescriptions.contains(aSuspectDescription))
      suspectDescriptions.add(aSuspectDescription);
    return aSuspectDescription;
  }

  public void delete() {
    //Delete all many ends first.
    for (ChargeOccurrence aChargeOccurrence : chargeOccurrences) {
      aChargeOccurrence.delete();
    }
    chargeOccurrences.clear();

  }

  public void deleteCrimeOccurrence(CrimeOccurrence aCrimeOccurrence) {

    if (crimeOccurrences.contains(aCrimeOccurrence)) {
      crimeOccurrences.remove(aCrimeOccurrence);

      //registry.removeObj(registry.getKey(aCrimeOccurrence));
    } else
    //Throw an UmpleException .. to be implemented.
    {
    }
  }

  public void deleteChargeOccurrence(ChargeOccurrence aChargeOccurrence) {

    if (chargeOccurrences.contains(aChargeOccurrence)) {
      chargeOccurrences.remove(aChargeOccurrence);

      //registry.removeObj(registry.getKey(aChargeOccurrence));
    } else
    //Throw an UmpleException .. to be implemented.
    {
    }
  }

  public void deleteSuspectDescription(SuspectDescription aSuspectDescription) {

    if (suspectDescriptions.contains(aSuspectDescription)) {
      suspectDescriptions.remove(aSuspectDescription);

      //registry.removeObj(registry.getKey(aSuspectDescription));
    } else
    //Throw an UmpleException .. to be implemented.
    {
    }
  }

  public boolean areManyEndsNull() {
    if (chargeOccurrences.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("statement", getStatement());
    return obj;
  }

}