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

Last change on this file since 86 was 86, checked in by imi, 18 years ago
  • added conflicts and resolve conflict dialog

This is one of those "changed everything" checkpoint.

File size: 1.9 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) {
82 return osm instanceof Segment ?
83 super.realEqual(osm) &&
84 from.equals(((Segment)osm).from) &&
85 to.equals(((Segment)osm).to) : false;
86 }
87}
Note: See TracBrowser for help on using the repository browser.