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

Last change on this file since 1747 was 1747, checked in by stoecker, 15 years ago

close #2874 (NPE), improved external style handling

  • Property svn:eol-style set to native
File size: 4.2 KB
Line 
1// License: GPL. Copyright 2007 by Immanuel Scholz and others
2package org.openstreetmap.josm.data.osm;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import org.openstreetmap.josm.Main;
7import org.openstreetmap.josm.data.coor.EastNorth;
8import org.openstreetmap.josm.data.coor.CachedLatLon;
9import org.openstreetmap.josm.data.coor.LatLon;
10import org.openstreetmap.josm.data.coor.LatLon.CoordinateFormat;
11import org.openstreetmap.josm.data.projection.Projection;
12import org.openstreetmap.josm.data.osm.visitor.Visitor;
13import org.openstreetmap.josm.data.osm.Node;
14
15/**
16 * One node data, consisting of one world coordinate waypoint.
17 *
18 * @author imi
19 */
20public final class Node extends OsmPrimitive {
21
22 private CachedLatLon coor;
23
24 public final void setCoor(LatLon coor) {
25 if(coor != null)
26 {
27 if(this.coor == null)
28 this.coor = new CachedLatLon(coor);
29 else
30 this.coor.setCoor(coor);
31 }
32 }
33
34 public final LatLon getCoor() {
35 return coor;
36 }
37
38 public final void setEastNorth(EastNorth eastNorth) {
39 if(eastNorth != null)
40 {
41 if(coor != null)
42 coor.setEastNorth(eastNorth);
43 else
44 coor = new CachedLatLon(eastNorth);
45 }
46 }
47
48 public final EastNorth getEastNorth() {
49 return coor != null ? coor.getEastNorth() : null;
50 }
51
52 private static CoordinateFormat mCord;
53
54 static public CoordinateFormat getCoordinateFormat()
55 {
56 return mCord;
57 }
58
59 static public void setCoordinateFormat()
60 {
61 try {
62 mCord = LatLon.CoordinateFormat.valueOf(Main.pref.get("coordinates"));
63 } catch (IllegalArgumentException iae) {
64 mCord = LatLon.CoordinateFormat.DECIMAL_DEGREES;
65 }
66 }
67
68 static {
69 setCoordinateFormat();
70 }
71
72 /**
73 * Create an incomplete Node object
74 */
75 public Node(long id) {
76 this.id = id;
77 incomplete = true;
78 }
79
80 /**
81 * Create an identical clone of the argument (including the id)
82 */
83 public Node(Node clone) {
84 cloneFrom(clone);
85 }
86
87 public Node(LatLon latlon) {
88 setCoor(latlon);
89 }
90
91 public Node(EastNorth eastNorth) {
92 setEastNorth(eastNorth);
93 }
94
95 @Override public void visit(Visitor visitor) {
96 visitor.visit(this);
97 }
98
99 @Override public void cloneFrom(OsmPrimitive osm) {
100 super.cloneFrom(osm);
101 setCoor(((Node)osm).coor);
102 }
103
104 @Override public String toString() {
105 if (coor == null) return "{Node id="+id+"}";
106 return "{Node id="+id+",version="+version+",lat="+coor.lat()+",lon="+coor.lon()+"}";
107 }
108
109 /**
110 * @deprecated
111 * @see #hasEqualSemanticAttributes(OsmPrimitive)
112 * @see #hasEqualTechnicalAttributes(OsmPrimitive)
113 */
114 @Deprecated
115 @Override public boolean realEqual(OsmPrimitive osm, boolean semanticOnly) {
116 if (osm instanceof Node) {
117 if (super.realEqual(osm, semanticOnly)) {
118 if ((coor == null) && ((Node)osm).coor == null)
119 return true;
120 if (coor != null)
121 return coor.equals(((Node)osm).coor);
122 }
123 }
124 return false;
125 }
126
127 @Override
128 public boolean hasEqualSemanticAttributes(OsmPrimitive other) {
129 if (other == null || ! (other instanceof Node) )
130 return false;
131 if (! super.hasEqualSemanticAttributes(other))
132 return false;
133 Node n = (Node)other;
134 if (coor == null && n.coor == null)
135 return true;
136 else if (coor != null && n.coor != null)
137 return coor.equals(n.coor);
138 else
139 return false;
140 }
141
142 public int compareTo(OsmPrimitive o) {
143 return o instanceof Node ? Long.valueOf(id).compareTo(o.id) : 1;
144 }
145
146 @Override
147 public String getName() {
148 String name;
149 if (incomplete) {
150 name = tr("incomplete");
151 } else {
152 name = get("name");
153 if (name == null) {
154 name = id == 0 ? tr("node") : ""+id;
155 }
156 name += " (" + coor.latToString(mCord) + ", " + coor.lonToString(mCord) + ")";
157 }
158 return name;
159 }
160
161}
Note: See TracBrowser for help on using the repository browser.