1 | // License: GPL. Copyright 2007 by Immanuel Scholz and others
|
---|
2 | package org.openstreetmap.josm.data.osm;
|
---|
3 |
|
---|
4 | import java.util.Locale;
|
---|
5 |
|
---|
6 | import org.openstreetmap.josm.data.coor.CachedLatLon;
|
---|
7 | import org.openstreetmap.josm.data.coor.EastNorth;
|
---|
8 | import org.openstreetmap.josm.data.coor.LatLon;
|
---|
9 | import org.openstreetmap.josm.data.osm.visitor.Visitor;
|
---|
10 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
11 |
|
---|
12 | /**
|
---|
13 | * One node data, consisting of one world coordinate waypoint.
|
---|
14 | *
|
---|
15 | * @author imi
|
---|
16 | */
|
---|
17 | public final class Node extends OsmPrimitive {
|
---|
18 |
|
---|
19 | private CachedLatLon coor;
|
---|
20 |
|
---|
21 | public final void setCoor(LatLon coor) {
|
---|
22 | if(coor != null)
|
---|
23 | {
|
---|
24 | if(this.coor == null) {
|
---|
25 | this.coor = new CachedLatLon(coor);
|
---|
26 | } else {
|
---|
27 | this.coor.setCoor(coor);
|
---|
28 | }
|
---|
29 | }
|
---|
30 | }
|
---|
31 |
|
---|
32 | public final LatLon getCoor() {
|
---|
33 | return coor;
|
---|
34 | }
|
---|
35 |
|
---|
36 | public final void setEastNorth(EastNorth eastNorth) {
|
---|
37 | if(eastNorth != null)
|
---|
38 | {
|
---|
39 | if(coor != null) {
|
---|
40 | coor.setEastNorth(eastNorth);
|
---|
41 | } else {
|
---|
42 | coor = new CachedLatLon(eastNorth);
|
---|
43 | }
|
---|
44 | }
|
---|
45 | }
|
---|
46 |
|
---|
47 | public final EastNorth getEastNorth() {
|
---|
48 | return coor != null ? coor.getEastNorth() : null;
|
---|
49 | }
|
---|
50 |
|
---|
51 |
|
---|
52 |
|
---|
53 | /**
|
---|
54 | * Create an incomplete Node object
|
---|
55 | */
|
---|
56 | public Node(long id) {
|
---|
57 | this.id = id;
|
---|
58 | incomplete = true;
|
---|
59 | }
|
---|
60 |
|
---|
61 | /**
|
---|
62 | * Create an identical clone of the argument (including the id)
|
---|
63 | */
|
---|
64 | public Node(Node clone) {
|
---|
65 | cloneFrom(clone);
|
---|
66 | }
|
---|
67 |
|
---|
68 | public Node(LatLon latlon) {
|
---|
69 | setCoor(latlon);
|
---|
70 | }
|
---|
71 |
|
---|
72 | public Node(EastNorth eastNorth) {
|
---|
73 | setEastNorth(eastNorth);
|
---|
74 | }
|
---|
75 |
|
---|
76 | @Override public void visit(Visitor visitor) {
|
---|
77 | visitor.visit(this);
|
---|
78 | }
|
---|
79 |
|
---|
80 | @Override public void cloneFrom(OsmPrimitive osm) {
|
---|
81 | super.cloneFrom(osm);
|
---|
82 | setCoor(((Node)osm).coor);
|
---|
83 | }
|
---|
84 |
|
---|
85 | @Override public String toString() {
|
---|
86 | if (coor == null) return "{Node id="+id+"}";
|
---|
87 | return "{Node id="+id+",version="+version+",lat="+coor.lat()+",lon="+coor.lon()+"}";
|
---|
88 | }
|
---|
89 |
|
---|
90 | @Override
|
---|
91 | public boolean hasEqualSemanticAttributes(OsmPrimitive other) {
|
---|
92 | if (other == null || ! (other instanceof Node) )
|
---|
93 | return false;
|
---|
94 | if (! super.hasEqualSemanticAttributes(other))
|
---|
95 | return false;
|
---|
96 | Node n = (Node)other;
|
---|
97 | if (coor == null && n.coor == null)
|
---|
98 | return true;
|
---|
99 | else if (coor != null && n.coor != null)
|
---|
100 | return coor.equals(n.coor);
|
---|
101 | else
|
---|
102 | return false;
|
---|
103 | }
|
---|
104 |
|
---|
105 | public int compareTo(OsmPrimitive o) {
|
---|
106 | return o instanceof Node ? Long.valueOf(id).compareTo(o.id) : 1;
|
---|
107 | }
|
---|
108 |
|
---|
109 | @Override
|
---|
110 | public String getDisplayName(NameFormatter formatter) {
|
---|
111 | return formatter.format(this);
|
---|
112 | }
|
---|
113 |
|
---|
114 | @Override
|
---|
115 | public String getName() {
|
---|
116 | String name = super.getName();
|
---|
117 | if (name != null)
|
---|
118 | return name;
|
---|
119 | // no translation
|
---|
120 | return "node " + id;
|
---|
121 | }
|
---|
122 |
|
---|
123 | @Override
|
---|
124 | public String getLocalName(){
|
---|
125 | String name = super.getLocalName();
|
---|
126 | if (name != null)
|
---|
127 | return name;
|
---|
128 | return tr("node {0}",id);
|
---|
129 | }
|
---|
130 | }
|
---|