source: josm/src/org/openstreetmap/josm/data/osm/DataSet.java@ 78

Last change on this file since 78 was 78, checked in by imi, 18 years ago
  • added more context menu items to layer list
  • added GPX export (raw gps and osm)
File size: 3.0 KB
Line 
1package org.openstreetmap.josm.data.osm;
2
3import java.util.Collection;
4import java.util.HashSet;
5import java.util.LinkedList;
6
7import org.openstreetmap.josm.data.SelectionTracker;
8
9/**
10 * DataSet is the data behind the application. It can consists of only a few
11 * points up to the whole osm database. DataSet's can be merged together,
12 * saved, (up/down/disk)loaded etc.
13 *
14 * Note, that DataSet is not an osm-primitive and so has no key association
15 * but a few members to store some information.
16 *
17 * @author imi
18 */
19public class DataSet extends SelectionTracker {
20
21 /**
22 * All nodes goes here, even when included in other data (ways etc).
23 * This enables the instant conversion of the whole DataSet by iterating over
24 * this data structure.
25 */
26 public Collection<Node> nodes = new LinkedList<Node>();
27
28 /**
29 * All line segments goes here, even when they are in a way.
30 */
31 public Collection<LineSegment> lineSegments = new LinkedList<LineSegment>();
32
33 /**
34 * All ways (Streets etc.) in the DataSet.
35 *
36 * The nodes of the way segments of this way must be objects from
37 * the nodes list, however the way segments are stored only in the
38 * way list.
39 */
40 public Collection<Way> ways = new LinkedList<Way>();
41
42 /**
43 * @return A collection containing all primitives (except keys) of the
44 * dataset.
45 */
46 public Collection<OsmPrimitive> allPrimitives() {
47 Collection<OsmPrimitive> o = new LinkedList<OsmPrimitive>();
48 o.addAll(nodes);
49 o.addAll(lineSegments);
50 o.addAll(ways);
51 return o;
52 }
53
54 /**
55 * @return A collection containing all not-deleted primitives (except keys).
56 */
57 public Collection<OsmPrimitive> allNonDeletedPrimitives() {
58 Collection<OsmPrimitive> o = new LinkedList<OsmPrimitive>();
59 for (OsmPrimitive osm : allPrimitives())
60 if (!osm.isDeleted())
61 o.add(osm);
62 return o;
63 }
64
65 /**
66 * Remove the selection of the whole dataset.
67 */
68 public void clearSelection() {
69 clearSelection(nodes);
70 clearSelection(lineSegments);
71 clearSelection(ways);
72 }
73
74 /**
75 * Return a list of all selected objects. Even keys are returned.
76 * @return List of all selected objects.
77 */
78 @Override
79 public Collection<OsmPrimitive> getSelected() {
80 Collection<OsmPrimitive> sel = getSelected(nodes);
81 sel.addAll(getSelected(lineSegments));
82 sel.addAll(getSelected(ways));
83 return sel;
84 }
85
86 /**
87 * Remove the selection from every value in the collection.
88 * @param list The collection to remove the selection from.
89 */
90 private void clearSelection(Collection<? extends OsmPrimitive> list) {
91 if (list == null)
92 return;
93 for (OsmPrimitive osm : list)
94 osm.setSelected(false);
95 }
96
97 /**
98 * Return all selected items in the collection.
99 * @param list The collection from which the selected items are returned.
100 */
101 private Collection<OsmPrimitive> getSelected(Collection<? extends OsmPrimitive> list) {
102 Collection<OsmPrimitive> sel = new HashSet<OsmPrimitive>();
103 if (list == null)
104 return sel;
105 for (OsmPrimitive osm : list)
106 if (osm.isSelected() && !osm.isDeleted())
107 sel.add(osm);
108 return sel;
109 }
110}
Note: See TracBrowser for help on using the repository browser.