/*This code was generated using the UMPLE modeling language!
 Date of generation: 2008/07/29 15:15:39*/
/*This class drives: Feature*/

package GIS.core;

import java.util.*;
import GIS.*;
import GIS.json.*;

public class Map {
  //Class datatypes
  private String scale;

  private String name;

  private String lattitude;

  private String longitude;

  private String height;

  private String width;

  //Class association variables
  private List<Feature> features;

  //Registry of our system.
  GISRegistry registry = GISRegistry.getInstance();

  //Constructor
  public Map(String aScale, String aName, String aLattitude, String aLongitude,
    String aHeight, String aWidth) {
    scale = aScale;
    name = aName;
    lattitude = aLattitude;
    longitude = aLongitude;
    height = aHeight;
    width = aWidth;
    features = new ArrayList<Feature>();
    registry.add(features);

  }

  public boolean setScale(String aScale) {
    scale = aScale;
    return true;
  }

  public boolean setName(String aName) {
    name = aName;
    return true;
  }

  public boolean setLattitude(String aLattitude) {
    lattitude = aLattitude;
    return true;
  }

  public boolean setLongitude(String aLongitude) {
    longitude = aLongitude;
    return true;
  }

  public boolean setHeight(String aHeight) {
    height = aHeight;
    return true;
  }

  public boolean setWidth(String aWidth) {
    width = aWidth;
    return true;
  }

  public String getScale() {
    return scale;
  }

  public String getName() {
    return name;
  }

  public String getLattitude() {
    return lattitude;
  }

  public String getLongitude() {
    return longitude;
  }

  public String getHeight() {
    return height;
  }

  public String getWidth() {
    return width;
  }

  public List<Feature> getFeatures() {
    return features;
  }

  public Feature addFeature(String aName, FeatureType aFeatureType) {
    Feature newFeature;
    newFeature = new Feature(aName, this, aFeatureType);
    if (!features.contains(newFeature)) {
      registry.add(newFeature);
      features.add(newFeature);
    }
    return newFeature;
  }

  public Feature addFeature(Feature aFeature) {
    if (!features.contains(aFeature))
      features.add(aFeature);
    return aFeature;
  }

  public void delete() {
    //Delete all many ends first.
    for (Feature aFeature : features) {
      aFeature.delete();
    }
    features.clear();

  }

  public void deleteFeature(Feature aFeature) {

    if (features.contains(aFeature)) {
      features.remove(aFeature);

      //registry.removeObj(registry.getKey(aFeature));
    } else
    //Throw an UmpleException .. to be implemented.
    {
    }
  }

  public boolean areManyEndsNull() {
    if (features.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("scale", getScale());
    obj.put("name", getName());
    obj.put("lattitude", getLattitude());
    obj.put("longitude", getLongitude());
    obj.put("height", getHeight());
    obj.put("width", getWidth());
    return obj;
  }

}