source: josm/src/org/openstreetmap/josm/data/osm/Segment.java@ 203

Last change on this file since 203 was 203, checked in by imi, 17 years ago
  • Fixed a bug in the Merger/Conflict to auto-resolve marked changes without real changes
  • Fixed bug in split way, that reversed the order of segments in one way.
  • Fixed bug where dialogs did not update anymore after loading a dataset twice
File size: 2.2 KB
Line 
1package org.openstreetmap.josm.data.osm;
2
3import org.openstreetmap.josm.data.osm.visitor.Visitor;
4
5
6/**
7 * One way segment consisting of a pair of nodes (from/to)
8 *
9 * @author imi
10 */
11public class Segment extends OsmPrimitive {
12
13 /**
14 * The starting node of the segment
15 */
16 public Node from;
17
18 /**
19 * The ending node of the segment
20 */
21 public Node to;
22
23 /**
24 * If set to true, this object is incomplete, which means only the id
25 * and type is known (type is the objects instance class)
26 */
27 public boolean incomplete;
28
29 /**
30 * Create an identical clone of the argument (including the id)
31 */
32 public Segment(Segment clone) {
33 cloneFrom(clone);
34 }
35
36 /**
37 * Create an segment from the given starting and ending node
38 * @param from Starting node of the segment.
39 * @param to Ending node of the segment.
40 */
41 public Segment(Node from, Node to) {
42 this.from = from;
43 this.to = to;
44 incomplete = false;
45 }
46
47 public Segment(long id) {
48 this.id = id;
49 incomplete = true;
50 }
51
52 @Override public void visit(Visitor visitor) {
53 visitor.visit(this);
54 }
55
56 /**
57 * @return <code>true</code>, if the <code>ls</code> occupy
58 * exactly the same place as <code>this</code>.
59 */
60 public boolean equalPlace(Segment ls) {
61 if (equals(ls))
62 return true;
63 if (incomplete || ls.incomplete)
64 return incomplete == ls.incomplete;
65 return ((from.coor.equals(ls.from.coor) && to.coor.equals(ls.to.coor)) ||
66 (from.coor.equals(ls.to.coor) && to.coor.equals(ls.from.coor)));
67 }
68
69 @Override public void cloneFrom(OsmPrimitive osm) {
70 super.cloneFrom(osm);
71 Segment ls = ((Segment)osm);
72 from = ls.from;
73 to = ls.to;
74 incomplete = ls.incomplete;
75 }
76
77 @Override public String toString() {
78 return "{Segment id="+id+" from="+from+" to="+to+"}";
79 }
80
81 @Override public boolean realEqual(OsmPrimitive osm, boolean semanticOnly) {
82 if (!(osm instanceof Segment))
83 return super.realEqual(osm, semanticOnly);
84 if (incomplete)
85 return ((Segment)osm).incomplete;
86 return super.realEqual(osm, semanticOnly) && from.equals(((Segment)osm).from) && to.equals(((Segment)osm).to);
87 }
88
89 public int compareTo(OsmPrimitive o) {
90 return o instanceof Segment ? Long.valueOf(id).compareTo(o.id) : (o instanceof Node ? -1 : 1);
91 }
92}
Note: See TracBrowser for help on using the repository browser.