Skip to content

Commit

Permalink
Move visitedWays check one level up to better reflect the actual beha…
Browse files Browse the repository at this point in the history
…viour
  • Loading branch information
gabortim committed Dec 29, 2023
1 parent 53b386d commit 3bd0364
Showing 1 changed file with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -174,10 +173,14 @@ private Collection<Collection<Way>> getGraphs() {
Collection<Collection<Way>> graphs = new ArrayList<>();

for (Way waterway : usableWaterways) {
if (visitedWays.contains(waterway.getUniqueId())) {
continue;
}
Collection<Way> graph = buildGraph(waterway);

if (!graph.isEmpty())
if (!graph.isEmpty()) {
graphs.add(graph);
}
}

return graphs;
Expand All @@ -190,9 +193,6 @@ private Collection<Collection<Way>> getGraphs() {
* @return a collection of ways which belongs to the same graph
*/
private Collection<Way> buildGraph(Way way) {
if (visitedWays.contains(way.getUniqueId()))
return Collections.emptySet();

final Set<Way> graph = new HashSet<>();
Queue<Way> queue = new ArrayDeque<>();
queue.offer(way);
Expand Down

0 comments on commit 3bd0364

Please sign in to comment.