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

Last change on this file since 12113 was 12017, checked in by Don-vip, 7 years ago

*Data: new constructors with a given id

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