1 | // License: GPL. For details, see Readme.txt file.
|
---|
2 | package org.openstreetmap.gui.jmapviewer;
|
---|
3 |
|
---|
4 | import java.awt.geom.Point2D;
|
---|
5 | import java.io.IOException;
|
---|
6 | import java.io.ObjectInputStream;
|
---|
7 | import java.io.ObjectOutputStream;
|
---|
8 | import java.io.Serializable;
|
---|
9 | import java.util.Objects;
|
---|
10 |
|
---|
11 | import org.openstreetmap.gui.jmapviewer.interfaces.ICoordinate;
|
---|
12 |
|
---|
13 | /**
|
---|
14 | * This class encapsulates a Point2D.Double and provide access
|
---|
15 | * via <tt>lat</tt> and <tt>lon</tt>.
|
---|
16 | *
|
---|
17 | * @author Jan Peter Stotz
|
---|
18 | *
|
---|
19 | */
|
---|
20 | public class Coordinate implements Serializable, ICoordinate {
|
---|
21 | private transient Point2D.Double data;
|
---|
22 |
|
---|
23 | public Coordinate(double lat, double lon) {
|
---|
24 | data = new Point2D.Double(lon, lat);
|
---|
25 | }
|
---|
26 |
|
---|
27 | public double getLat() {
|
---|
28 | return data.y;
|
---|
29 | }
|
---|
30 |
|
---|
31 | public void setLat(double lat) {
|
---|
32 | data.y = lat;
|
---|
33 | }
|
---|
34 |
|
---|
35 | public double getLon() {
|
---|
36 | return data.x;
|
---|
37 | }
|
---|
38 |
|
---|
39 | public void setLon(double lon) {
|
---|
40 | data.x = lon;
|
---|
41 | }
|
---|
42 |
|
---|
43 | private void writeObject(ObjectOutputStream out) throws IOException {
|
---|
44 | out.writeObject(data.x);
|
---|
45 | out.writeObject(data.y);
|
---|
46 | }
|
---|
47 |
|
---|
48 | private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
|
---|
49 | data = new Point2D.Double();
|
---|
50 | data.x = (Double) in.readObject();
|
---|
51 | data.y = (Double) in.readObject();
|
---|
52 | }
|
---|
53 |
|
---|
54 | public String toString() {
|
---|
55 | return "Coordinate[" + data.y + ", " + data.x + "]";
|
---|
56 | }
|
---|
57 |
|
---|
58 | @Override
|
---|
59 | public int hashCode() {
|
---|
60 | int hash = 3;
|
---|
61 | hash = 61 * hash + Objects.hashCode(this.data);
|
---|
62 | return hash;
|
---|
63 | }
|
---|
64 |
|
---|
65 | @Override
|
---|
66 | public boolean equals(Object obj) {
|
---|
67 | if (obj == null) {
|
---|
68 | return false;
|
---|
69 | }
|
---|
70 | if (getClass() != obj.getClass()) {
|
---|
71 | return false;
|
---|
72 | }
|
---|
73 | final Coordinate other = (Coordinate) obj;
|
---|
74 | if (!Objects.equals(this.data, other.data)) {
|
---|
75 | return false;
|
---|
76 | }
|
---|
77 | return true;
|
---|
78 | }
|
---|
79 | }
|
---|