Skip to content

Commit

Permalink
Adjust code as requested by Taylor
Browse files Browse the repository at this point in the history
  • Loading branch information
gabortim committed Dec 18, 2023
1 parent 92500bd commit 44682aa
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 14 deletions.
10 changes: 5 additions & 5 deletions src/org/openstreetmap/josm/data/osm/NodeGraph.java
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public void add(NodePair pair) {
* Add a list of node pairs.
* @param pairs collection of node pairs
*/
public void add(Collection<NodePair> pairs) {
public void add(Iterable<NodePair> pairs) {
for (NodePair pair : pairs) {
add(pair);
}
Expand All @@ -194,15 +194,15 @@ public void add(Collection<NodePair> pairs) {
* Return the edges containing the node pairs of the graph.
* @return the edges containing the node pairs of the graph
*/
public Set<NodePair> getEdges() {
return edges;
public Collection<NodePair> getEdges() {
return Collections.unmodifiableSet(edges);
}

/**
* Return the graph's nodes.
* @return the graph's nodes
*/
public Set<Node> getNodes() {
public Collection<Node> getNodes() {
Set<Node> nodes = new LinkedHashSet<>(2 * edges.size());
for (NodePair pair : edges) {
nodes.add(pair.getA());
Expand Down Expand Up @@ -391,7 +391,7 @@ public List<Node> buildSpanningPathNoRemove() {
* @return {@code true} if it is connected
*/
private boolean isConnected() {
Set<Node> nodes = getNodes();
Collection<Node> nodes = getNodes();
if (nodes.isEmpty())
return false;
Deque<Node> toVisit = new ArrayDeque<>();
Expand Down
7 changes: 3 additions & 4 deletions src/org/openstreetmap/josm/data/validation/algos/Tarjan.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@
import java.util.List;
import java.util.Map;


/**
* Tarjan's strongly connected components algorithm for JOSM.
*
* @author gaben
* @see <a href="https://en.wikipedia.org/wiki/Tarjan%27s_strongly_connected_components_algorithm">
* Tarjan's strongly connected components algorithm</a>
* @author gaben
* @since xxx
*/
public final class Tarjan {
Expand Down Expand Up @@ -67,8 +66,8 @@ public Collection<List<Node>> getSCC() {

/**
* Returns the graph data as a map.
* @see NodeGraph#createMap()
* @return the graph data as a map
* @see NodeGraph#createMap()
*/
public Map<Node, List<Node>> getGraphMap() {
return graphMap;
Expand Down Expand Up @@ -148,7 +147,7 @@ private List<Node> getSuccessors(Node node) {
/**
* Helper class for storing the Tarjan algorithm runtime metadata.
*/
private static class TarjanHelper {
private static final class TarjanHelper {
private final int index;
private int lowlink;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
/**
* General purpose algorithm classes for JOSM data validation.
*/
package org.openstreetmap.josm.data.validation.algos;
package org.openstreetmap.josm.data.validation.algos;
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,15 @@
@BasicPreferences
class CycleDetectorTest {

@Test()
@Test
void testCycleDetection() throws Exception {
CycleDetector cycleDetector = new CycleDetector();
DataSet ds = OsmReader.parseDataSet(
Files.newInputStream(Paths.get(TestUtils.getTestDataRoot(), "CycleDetector_test_wikipedia.osm")), null);
DataSet ds = OsmReader.parseDataSet(TestUtils.getRegressionDataStream(21881, "CycleDetector_test_wikipedia.osm"), null);
cycleDetector.startTest(null);
cycleDetector.visit(ds.allPrimitives());
cycleDetector.endTest();

// we have 4 cycles in the test file
assertEquals(4, cycleDetector.getErrors().size());
}
}
}

0 comments on commit 44682aa

Please sign in to comment.