
// Copyright (c) 2004 
package uk.co.patrickhaston.mars;


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;

/**
 * A Class class.
 * <P>
 * @author Patrick Haston
 */
public class MarsFeature extends MarsData 
{
  public String featureName;
  public int featureType;
  public LatLong location;
  public double radius;
  public String description;

  /**
   * Constructor
   */
  public MarsFeature(int id) 
  {
    super(id);
  }

  public MarsFeature(MarsFeature f)
  {
    super(f);
    featureName = f.featureName;
    featureType = f.featureType;
    location = new LatLong(f.location);
    radius = f.radius;
    description = f.description;
  }
  
  public MarsFeature(String line)
  {
    super(line);
    featureType = readInteger(line, 0);
    featureName = new String(readString(line, 1));
    double latitude = readDouble(line, 2);
    double longitude = readDouble(line, 3);
    location = new LatLong(latitude, longitude);
    radius = readDouble(line, 4);
    description = readString(line, 5);
  }

  public void writeData(BufferedWriter output)
  {
   try
   {
    String s;
    Float f;
    Integer i;

    // save featureName
    s = "Name=" + featureName;
    output.write(s);
    output.newLine();

    // save Type
    i = new Integer(featureType);
    s = "Type=" + i.toString();
    output.write(s);
    output.newLine();

    // save Latitude
    f = new Float(location.north);
    s = "Latitude=" + f.toString();
    output.write(s);
    output.newLine();

    // save Longitude
    f = new Float(location.east);
    s = "Longitude=" + f.toString();
    output.write(s);
    output.newLine();

    // save radius
    f = new Float(radius);
    s = "Radius=" + f.toString();
    output.write(s);
    output.newLine();

    // save description
    s = "Description=" + description;
    output.write(s);
    output.newLine();
   }
   catch (IOException e)
   {
   }
  }

  public void readValue(String key, String value)
  {
    if (key == "Name") featureName = value;
    if (key == "Type")
    {
      Integer val = new Integer(value);
      featureType = val.intValue();
    }
    if (key == "Latitude")
    {
      Float val = new Float(value);
      location.north = val.floatValue();
    }
    if (key == "Longitude")
    {
      Float val = new Float(value);
      location.east = val.floatValue();
    }
    if (key == "Radius")
    {
      Float val = new Float(value);
      radius = val.floatValue();
    }
    if (key == "Description") description = value;
  }

}

 
