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

Last change on this file since 8588 was 8510, checked in by Don-vip, 9 years ago

checkstyle: enable relevant whitespace checks and fix them

  • Property svn:eol-style set to native
File size: 2.1 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 /**
18 * Constructs a new {@code NodeData}.
19 */
20 public NodeData() {
21 // contents can be set later with setters
22 }
23
24 /**
25 * Constructs a new {@code NodeData}.
26 * @param data node data to copy
27 */
28 public NodeData(NodeData data) {
29 super(data);
30 setCoor(data.getCoor());
31 }
32
33 private boolean isLatLonKnown() {
34 return !Double.isNaN(lat) && !Double.isNaN(lon);
35 }
36
37 @Override
38 public LatLon getCoor() {
39 return isLatLonKnown() ? new LatLon(lat, lon) : null;
40 }
41
42 @Override
43 public final void setCoor(LatLon coor) {
44 if (coor == null) {
45 this.lat = Double.NaN;
46 this.lon = Double.NaN;
47 } else {
48 this.lat = coor.lat();
49 this.lon = coor.lon();
50 }
51 }
52
53 @Override
54 public EastNorth getEastNorth() {
55 // No internal caching of projected coordinates needed. In contrast to getEastNorth()
56 // on Node, this method is rarely used. Caching would be overkill.
57 return Projections.project(getCoor());
58 }
59
60 @Override
61 public void setEastNorth(EastNorth eastNorth) {
62 setCoor(Projections.inverseProject(eastNorth));
63 }
64
65 @Override
66 public NodeData makeCopy() {
67 return new NodeData(this);
68 }
69
70 @Override
71 public String toString() {
72 return super.toString() + " NODE " + getCoor();
73 }
74
75 @Override
76 public OsmPrimitiveType getType() {
77 return OsmPrimitiveType.NODE;
78 }
79
80 @Override
81 public void accept(PrimitiveVisitor visitor) {
82 visitor.visit(this);
83 }
84}
Note: See TracBrowser for help on using the repository browser.