source: josm/trunk/src/org/openstreetmap/josm/data/coor/CachedLatLon.java@ 12093

Last change on this file since 12093 was 10334, checked in by Don-vip, 8 years ago

fix equals methods for Coordinate classes

  • Property svn:eol-style set to native
File size: 2.2 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data.coor;
3
4import java.util.Objects;
5
6import org.openstreetmap.josm.Main;
7import org.openstreetmap.josm.data.projection.Projection;
8
9/**
10 * LatLon class that maintains a cache of projected EastNorth coordinates.
11 *
12 * This class is convenient to use, but has relatively high memory costs.
13 * It keeps a pointer to the last known projection in order to detect projection changes.
14 *
15 * Node and WayPoint have another, optimized, cache for projected coordinates.
16 */
17public class CachedLatLon extends LatLon {
18
19 private static final long serialVersionUID = 1L;
20
21 private EastNorth eastNorth;
22 private transient Projection proj;
23
24 /**
25 * Constructs a new {@code CachedLatLon}.
26 * @param lat latitude
27 * @param lon longitude
28 */
29 public CachedLatLon(double lat, double lon) {
30 super(lat, lon);
31 }
32
33 /**
34 * Constructs a new {@code CachedLatLon}.
35 * @param coor lat/lon
36 */
37 public CachedLatLon(LatLon coor) {
38 super(coor.lat(), coor.lon());
39 proj = null;
40 }
41
42 /**
43 * Constructs a new {@code CachedLatLon}.
44 * @param eastNorth easting/northing
45 */
46 public CachedLatLon(EastNorth eastNorth) {
47 super(Main.getProjection().eastNorth2latlon(eastNorth));
48 proj = Main.getProjection();
49 this.eastNorth = eastNorth;
50 }
51
52 /**
53 * Replies the projected east/north coordinates.
54 *
55 * @return the internally cached east/north coordinates. null, if the globally defined projection is null
56 */
57 public final EastNorth getEastNorth() {
58 if (!Objects.equals(proj, Main.getProjection())) {
59 proj = Main.getProjection();
60 eastNorth = proj.latlon2eastNorth(this);
61 }
62 return eastNorth;
63 }
64
65 @Override
66 public int hashCode() {
67 return Objects.hash(x, y, eastNorth);
68 }
69
70 @Override
71 public boolean equals(Object obj) {
72 if (!super.equals(obj))
73 return false;
74 CachedLatLon other = (CachedLatLon) obj;
75 return Objects.equals(eastNorth, other.eastNorth);
76 }
77
78 @Override
79 public String toString() {
80 return "CachedLatLon[lat="+lat()+",lon="+lon()+']';
81 }
82}
Note: See TracBrowser for help on using the repository browser.