source: josm/src/org/openstreetmap/josm/data/osm/LineSegment.java@ 18

Last change on this file since 18 was 18, checked in by imi, 19 years ago

added Server connection to osm server.

File size: 1.9 KB
Line 
1package org.openstreetmap.josm.data.osm;
2
3import java.util.Collection;
4import java.util.Collections;
5import java.util.LinkedList;
6
7import org.openstreetmap.josm.data.osm.visitor.Visitor;
8
9
10/**
11 * One track line segment consisting of a pair of nodes (start/end)
12 *
13 * @author imi
14 */
15public class LineSegment extends OsmPrimitive {
16
17 /**
18 * The starting node of the line segment
19 */
20 Node start;
21
22 /**
23 * The ending node of the line segment
24 */
25 Node end;
26
27 /**
28 * The tracks, this line segment is part of.
29 */
30 transient Collection<Track> parent = new LinkedList<Track>();
31
32 /**
33 * Create an line segment from the given starting and ending node
34 * @param start Starting node of the line segment.
35 * @param end Ending node of the line segment.
36 */
37 public LineSegment(Node start, Node end) {
38 this.start = start;
39 this.end = end;
40 start.parentSegment.add(this);
41 end.parentSegment.add(this);
42 }
43
44 /**
45 * Return all parent tracks this line segment is part of. The list is readonly.
46 */
47 public Collection<Track> getParents() {
48 return Collections.unmodifiableCollection(parent);
49 }
50
51 public void setStart(Node start) {
52 this.start.parentSegment.remove(this);
53 this.start = start;
54 start.parentSegment.add(this);
55 }
56 public Node getStart() {
57 return start;
58 }
59 public void setEnd(Node end) {
60 this.end.parentSegment.remove(this);
61 this.end = end;
62 end.parentSegment.add(this);
63 }
64 public Node getEnd() {
65 return end;
66 }
67
68 /**
69 * The LineSegment is going to be destroyed. Unlink all back references.
70 */
71 void destroy() {
72 start.parentSegment.remove(this);
73 end.parentSegment.remove(this);
74 }
75
76 /**
77 * Return start and end in a list.
78 */
79 @Override
80 public Collection<Node> getAllNodes() {
81 LinkedList<Node> nodes = new LinkedList<Node>();
82 nodes.add(getStart());
83 nodes.add(getEnd());
84 return nodes;
85 }
86
87 @Override
88 public void visit(Visitor visitor) {
89 visitor.visit(this);
90 }
91}
Note: See TracBrowser for help on using the repository browser.