source: josm/trunk/src/org/openstreetmap/josm/data/osm/NodeData.java@ 7392

Last change on this file since 7392 was 6890, checked in by Don-vip, 10 years ago

fix some Sonar issues (Constructor Calls Overridable Method)

  • Property svn:eol-style set to native
File size: 2.0 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data.osm;
3
4import org.openstreetmap.josm.data.coor.EastNorth;
5import org.openstreetmap.josm.data.coor.LatLon;
6import org.openstreetmap.josm.data.osm.visitor.PrimitiveVisitor;
7import org.openstreetmap.josm.data.projection.Projections;
8
9public class NodeData extends PrimitiveData implements INode {
10
11 /*
12 * we "inline" lat/lon coordinates instead of using a LatLon => reduces memory footprint
13 */
14 private double lat = Double.NaN;
15 private double lon = Double.NaN;
16
17 public NodeData() {}
18
19 public NodeData(NodeData data) {
20 super(data);
21 setCoor(data.getCoor());
22 }
23
24 private boolean isLatLonKnown() {
25 return !Double.isNaN(lat) && !Double.isNaN(lon);
26 }
27
28 @Override
29 public LatLon getCoor() {
30 return isLatLonKnown() ? new LatLon(lat,lon) : null;
31 }
32
33 @Override
34 public final void setCoor(LatLon coor) {
35 if (coor == null) {
36 this.lat = Double.NaN;
37 this.lon = Double.NaN;
38 } else {
39 this.lat = coor.lat();
40 this.lon = coor.lon();
41 }
42 }
43
44 @Override
45 public EastNorth getEastNorth() {
46 /*
47 * No internal caching of projected coordinates needed. In contrast to getEastNorth()
48 * on Node, this method is rarely used. Caching would be overkill.
49 */
50 return Projections.project(getCoor());
51 }
52
53 @Override
54 public void setEastNorth(EastNorth eastNorth) {
55 LatLon ll = Projections.inverseProject(eastNorth);
56 setCoor(ll);
57 }
58
59 @Override
60 public NodeData makeCopy() {
61 return new NodeData(this);
62 }
63
64 @Override
65 public String toString() {
66 return super.toString() + " NODE " + getCoor();
67 }
68
69 @Override
70 public OsmPrimitiveType getType() {
71 return OsmPrimitiveType.NODE;
72 }
73
74 @Override
75 public void accept(PrimitiveVisitor visitor) {
76 visitor.visit(this);
77 }
78
79}
Note: See TracBrowser for help on using the repository browser.