- Timestamp:
- 2010-04-25T10:51:06+02:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/UploadSelectionAction.java
r3083 r3206 67 67 protected Set<OsmPrimitive> getDeletedPrimitives(DataSet ds) { 68 68 HashSet<OsmPrimitive> ret = new HashSet<OsmPrimitive>(); 69 for (OsmPrimitive p : ds.getNodes()) { 70 if (p.isDeleted() && !p.isNew() && p.isVisible() && p.isModified()) { 71 ret.add(p); 72 } 73 } 74 for (OsmPrimitive p : ds.getWays()) { 75 if (p.isDeleted() && !p.isNew() && p.isVisible() && p.isModified()) { 76 ret.add(p); 77 } 78 } 79 for (OsmPrimitive p : ds.getRelations()) { 69 for (OsmPrimitive p: ds.allPrimitives()) { 80 70 if (p.isDeleted() && !p.isNew() && p.isVisible() && p.isModified()) { 81 71 ret.add(p); … … 136 126 * Replies true if there is at least one non-new, deleted primitive in 137 127 * <code>primitives</code> 138 * 128 * 139 129 * @param primitives the primitives to scan 140 130 * @return true if there is at least one non-new, deleted primitive in -
trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmTaskList.java
r3083 r3206 106 106 protected Set<OsmPrimitive> getCompletePrimitives(DataSet ds) { 107 107 HashSet<OsmPrimitive> ret = new HashSet<OsmPrimitive>(); 108 for (OsmPrimitive primitive : ds.getNodes()) { 109 if (!primitive.isIncomplete() && !primitive.isNew()) { 110 ret.add(primitive); 111 } 112 } 113 for (OsmPrimitive primitive : ds.getWays()) { 114 if (!primitive.isIncomplete() && !primitive.isNew()) { 115 ret.add(primitive); 116 } 117 } 118 for (OsmPrimitive primitive : ds.getRelations()) { 108 for (OsmPrimitive primitive : ds.allPrimitives()) { 119 109 if (!primitive.isIncomplete() && !primitive.isNew()) { 120 110 ret.add(primitive); … … 205 195 DataSet ds = ((DownloadOsmTask) task).getDownloadedData(); 206 196 if (ds != null) { 207 ret.addAll(ds.getNodes()); 208 ret.addAll(ds.getWays()); 209 ret.addAll(ds.getRelations()); 197 ret.addAll(ds.allPrimitives()); 210 198 } 211 199 } … … 272 260 DataSet ds = ((DownloadOsmTask) task).getDownloadedData(); 273 261 if (ds != null) { 274 myPrimitives.removeAll(ds.getNodes()); 275 myPrimitives.removeAll(ds.getWays()); 276 myPrimitives.removeAll(ds.getRelations()); 262 myPrimitives.removeAll(ds.allPrimitives()); 277 263 } 278 264 } -
trunk/src/org/openstreetmap/josm/data/osm/DataSet.java
r3187 r3206 10 10 import java.util.Collections; 11 11 import java.util.HashMap; 12 import java.util.HashSet;13 12 import java.util.Iterator; 14 13 import java.util.LinkedHashSet; … … 16 15 import java.util.List; 17 16 import java.util.Map; 18 import java.util.Set;19 17 20 18 import org.openstreetmap.josm.data.SelectionChangedListener; 21 19 import org.openstreetmap.josm.data.coor.LatLon; 22 import org.openstreetmap.josm.data.osm.OsmPrimitive;23 20 import org.openstreetmap.josm.data.osm.event.AbstractDatasetChangedEvent; 24 21 import org.openstreetmap.josm.data.osm.event.ChangesetIdChangedEvent; … … 209 206 } 210 207 allPrimitives.add(primitive); 211 primitive.setDataset(this); 208 primitive.setDataset(this); 212 209 firePrimitivesAdded(Collections.singletonList(primitive), false); 213 210 } … … 642 639 } 643 640 644 public Set<Long> getPrimitiveIds() {645 HashSet<Long> ret = new HashSet<Long>();646 for (OsmPrimitive primitive : nodes) {647 ret.add(primitive.getId());648 }649 for (OsmPrimitive primitive : ways) {650 ret.add(primitive.getId());651 }652 for (OsmPrimitive primitive : relations) {653 ret.add(primitive.getId());654 }655 return ret;656 }657 658 641 protected void deleteWay(Way way) { 659 642 way.setNodes(null); … … 717 700 unlinkPrimitiveFromRelations(referencedPrimitive); 718 701 } 719 }720 721 /**722 * Replies a list of parent relations which refer to the relation723 * <code>child</code>. Replies an empty list if child is null.724 *725 * @param child the child relation726 * @return a list of parent relations which refer to the relation727 * <code>child</code>728 */729 public List<Relation> getParentRelations(Relation child) {730 ArrayList<Relation> parents = new ArrayList<Relation>();731 if (child == null)732 return parents;733 for (Relation parent : relations) {734 if (parent == child) {735 continue;736 }737 for (RelationMember member: parent.getMembers()) {738 if (member.refersTo(child)) {739 parents.add(parent);740 break;741 }742 }743 }744 return parents;745 702 } 746 703 -
trunk/src/org/openstreetmap/josm/data/osm/DatasetCollection.java
r3177 r3206 8 8 import org.openstreetmap.josm.tools.Predicate; 9 9 10 class DatasetCollection extends AbstractCollection<OsmPrimitive> {10 public class DatasetCollection extends AbstractCollection<OsmPrimitive> { 11 11 12 12 private class FilterIterator implements Iterator<OsmPrimitive> { 13 13 14 private final Iterator< OsmPrimitive> iterator;14 private final Iterator<? extends OsmPrimitive> iterator; 15 15 private OsmPrimitive current; 16 16 17 public FilterIterator(Iterator< OsmPrimitive> iterator) {17 public FilterIterator(Iterator<? extends OsmPrimitive> iterator) { 18 18 this.iterator = iterator; 19 19 } … … 47 47 } 48 48 49 private final Collection< OsmPrimitive> primitives;49 private final Collection<? extends OsmPrimitive> primitives; 50 50 private final Predicate<OsmPrimitive> predicate; 51 51 52 public DatasetCollection(Collection< OsmPrimitive> primitives, Predicate<OsmPrimitive> predicate) {52 public DatasetCollection(Collection<? extends OsmPrimitive> primitives, Predicate<OsmPrimitive> predicate) { 53 53 this.primitives = primitives; 54 54 this.predicate = predicate; … … 75 75 return !iterator().hasNext(); 76 76 } 77 77 78 } -
trunk/src/org/openstreetmap/josm/data/osm/Storage.java
r3202 r3206 23 23 import java.util.AbstractSet; 24 24 import java.util.Collection; 25 import java.util.ConcurrentModificationException;26 25 import java.util.Iterator; 27 26 import java.util.Map; -
trunk/src/org/openstreetmap/josm/data/osm/TagCollection.java
r3137 r3206 57 57 * Creates a tag collection from a map of key/value-pairs. Replies 58 58 * an empty tag collection if {@code tags} is null. 59 * 59 * 60 60 * @param tags the key/value-pairs 61 61 * @return the tag collection … … 130 130 TagCollection tags = new TagCollection(); 131 131 if (ds == null) return tags; 132 tags.add(TagCollection.unionOfAllPrimitives(ds.getNodes())); 133 tags.add(TagCollection.unionOfAllPrimitives(ds.getWays())); 134 tags.add(TagCollection.unionOfAllPrimitives(ds.getRelations())); 132 tags.add(TagCollection.unionOfAllPrimitives(ds.allPrimitives())); 135 133 return tags; 136 134 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/ChangesetDialog.java
r3083 r3206 307 307 return; 308 308 Set<OsmPrimitive> sel = new HashSet<OsmPrimitive>(); 309 for (OsmPrimitive p: ds.getNodes()) { 310 if (ids.contains(p.getChangesetId())) { 311 sel.add(p); 312 } 313 } 314 for (OsmPrimitive p: ds.getWays()) { 315 if (ids.contains(p.getChangesetId())) { 316 sel.add(p); 317 } 318 } 319 for (OsmPrimitive p: ds.getRelations()) { 309 for (OsmPrimitive p: ds.allPrimitives()) { 320 310 if (ids.contains(p.getChangesetId())) { 321 311 sel.add(p); -
trunk/src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetDetailPanel.java
r3083 r3206 380 380 OsmDataLayer layer = Main.main.getEditLayer(); 381 381 Set<OsmPrimitive> target = new HashSet<OsmPrimitive>(); 382 for (OsmPrimitive p: layer.data.getNodes()) { 383 if (p.isUsable() && p.getChangesetId() == current.getId()) { 384 target.add(p); 385 } 386 } 387 for (OsmPrimitive p: layer.data.getWays()) { 388 if (p.isUsable() && p.getChangesetId() == current.getId()) { 389 target.add(p); 390 } 391 } 392 for (OsmPrimitive p: layer.data.getRelations()) { 382 for (OsmPrimitive p: layer.data.allPrimitives()) { 393 383 if (p.isUsable() && p.getChangesetId() == current.getId()) { 394 384 target.add(p); … … 449 439 OsmDataLayer layer = Main.main.getEditLayer(); 450 440 Set<OsmPrimitive> target = new HashSet<OsmPrimitive>(); 451 for (OsmPrimitive p: layer.data. getNodes()) {441 for (OsmPrimitive p: layer.data.allPrimitives()) { 452 442 if (p.isUsable() && p.getChangesetId() == current.getId()) { 453 443 target.add(p); 454 444 } 455 445 } 456 for (OsmPrimitive p: layer.data.getWays()) {457 if (p.isUsable() && p.getChangesetId() == current.getId()) {458 target.add(p);459 }460 }461 for (OsmPrimitive p: layer.data.getRelations()) {462 if (p.isUsable() && p.getChangesetId() == current.getId()) {463 target.add(p);464 }465 }466 446 if (target.isEmpty()) { 467 447 alertNoPrimitivesToZoomTo(); -
trunk/src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetListModel.java
r3083 r3206 137 137 } 138 138 Set<Changeset> changesets = new HashSet<Changeset>(); 139 for (OsmPrimitive p: ds.getNodes()) { 140 if (p.getChangesetId() <=0 ) { 141 continue; 142 } 143 changesets.add(new Changeset(p.getChangesetId())); 144 } 145 for (OsmPrimitive p: ds.getWays()) { 146 if (p.getChangesetId() <=0 ) { 147 continue; 148 } 149 changesets.add(new Changeset(p.getChangesetId())); 150 } 151 for (OsmPrimitive p: ds.getRelations()) { 139 for (OsmPrimitive p: ds.allPrimitives()) { 152 140 if (p.getChangesetId() <=0 ) { 153 141 continue; -
trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java
r3118 r3206 25 25 import java.util.HashMap; 26 26 import java.util.HashSet; 27 import java.util.Iterator;28 27 import java.util.LinkedList; 29 28 import java.util.Map; 30 import java.util.Set;31 29 32 30 import javax.swing.AbstractAction; … … 55 53 import org.openstreetmap.josm.data.osm.DataSetMerger; 56 54 import org.openstreetmap.josm.data.osm.DataSource; 55 import org.openstreetmap.josm.data.osm.DatasetCollection; 57 56 import org.openstreetmap.josm.data.osm.DatasetConsistencyTest; 58 57 import org.openstreetmap.josm.data.osm.Node; … … 271 270 272 271 @Override public String getToolTipText() { 273 int nodes = undeletedSize(data.getNodes());274 int ways = undeletedSize(data.getWays());272 int nodes = new DatasetCollection(data.getNodes(), OsmPrimitive.nonDeletedPredicate).size(); 273 int ways = new DatasetCollection(data.getWays(), OsmPrimitive.nonDeletedPredicate).size(); 275 274 276 275 String tool = trn("{0} node", "{0} nodes", nodes, nodes)+", "; … … 477 476 478 477 // if uploaded, clean the modified flags as well 479 final Set<OsmPrimitive> processedSet = new HashSet<OsmPrimitive>(processed);480 478 data.clenupDeletedPrimitives(); 481 for (final Iterator<Node> it = data.getNodes().iterator(); it.hasNext();) { 482 cleanIterator(it, processedSet); 483 } 484 for (final Iterator<Way> it = data.getWays().iterator(); it.hasNext();) { 485 cleanIterator(it, processedSet); 486 } 487 for (final Iterator<Relation> it = data.getRelations().iterator(); it.hasNext();) { 488 cleanIterator(it, processedSet); 489 } 490 } 491 492 /** 493 * Clean the modified flag for the given iterator over a collection if it is in the 494 * list of processed entries. 495 * 496 * @param it The iterator to change the modified and remove the items if deleted. 497 * @param processed A list of all objects that have been successfully progressed. 498 * If the object in the iterator is not in the list, nothing will be changed on it. 499 */ 500 private void cleanIterator(final Iterator<? extends OsmPrimitive> it, final Collection<OsmPrimitive> processed) { 501 final OsmPrimitive osm = it.next(); 502 if (!processed.remove(osm)) 503 return; 504 osm.setModified(false); 505 } 506 507 /** 508 * @return The number of not-deleted and visible primitives in the list. 509 */ 510 private int undeletedSize(final Collection<? extends OsmPrimitive> list) { 511 int size = 0; 512 for (final OsmPrimitive osm : list) 513 if (!osm.isDeleted() && osm.isVisible()) { 514 size++; 515 } 516 return size; 517 } 479 for (OsmPrimitive p: data.allPrimitives()) { 480 if (processed.contains(p)) { 481 p.setModified(false); 482 } 483 } 484 } 485 518 486 519 487 @Override public Object getInfoComponent() {
Note:
See TracChangeset
for help on using the changeset viewer.