source: josm/src/org/openstreetmap/josm/data/osm/Track.java@ 7

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

added mapmodes for adding and combining stuff. Reorganized images

File size: 2.1 KB
Line 
1package org.openstreetmap.josm.data.osm;
2
3import java.util.ArrayList;
4import java.util.Collection;
5import java.util.List;
6
7/**
8 * One full track, consisting of several track segments chained together.
9 *
10 * @author imi
11 */
12public class Track extends OsmPrimitive {
13
14 /**
15 * All track segments in this track
16 */
17 public final List<LineSegment> segments = new ArrayList<LineSegment>();
18
19 /**
20 * Return a merge of getAllNodes - calls to the line segments.
21 */
22 @Override
23 public Collection<Node> getAllNodes() {
24 ArrayList<Node> nodes = new ArrayList<Node>();
25 for (LineSegment ls : segments)
26 nodes.addAll(ls.getAllNodes());
27 return nodes;
28 }
29
30 /**
31 * Tracks are equal, when all segments and the keys are equal
32 */
33 @Override
34 public boolean equals(Object obj) {
35 if (!(obj instanceof Track))
36 return false;
37 if (!super.equals(obj))
38 return false;
39 Track t = (Track)obj;
40 int size = segments.size();
41 if (size != t.segments.size())
42 return false;
43 for (int i = 0; i < size; ++i)
44 if (!segments.get(i).equals(t.segments.get(i)))
45 return false;
46 return true;
47 }
48
49 @Override
50 public int hashCode() {
51 int hash = super.hashCode();
52 for (LineSegment ls : segments)
53 hash += ls.hashCode();
54 return hash;
55 }
56
57 /**
58 * Return the last node in the track. This is the node, which no line segment
59 * has as start, but at least one has it as end. If there are not exact one
60 * such nodes found, <code>null</code> is returned.
61 *
62 * TODO Currently does return just the end node in the list.
63 *
64 * @return The ending node, if there is one.
65 */
66 public Node getEndingNode() {
67 if (segments.isEmpty())
68 return null;
69 return segments.get(segments.size()-1).end;
70 }
71
72 /**
73 * Return the first node in the track. This is the node, which no line segment
74 * has as end, but at least one as starting node. If there are not exact one
75 * such nodes found, <code>null</code> is returned.
76 *
77 * TODO Currently does return just the first node in the list.
78 *
79 * @return The starting node, if there is one.
80 */
81 public Node getStartingNode() {
82 if (segments.isEmpty())
83 return null;
84 return segments.get(0).start;
85 }
86}
Note: See TracBrowser for help on using the repository browser.