Class CycleDetector
- java.lang.Object
-
- org.openstreetmap.josm.data.validation.Test
-
- org.openstreetmap.josm.data.validation.tests.CycleDetector
-
- All Implemented Interfaces:
OsmPrimitiveVisitor
public class CycleDetector extends Test
Test for detecting cycles in a directed graph, currently used for waterways only. The processed graph consists of ways labeled as waterway.- Since:
- 19062
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.openstreetmap.josm.data.validation.Test
Test.TagTest
-
-
Field Summary
Fields Modifier and Type Field Description protected static int
CYCLE_DETECTED
private java.util.List<java.lang.String>
directionalWaterways
Currently used directional waterways from the OSM wikiprotected static java.lang.String
PREFIX
private java.util.Set<Way>
usableWaterways
All waterways for cycle detectionprivate java.util.Set<java.lang.Long>
visitedWays
Already visited primitive unique IDs-
Fields inherited from class org.openstreetmap.josm.data.validation.Test
checkBeforeUpload, checkEnabled, description, enabled, errors, IN_DOWNLOADED_AREA, IN_DOWNLOADED_AREA_STRICT, isBeforeUpload, name, partialSelection, progressMonitor, stopwatch, testBeforeUpload
-
-
Constructor Summary
Constructors Constructor Description CycleDetector()
Constructor
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private java.util.Collection<Way>
buildGraph(Way way)
Returns a collection of ways, which belongs to the same graph.private static java.util.Collection<WaySegment>
createSegments(java.util.Map<Node,java.util.List<Node>> graphMap, java.util.Collection<Node> nodes)
Creates WaySegments from Nodes for the error highlight function.void
endTest()
Notification of the end of the test.private java.util.Collection<java.util.Collection<Way>>
getGraphs()
Returns all directional waterways which connect to at least one other usable way.private static boolean
isConsecutive(Way w, Node n, Node m)
Determines if the given nodes are consecutive part of the parent way.boolean
isPrimitiveUsable(OsmPrimitive p)
Determines if the primitive is usable for tests.void
startTest(ProgressMonitor progressMonitor)
Start the test using a given progress monitorvoid
visit(Way w)
Visiting call for lines.-
Methods inherited from class org.openstreetmap.josm.data.validation.Test
addGui, clear, deletePrimitivesIfNeeded, fixError, getErrors, getName, getSource, initialize, isBuilding, isCanceled, isFixable, isResidentialArea, ok, removeIrrelevantErrors, setBeforeUpload, setPartialSelection, setShowElements, testBeforeUpload, visit, visit, visit
-
-
-
-
Field Detail
-
CYCLE_DETECTED
protected static final int CYCLE_DETECTED
- See Also:
- Constant Field Values
-
usableWaterways
private final java.util.Set<Way> usableWaterways
All waterways for cycle detection
-
visitedWays
private final java.util.Set<java.lang.Long> visitedWays
Already visited primitive unique IDs
-
directionalWaterways
private java.util.List<java.lang.String> directionalWaterways
Currently used directional waterways from the OSM wiki
-
PREFIX
protected static final java.lang.String PREFIX
-
-
Constructor Detail
-
CycleDetector
public CycleDetector()
Constructor
-
-
Method Detail
-
isPrimitiveUsable
public boolean isPrimitiveUsable(OsmPrimitive p)
Description copied from class:Test
Determines if the primitive is usable for tests.- Overrides:
isPrimitiveUsable
in classTest
- Parameters:
p
- The primitive- Returns:
true
if the primitive can be tested,false
otherwise
-
visit
public void visit(Way w)
Description copied from interface:OsmPrimitiveVisitor
Visiting call for lines.- Specified by:
visit
in interfaceOsmPrimitiveVisitor
- Overrides:
visit
in classTest
- Parameters:
w
- The way to inspect.
-
startTest
public void startTest(ProgressMonitor progressMonitor)
Description copied from class:Test
Start the test using a given progress monitor
-
endTest
public void endTest()
Description copied from class:Test
Notification of the end of the test. The tester may perform additional actions and destroy the used structures.If you override this method, don't forget to cleanup
progressMonitor
(most overrides callsuper.endTest()
to do this).
-
createSegments
private static java.util.Collection<WaySegment> createSegments(java.util.Map<Node,java.util.List<Node>> graphMap, java.util.Collection<Node> nodes)
Creates WaySegments from Nodes for the error highlight function.- Parameters:
graphMap
- the complete graph datanodes
- nodes to build the way segments from- Returns:
- WaySegments from the Nodes
-
isConsecutive
private static boolean isConsecutive(Way w, Node n, Node m)
Determines if the given nodes are consecutive part of the parent way.- Parameters:
w
- parent wayn
- the first node to look up in the way directionm
- the second, possibly consecutive node- Returns:
true
if the nodes are consecutive order in the way direction
-
getGraphs
private java.util.Collection<java.util.Collection<Way>> getGraphs()
Returns all directional waterways which connect to at least one other usable way.- Returns:
- all directional waterways which connect to at least one other usable way
-
buildGraph
private java.util.Collection<Way> buildGraph(Way way)
Returns a collection of ways, which belongs to the same graph.- Parameters:
way
- starting way to extend the graph from- Returns:
- a collection of ways which belongs to the same graph
-
-