package seng302; /** * GPS Coordinate for the world map. * Created by esa46 on 15/03/17. */ public class GPSCoordinate { private double latitude; private double longitude; /** * Constructor Method * * @param latitude latitude the coordinate is located at. * @param longitude Longitude that the coordinate is located at. */ public GPSCoordinate(double latitude, double longitude) { this.latitude = latitude; this.longitude = longitude; } /** * Gets the Latitude that the Coordinate is at. * * @return Returns the latitude of the Coordinate. */ public double getLatitude() { return latitude; } /** * Gets the Longitude that the Coordinate is at. * * @return Returns the longitude of the Coordinate. */ public double getLongitude() { return longitude; } /** * To String method of the Coordinate in the form Latitude: $f, Longitude: $f. * * @return A String representation of the GPSCoordinate Class. */ public String toString() { return String.format("Latitude: %f, Longitude: %f", latitude, longitude); } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; GPSCoordinate that = (GPSCoordinate) o; if (Math.abs(this.latitude - latitude) > 1e-6) return false; return (Math.abs(this.longitude - longitude) < 1e-6); } @Override public int hashCode() { int result; long temp; temp = Double.doubleToLongBits(latitude); result = (int) (temp ^ (temp >>> 32)); temp = Double.doubleToLongBits(longitude); result = 31 * result + (int) (temp ^ (temp >>> 32)); return result; } }