Changeset 6556 in josm for trunk/src/org/openstreetmap/josm/data/osm
- Timestamp:
- 2013-12-28T23:17:38+01:00 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/Node.java
r6491 r6556 8 8 import org.openstreetmap.josm.data.osm.visitor.Visitor; 9 9 import org.openstreetmap.josm.data.projection.Projections; 10 import org.openstreetmap.josm.tools.CheckParameterUtil; 11 import org.openstreetmap.josm.tools.Predicate; 12 import org.openstreetmap.josm.tools.Utils; 13 14 import java.util.Collection; 15 import java.util.Set; 16 import java.util.TreeSet; 10 17 11 18 /** … … 337 344 return false; 338 345 } 346 347 /** 348 * Tests whether {@code this} node is connected to {@code otherNode} via at most {@code hops} nodes 349 * matching the {@code predicate} (which may be {@code null} to consider all nodes). 350 */ 351 public boolean isConnectedTo(final Collection<Node> otherNodes, final int hops, Predicate<Node> predicate) { 352 CheckParameterUtil.ensureParameterNotNull(otherNodes); 353 CheckParameterUtil.ensureThat(!otherNodes.isEmpty(), "otherNodes must not be empty!"); 354 CheckParameterUtil.ensureThat(hops >= 0, "hops must be non-negative!"); 355 return hops == 0 356 ? isConnectedTo(otherNodes, hops, predicate, null) 357 : isConnectedTo(otherNodes, hops, predicate, new TreeSet<Node>()); 358 } 359 360 private boolean isConnectedTo(final Collection<Node> otherNodes, final int hops, Predicate<Node> predicate, Set<Node> visited) { 361 if (otherNodes.contains(this)) { 362 return true; 363 } 364 if (hops > 0) { 365 visited.add(this); 366 for (final Way w : Utils.filteredCollection(this.getReferrers(), Way.class)) { 367 for (final Node n : w.getNodes()) { 368 final boolean containsN = visited.contains(n); 369 visited.add(n); 370 if (!containsN && (predicate == null || predicate.evaluate(n)) && n.isConnectedTo(otherNodes, hops - 1, predicate, visited)) { 371 return true; 372 } 373 } 374 } 375 } 376 return false; 377 } 339 378 }
Note:
See TracChangeset
for help on using the changeset viewer.