Class Test
- java.lang.Object
-
- org.openstreetmap.josm.data.validation.Test
-
- All Implemented Interfaces:
OsmPrimitiveVisitor
- Direct Known Subclasses:
Addresses
,ApiCapabilitiesTest
,BarriersEntrances
,Coastlines
,ConnectivityRelations
,CrossingWays
,CycleDetector
,DirectionNodes
,DuplicatedWayNodes
,DuplicateNode
,DuplicateRelation
,DuplicateWay
,Highways
,LongSegment
,MultipolygonTest
,OverlappingWays
,PowerLines
,PublicTransportRouteTest
,RelationChecker
,RightAngleBuildingTest
,SelfIntersectingWay
,SharpAngles
,SimilarNamedWays
,Test.TagTest
,TurnrestrictionTest
,UnclosedWays
,UnconnectedWays
,UntaggedNode
,UntaggedWay
,WayConnectedToArea
,WronglyOrderedWays
public class Test extends java.lang.Object implements OsmPrimitiveVisitor
Parent class for all validation tests.A test is a primitive visitor, so that it can access to all data to be validated. These primitives are always visited in the same order: nodes first, then ways.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Test.TagTest
A test that forwards all primitives toTest.TagTest.check(OsmPrimitive)
.
-
Field Summary
Fields Modifier and Type Field Description protected javax.swing.JCheckBox
checkBeforeUpload
The preferences check for validation on uploadprotected javax.swing.JCheckBox
checkEnabled
The preferences check for validationprotected java.lang.String
description
Description of the testboolean
enabled
Whether this test is enabled.protected java.util.List<TestError>
errors
The list of errorsprotected static java.util.function.Predicate<OsmPrimitive>
IN_DOWNLOADED_AREA
protected static java.util.function.Predicate<OsmPrimitive>
IN_DOWNLOADED_AREA_STRICT
protected boolean
isBeforeUpload
Whether this test is performing just before an uploadprotected java.lang.String
name
Name of the testprotected boolean
partialSelection
Whether the test is run on a partial selection dataprotected ProgressMonitor
progressMonitor
the progress monitor to useprivate boolean
showElementCount
protected Stopwatch
stopwatch
the start time to compute elapsed time when test finishesboolean
testBeforeUpload
Whether this test must check before upload.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addGui(javax.swing.JPanel testPanel)
Allow the tester to manage its own preferencesvoid
clear()
Free resources.protected Command
deletePrimitivesIfNeeded(java.util.Collection<? extends OsmPrimitive> primitives)
Build a Delete command on all primitives that have not yet been deleted manually by user, or by another error fix.void
endTest()
Notification of the end of the test.Command
fixError(TestError testError)
Fixes the error with the appropriate commandjava.util.List<TestError>
getErrors()
Gets the validation errors accumulated until this moment.java.lang.String
getName()
Returns the test name.java.lang.Object
getSource()
Returns the name of this class.void
initialize()
Initializes any global data used this tester.protected static boolean
isBuilding(OsmPrimitive p)
Determines if the specified primitive denotes a building.boolean
isCanceled()
Determines if the test has been canceled.boolean
isFixable(TestError testError)
Returns true if the given error can be fixed automaticallyboolean
isPrimitiveUsable(OsmPrimitive p)
Determines if the primitive is usable for tests.protected static boolean
isResidentialArea(OsmPrimitive p)
Determines if the specified primitive denotes a residential area.boolean
ok()
Called when the used submits the preferencesvoid
removeIrrelevantErrors(java.util.Collection<? extends OsmPrimitive> given)
Filter the list of errors, remove all which do not concern the given list of primitivesvoid
setBeforeUpload(boolean isUpload)
Sets the flag that marks an upload checkvoid
setPartialSelection(boolean partialSelection)
Flag notifying that this test is run over a partial data selectionprotected void
setShowElements(boolean b)
void
startTest(ProgressMonitor progressMonitor)
Start the test using a given progress monitorboolean
testBeforeUpload()
Returns true if this plugin must check the uploaded data before uploadingvoid
visit(java.util.Collection<OsmPrimitive> selection)
Visits all primitives to be tested.void
visit(Node n)
Visiting call for points.void
visit(Relation r)
Visiting call for relations.void
visit(Way w)
Visiting call for lines.
-
-
-
Field Detail
-
IN_DOWNLOADED_AREA
protected static final java.util.function.Predicate<OsmPrimitive> IN_DOWNLOADED_AREA
-
IN_DOWNLOADED_AREA_STRICT
protected static final java.util.function.Predicate<OsmPrimitive> IN_DOWNLOADED_AREA_STRICT
-
name
protected final java.lang.String name
Name of the test
-
description
protected final java.lang.String description
Description of the test
-
enabled
public boolean enabled
Whether this test is enabled. Enabled by default
-
checkEnabled
protected javax.swing.JCheckBox checkEnabled
The preferences check for validation
-
checkBeforeUpload
protected javax.swing.JCheckBox checkBeforeUpload
The preferences check for validation on upload
-
testBeforeUpload
public boolean testBeforeUpload
Whether this test must check before upload. Enabled by default
-
isBeforeUpload
protected boolean isBeforeUpload
Whether this test is performing just before an upload
-
partialSelection
protected boolean partialSelection
Whether the test is run on a partial selection data
-
progressMonitor
protected ProgressMonitor progressMonitor
the progress monitor to use
-
showElementCount
private boolean showElementCount
-
-
Method Detail
-
initialize
public void initialize() throws java.lang.Exception
Initializes any global data used this tester.- Throws:
java.lang.Exception
- When cannot initialize the test
-
startTest
public void startTest(ProgressMonitor progressMonitor)
Start the test using a given progress monitor- Parameters:
progressMonitor
- the progress monitor
-
setPartialSelection
public void setPartialSelection(boolean partialSelection)
Flag notifying that this test is run over a partial data selection- Parameters:
partialSelection
- Whether the test is on a partial selection data
-
getErrors
public java.util.List<TestError> getErrors()
Gets the validation errors accumulated until this moment.- Returns:
- The list of errors
-
endTest
public void endTest()
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).
-
visit
public void visit(java.util.Collection<OsmPrimitive> selection)
Visits all primitives to be tested. These primitives are always visited in the same order: nodes first, then ways.- Parameters:
selection
- The primitives to be tested
-
isPrimitiveUsable
public boolean isPrimitiveUsable(OsmPrimitive p)
Determines if the primitive is usable for tests.- Parameters:
p
- The primitive- Returns:
true
if the primitive can be tested,false
otherwise
-
visit
public void visit(Node n)
Description copied from interface:OsmPrimitiveVisitor
Visiting call for points.- Specified by:
visit
in interfaceOsmPrimitiveVisitor
- Parameters:
n
- The node to inspect.
-
visit
public void visit(Way w)
Description copied from interface:OsmPrimitiveVisitor
Visiting call for lines.- Specified by:
visit
in interfaceOsmPrimitiveVisitor
- Parameters:
w
- The way to inspect.
-
visit
public void visit(Relation r)
Description copied from interface:OsmPrimitiveVisitor
Visiting call for relations.- Specified by:
visit
in interfaceOsmPrimitiveVisitor
- Parameters:
r
- The relation to inspect.
-
addGui
public void addGui(javax.swing.JPanel testPanel)
Allow the tester to manage its own preferences- Parameters:
testPanel
- The panel to add any preferences component
-
ok
public boolean ok()
Called when the used submits the preferences- Returns:
true
if restart is required,false
otherwise
-
fixError
public Command fixError(TestError testError)
Fixes the error with the appropriate command- Parameters:
testError
- error to fix- Returns:
- The command to fix the error
-
isFixable
public boolean isFixable(TestError testError)
Returns true if the given error can be fixed automatically- Parameters:
testError
- The error to check if can be fixed- Returns:
- true if the error can be fixed
-
testBeforeUpload
public boolean testBeforeUpload()
Returns true if this plugin must check the uploaded data before uploading- Returns:
- true if this plugin must check the uploaded data before uploading
-
setBeforeUpload
public void setBeforeUpload(boolean isUpload)
Sets the flag that marks an upload check- Parameters:
isUpload
- if true, the test is before upload
-
getName
public java.lang.String getName()
Returns the test name.- Returns:
- The test name
-
isCanceled
public boolean isCanceled()
Determines if the test has been canceled.- Returns:
true
if the test has been canceled,false
otherwise
-
deletePrimitivesIfNeeded
protected final Command deletePrimitivesIfNeeded(java.util.Collection<? extends OsmPrimitive> primitives)
Build a Delete command on all primitives that have not yet been deleted manually by user, or by another error fix. If all primitives have already been deleted, null is returned.- Parameters:
primitives
- The primitives wanted for deletion- Returns:
- a Delete command on all primitives that have not yet been deleted, or null otherwise
-
isBuilding
protected static final boolean isBuilding(OsmPrimitive p)
Determines if the specified primitive denotes a building.- Parameters:
p
- The primitive to be tested- Returns:
- True if building key is set and different from no,entrance
-
isResidentialArea
protected static final boolean isResidentialArea(OsmPrimitive p)
Determines if the specified primitive denotes a residential area.- Parameters:
p
- The primitive to be tested- Returns:
- True if landuse key is equal to residential
-
clear
public void clear()
Free resources.
-
setShowElements
protected void setShowElements(boolean b)
-
getSource
public java.lang.Object getSource()
Returns the name of this class.- Returns:
- the name of this class (for ToolTip)
- Since:
- 15972
-
removeIrrelevantErrors
public void removeIrrelevantErrors(java.util.Collection<? extends OsmPrimitive> given)
Filter the list of errors, remove all which do not concern the given list of primitives- Parameters:
given
- the list of primitives- Since:
- 18960
-
-