001 // License: GPL. Copyright 2007 by Immanuel Scholz and others
002 package org.openstreetmap.josm.data.coor;
003
004 import java.awt.geom.Point2D;
005 import java.io.Serializable;
006
007 /**
008 * Base class of points of both coordinate systems.
009 *
010 * The variables are default package protected to allow routines in the
011 * data package to access them directly.
012 *
013 * As the class itself is package protected too, it is not visible
014 * outside of the data package. Routines there should only use LatLon or
015 * EastNorth.
016 *
017 * @author imi
018 */
019 abstract class Coordinate extends Point2D implements Serializable {
020
021 protected double x;
022 protected double y;
023
024 /**
025 * Construct the point with latitude / longitude values.
026 *
027 * @param x X coordinate of the point.
028 * @param y Y coordinate of the point.
029 */
030 Coordinate(double x, double y) {
031 this.x = x; this.y = y;
032 }
033
034 public double getX() {
035 return x;
036 }
037
038 public double getY() {
039 return y;
040 }
041
042 public void setLocation (double x, double y) {
043 this.x = x;
044 this.y = y;
045 }
046
047 @Override
048 public int hashCode() {
049 final int prime = 31;
050 int result = super.hashCode();
051 long temp;
052 temp = java.lang.Double.doubleToLongBits(x);
053 result = prime * result + (int) (temp ^ (temp >>> 32));
054 temp = java.lang.Double.doubleToLongBits(y);
055 result = prime * result + (int) (temp ^ (temp >>> 32));
056 return result;
057 }
058
059 @Override
060 public boolean equals(Object obj) {
061 if (this == obj)
062 return true;
063 if (!super.equals(obj))
064 return false;
065 if (getClass() != obj.getClass())
066 return false;
067 Coordinate other = (Coordinate) obj;
068 if (java.lang.Double.doubleToLongBits(x) != java.lang.Double.doubleToLongBits(other.x))
069 return false;
070 if (java.lang.Double.doubleToLongBits(y) != java.lang.Double.doubleToLongBits(other.y))
071 return false;
072 return true;
073 }
074 }