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

Last change on this file since 2410 was 2410, checked in by jttt, 14 years ago

Add clearId parameter to primitives copy constructor, replace some clearOsmId calls, throw exception if id is set after primitive was added to the dataset

  • Property svn:eol-style set to native
File size: 3.7 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 }
26 }
27
28 public final LatLon getCoor() {
29 return coor;
30 }
31
32 public final void setEastNorth(EastNorth eastNorth) {
33 if(eastNorth != null)
34 {
35 if(coor != null) {
36 coor.setEastNorth(eastNorth);
37 } else {
38 coor = new CachedLatLon(eastNorth);
39 }
40 }
41 }
42
43 public final EastNorth getEastNorth() {
44 return coor != null ? coor.getEastNorth() : null;
45 }
46
47
48 protected Node(long id, boolean allowNegative) {
49 super(id, allowNegative);
50 }
51
52
53 /**
54 * Create a new local node.
55 *
56 */
57 public Node() {
58 this(0, false);
59 }
60
61
62 /**
63 * Create an incomplete Node object
64 */
65 public Node(long id) {
66 super(id, false);
67 }
68
69 /**
70 *
71 * @param clone
72 * @param clearId If true, set version to 0 and id to new unique value
73 */
74 public Node(Node clone, boolean clearId) {
75 super(clone.getUniqueId(), true);
76 cloneFrom(clone);
77 if (clearId) {
78 clearOsmId();
79 }
80 }
81
82 /**
83 * Create an identical clone of the argument (including the id)
84 */
85 public Node(Node clone) {
86 this(clone, false);
87 }
88
89 public Node(LatLon latlon) {
90 super(0, false);
91 setCoor(latlon);
92 }
93
94 public Node(EastNorth eastNorth) {
95 super(0, false);
96 setEastNorth(eastNorth);
97 }
98
99 @Override public void visit(Visitor visitor) {
100 visitor.visit(this);
101 }
102
103 @Override public void cloneFrom(OsmPrimitive osm) {
104 super.cloneFrom(osm);
105 setCoor(((Node)osm).coor);
106 }
107
108 @Override public void load(PrimitiveData data) {
109 super.load(data);
110 setCoor(((NodeData)data).getCoor());
111 }
112
113 @Override public NodeData save() {
114 NodeData data = new NodeData();
115 saveCommonAttributes(data);
116 data.setCoor(getCoor());
117 return data;
118 }
119
120 @Override public String toString() {
121 String coorDesc = coor == null?"":"lat="+coor.lat()+",lon="+coor.lon();
122 return "{Node id=" + getUniqueId() + " version=" + getVersion() + " " + getFlagsAsString() + " " + coorDesc+"}";
123 }
124
125 @Override
126 public boolean hasEqualSemanticAttributes(OsmPrimitive other) {
127 if (other == null || ! (other instanceof Node) )
128 return false;
129 if (! super.hasEqualSemanticAttributes(other))
130 return false;
131 Node n = (Node)other;
132 if (coor == null && n.coor == null)
133 return true;
134 else if (coor != null && n.coor != null)
135 return coor.equals(n.coor);
136 else
137 return false;
138 }
139
140 public int compareTo(OsmPrimitive o) {
141 return o instanceof Node ? Long.valueOf(getId()).compareTo(o.getId()) : 1;
142 }
143
144 @Override
145 public String getDisplayName(NameFormatter formatter) {
146 return formatter.format(this);
147 }
148
149 public OsmPrimitiveType getType() {
150 return OsmPrimitiveType.NODE;
151 }
152}
Note: See TracBrowser for help on using the repository browser.