
package org.mbari.vdm.expd;

import java.util.Comparator;

import org.mbari.vdm.VdmLine;

import ucar.unidata.geoloc.LatLonPoint;
import ucar.unidata.geoloc.LatLonPointImpl;

public final class ExpdLine implements VdmLine {

    private double lat;
    private double lon;
    private float depth;
    long epochSecs;
    public static String HEADER = "Latitude, Longitude, Depth, EpochSecs";

    public ExpdLine(double lat, double lon, float depth, long secs) {
        this.lat = lat;
        this.lon = lon;
        this.depth = depth;
        this.epochSecs = secs;
    }

    public ExpdLine(String[] parts) {
        this(Double.parseDouble(parts[0]), Double.parseDouble(parts[1]), Float
            .parseFloat(parts[2]), Long.parseLong(parts[3]));
    }

    public String getHeader() {
        return HEADER;
    }

    public String toString() {
        return toCsvString();
    }

    public String toCsvString() {
        return this.lat + ", " + this.lon + ", " + this.depth + ", " + this.epochSecs;
    }

    public LatLonPoint getPoint() {
        return new LatLonPointImpl(lat, lon);
    }
    
    public double getLat(){
        return lat;
    }
    
    public double getLon(){
        return lon;
    }
    public float getDepth(){
        return depth;
    }

    final static Comparator getComparator() {
        return new Comparator() {

            public int compare(Object o1, Object o2) {
                VdmLine o1cast = (VdmLine) o1;
                VdmLine o2cast = (VdmLine) o2;
                if (o1cast.getLat() != o2cast.getLat()) {
                    if (o1cast.getLat() > o2cast.getLat()) {
                        return -1;
                    }
                    return 1;
                } else if (o1cast.getLon() != o2cast.getLon()) {
                    if (o1cast.getLon() > o2cast.getLon() ) {
                        return 1;
                    }
                    return -1;
                }
                return 0;
            }
        };
    }

    final static Comparator getLonComparator() {
        return new Comparator() {

            public int compare(Object o1, Object o2) {
                VdmLine o1cast = (VdmLine) o1;
                VdmLine o2cast = (VdmLine) o2;
                if (o1cast.getLon() != o2cast.getLon()) {
                    if (o1cast.getLon() > o2cast.getLon()) {
                        return 1;
                    }
                    return -1;
                } 
                return 0;
            }
        };
    }
}