source: josm/trunk/src/org/openstreetmap/josm/data/osm/Node.java@ 2748

Last change on this file since 2748 was 2748, checked in by Gubaer, 14 years ago

new: JOSM now supports OAuth

See also online help for server preferences and new OAuth Authorisation Wizard

  • Property svn:eol-style set to native
File size: 5.3 KB
Line 
1// License: GPL. Copyright 2007 by Immanuel Scholz and others
2package org.openstreetmap.josm.data.osm;
3
4import org.openstreetmap.josm.data.coor.CachedLatLon;
5import org.openstreetmap.josm.data.coor.EastNorth;
6import org.openstreetmap.josm.data.coor.LatLon;
7import org.openstreetmap.josm.data.osm.visitor.Visitor;
8
9/**
10 * One node data, consisting of one world coordinate waypoint.
11 *
12 * @author imi
13 */
14public final class Node extends OsmPrimitive {
15
16 private CachedLatLon coor;
17
18 public final void setCoor(LatLon coor) {
19 if(coor != null){
20 if(this.coor == null) {
21 this.coor = new CachedLatLon(coor);
22 } else {
23 this.coor.setCoor(coor);
24 }
25 if (getDataSet() != null) {
26 getDataSet().fireNodeMoved(this);
27 }
28 }
29 }
30
31 public final LatLon getCoor() {
32 return coor;
33 }
34
35 public final void setEastNorth(EastNorth eastNorth) {
36 if(eastNorth != null)
37 {
38 if(coor != null) {
39 coor.setEastNorth(eastNorth);
40 } else {
41 coor = new CachedLatLon(eastNorth);
42 }
43 if (getDataSet() != null) {
44 getDataSet().fireNodeMoved(this);
45 }
46 }
47 }
48
49 public final EastNorth getEastNorth() {
50 return coor != null ? coor.getEastNorth() : null;
51 }
52
53 protected Node(long id, boolean allowNegative) {
54 super(id, allowNegative);
55 }
56
57 /**
58 * Create a new local node.
59 *
60 */
61 public Node() {
62 this(0, false);
63 }
64
65 /**
66 * Create an incomplete Node object
67 */
68 public Node(long id) {
69 super(id, false);
70 }
71
72 /**
73 * Create new complete node
74 * @param id
75 * @param version
76 */
77 public Node(long id, int version) {
78 super(id, false);
79 setOsmId(id, version);
80 }
81
82 /**
83 *
84 * @param clone
85 * @param clearId If true, set version to 0 and id to new unique value
86 */
87 public Node(Node clone, boolean clearId) {
88 super(clone.getUniqueId(), true /* allow negative IDs */);
89 cloneFrom(clone);
90 if (clearId) {
91 clearOsmId();
92 }
93 }
94
95 /**
96 * Create an identical clone of the argument (including the id)
97 */
98 public Node(Node clone) {
99 this(clone, false);
100 }
101
102 public Node(LatLon latlon) {
103 super(0, false);
104 setCoor(latlon);
105 }
106
107 public Node(EastNorth eastNorth) {
108 super(0, false);
109 setEastNorth(eastNorth);
110 }
111
112 @Override public void visit(Visitor visitor) {
113 visitor.visit(this);
114 }
115
116 @Override public void cloneFrom(OsmPrimitive osm) {
117 super.cloneFrom(osm);
118 setCoor(((Node)osm).coor);
119 }
120
121 /**
122 * Merges the technical and semantical attributes from <code>other</code> onto this.
123 *
124 * Both this and other must be new, or both must be assigned an OSM ID. If both this and <code>other</code>
125 * have an assigend OSM id, the IDs have to be the same.
126 *
127 * @param other the other primitive. Must not be null.
128 * @throws IllegalArgumentException thrown if other is null.
129 * @throws DataIntegrityProblemException thrown if either this is new and other is not, or other is new and this is not
130 * @throws DataIntegrityProblemException thrown if other is new and other.getId() != this.getId()
131 */
132 @Override
133 public void mergeFrom(OsmPrimitive other) {
134 super.mergeFrom(other);
135 if (!other.isIncomplete()) {
136 setCoor(new LatLon(((Node)other).coor));
137 }
138 }
139
140 @Override public void load(PrimitiveData data) {
141 super.load(data);
142 setCoor(((NodeData)data).getCoor());
143 }
144
145 @Override public NodeData save() {
146 NodeData data = new NodeData();
147 saveCommonAttributes(data);
148 if (!isIncomplete()) {
149 data.setCoor(getCoor());
150 }
151 return data;
152 }
153
154 @Override public String toString() {
155 String coorDesc = coor == null?"":"lat="+coor.lat()+",lon="+coor.lon();
156 return "{Node id=" + getUniqueId() + " version=" + getVersion() + " " + getFlagsAsString() + " " + coorDesc+"}";
157 }
158
159 @Override
160 public boolean hasEqualSemanticAttributes(OsmPrimitive other) {
161 if (other == null || ! (other instanceof Node) )
162 return false;
163 if (! super.hasEqualSemanticAttributes(other))
164 return false;
165 Node n = (Node)other;
166 if (coor == null && n.coor == null)
167 return true;
168 else if (coor != null && n.coor != null)
169 return coor.equalsEpsilon(n.coor);
170 else
171 return false;
172 }
173
174 public int compareTo(OsmPrimitive o) {
175 return o instanceof Node ? Long.valueOf(getUniqueId()).compareTo(o.getUniqueId()) : 1;
176 }
177
178 @Override
179 public String getDisplayName(NameFormatter formatter) {
180 return formatter.format(this);
181 }
182
183 public OsmPrimitiveType getType() {
184 return OsmPrimitiveType.NODE;
185 }
186
187 @Override
188 public BBox getBBox() {
189 if (coor == null)
190 return new BBox(0, 0, 0, 0);
191 else
192 return new BBox(coor, coor);
193 }
194
195 @Override
196 public void updatePosition() {
197 // Do nothing for now, but in future replace CachedLatLon with simple doubles and update precalculated EastNorth value here
198 }
199}
Note: See TracBrowser for help on using the repository browser.