package uk.co.patrickhaston.mars;

public class MarsLocatedObject extends MarsType 
{
  private LatLong location;
  
  public MarsLocatedObject(int id)
  {
    super(id);
    location = new LatLong();
  }
  
  public MarsLocatedObject(MarsLocatedObject obj)
  {
    super((MarsType) obj);
    if(obj != null)
    {
      location = obj.location;
    }
  }
  
  public MarsLocatedObject(String line)
  {
    super(line); // name is contained in col zero
    double latitude = readDouble(line, 1);
    double longitude = readDouble(line, 2);
    location = new LatLong(latitude, longitude);
  }
  
  public String toString()
  {
    String s = super.toString();
    s = s + " at (" + Double.toString(location.east) + "," + Double.toString(location.north) + ")";
    return s;
  }
  
  public String toFile()
  {
    String s = super.toFile();
    s = s + "," + Double.toString(location.east) + "," + Double.toString(location.north);
    return s;
  }
  
  public void setLocation(LatLong loc)
  {
    if(loc != null)
    {
      location.east = loc.east;
      location.north = loc.north;
    }
  }
  
  public LatLong getLocation()
  {
    return location;
  }
}
