/*This code was generated using the UMPLE modeling language!
 Date of generation: 2008/07/30 10:46:15*/
/*This class drives: RentableSpace*/

package hotel.core;

import java.util.*;
import hotel.*;
import hotel.json.*;

public class Suite {
  //Class datatypes

  //Class association variables
  private List<RentableSpace> rentableSpaces;

  //Registry of our system.
  HotelRegistry registry = HotelRegistry.getInstance();

  //Constructor
  public Suite() {
    rentableSpaces = new ArrayList<RentableSpace>();
    registry.add(rentableSpaces);

  }

  public List<RentableSpace> getRentableSpaces() {
    return rentableSpaces;
  }

  public RentableSpace addRentableSpace(String aCostPerDay, String aFloorArea,
    Hotel aHotel, Suite aSuite) {
    RentableSpace newRentableSpace;
    newRentableSpace = new RentableSpace(aCostPerDay, aFloorArea, aHotel, this);
    if (!rentableSpaces.contains(newRentableSpace)) {
      registry.add(newRentableSpace);
      rentableSpaces.add(newRentableSpace);
    }
    return newRentableSpace;
  }

  public RentableSpace addRentableSpace(RentableSpace aRentableSpace) {
    if (!rentableSpaces.contains(aRentableSpace))
      rentableSpaces.add(aRentableSpace);
    return aRentableSpace;
  }

  public void delete() {
    //Delete all many ends first.
    for (RentableSpace aRentableSpace : rentableSpaces) {
      aRentableSpace.delete();
    }
    rentableSpaces.clear();

  }

  public void deleteRentableSpace(RentableSpace aRentableSpace) {

    if (rentableSpaces.contains(aRentableSpace)) {
      rentableSpaces.remove(aRentableSpace);

      //registry.removeObj(registry.getKey(aRentableSpace));
    } else
    //Throw an UmpleException .. to be implemented.
    {
    }
  }

  public boolean areManyEndsNull() {
    if (rentableSpaces.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));
    return obj;
  }

}