Changeset 35 in josm for src/org/openstreetmap/josm/data/osm/DataSet.java
- Timestamp:
- 2005-12-28T01:29:01+01:00 (20 years ago)
- File:
-
- 1 edited
-
src/org/openstreetmap/josm/data/osm/DataSet.java (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/org/openstreetmap/josm/data/osm/DataSet.java
r32 r35 2 2 3 3 import java.util.Collection; 4 import java.util.HashMap;5 4 import java.util.HashSet; 6 5 import java.util.LinkedList; 7 import java.util.Map;8 6 9 7 import org.openstreetmap.josm.data.Bounds; … … 44 42 45 43 /** 46 * All deleted objects goes here. 44 * @return A collection containing all primitives (except keys) of the 45 * dataset. 47 46 */ 48 public Collection<OsmPrimitive> deleted = new LinkedList<OsmPrimitive>(); 49 47 public Collection<OsmPrimitive> allPrimitives() { 48 Collection<OsmPrimitive> o = new LinkedList<OsmPrimitive>(); 49 o.addAll(nodes); 50 o.addAll(lineSegments); 51 o.addAll(tracks); 52 return o; 53 } 54 50 55 /** 51 56 * Return the bounds of this DataSet, depending on X/Y values. … … 133 138 134 139 /** 135 * Import the given dataset by merging all data with this dataset.136 * The objects imported are not cloned, so from now on, these data belong137 * to both datasets. So use mergeFrom only if you are about to abandon the138 * other dataset.139 *140 * Elements are tried to merged.141 * Nodes are merged first, if their lat/lon are equal.142 * Line segments are merged, if they have the same nodes.143 * Tracks are merged, if they consist of the same line segments.144 *145 * TODO Additional to that, every two objects with the same id are merged.146 *147 * @param ds The DataSet to merge into this one.148 */149 public void mergeFrom(DataSet ds) {150 // merge nodes151 152 Map<Node, Node> nodeMap = new HashMap<Node, Node>();153 154 // find mergable155 for (Node otherNode : ds.nodes)156 for (Node myNode : nodes)157 if (otherNode.coor.equalsLatLon(myNode.coor))158 nodeMap.put(otherNode, myNode);159 // add160 for (Node n : ds.nodes)161 if (!nodeMap.containsKey(n))162 nodes.add(n);163 // reassign164 for (LineSegment ls : ds.lineSegments) {165 Node n = nodeMap.get(ls.start);166 if (n != null)167 ls.start = n;168 n = nodeMap.get(ls.end);169 if (n != null)170 ls.end = n;171 }172 173 174 // merge line segments175 176 Map<LineSegment, LineSegment> lsMap = new HashMap<LineSegment, LineSegment>();177 // find mergable178 for (LineSegment otherLS : ds.lineSegments)179 for (LineSegment myLS : lineSegments)180 if (otherLS.start == myLS.start && otherLS.end == myLS.end)181 lsMap.put(otherLS, myLS);182 // add ls183 for (LineSegment ls : ds.lineSegments)184 if (!lsMap.containsKey(ls))185 lineSegments.add(ls);186 // reassign187 for (Track t : ds.tracks) {188 for (int i = 0; i < t.segments.size(); ++i) {189 LineSegment newLS = lsMap.get(t.segments.get(i));190 if (newLS != null)191 t.segments.set(i, newLS);192 }193 }194 195 196 // merge tracks197 198 LinkedList<Track> trackToAdd = new LinkedList<Track>();199 for (Track otherTrack : ds.tracks) {200 boolean found = false;201 for (Track myTrack : tracks) {202 if (myTrack.segments.equals(otherTrack.segments)) {203 found = true;204 break;205 }206 }207 if (!found)208 trackToAdd.add(otherTrack);209 }210 tracks.addAll(trackToAdd);211 }212 213 /**214 140 * Remove the selection from every value in the collection. 215 141 * @param list The collection to remove the selection from. … … 234 160 return sel; 235 161 for (OsmPrimitive osm : list) { 236 if (osm.isSelected()) 162 if (osm.isSelected() && !osm.isDeleted()) 237 163 sel.add(osm); 238 164 if (osm.keys != null)
Note:
See TracChangeset
for help on using the changeset viewer.
