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 classTest.TagTestA test that forwards all primitives toTest.TagTest.check(OsmPrimitive).
-
Field Summary
Fields Modifier and Type Field Description protected javax.swing.JCheckBoxcheckBeforeUploadThe preferences check for validation on uploadprotected javax.swing.JCheckBoxcheckEnabledThe preferences check for validationprotected java.lang.StringdescriptionDescription of the testbooleanenabledWhether this test is enabled.protected java.util.List<TestError>errorsThe list of errorsprotected static java.util.function.Predicate<OsmPrimitive>IN_DOWNLOADED_AREAprotected static java.util.function.Predicate<OsmPrimitive>IN_DOWNLOADED_AREA_STRICTprotected booleanisBeforeUploadWhether this test is performing just before an uploadprotected java.lang.StringnameName of the testprotected booleanpartialSelectionWhether the test is run on a partial selection dataprotected ProgressMonitorprogressMonitorthe progress monitor to useprivate booleanshowElementCountprotected Stopwatchstopwatchthe start time to compute elapsed time when test finishesbooleantestBeforeUploadWhether this test must check before upload.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddGui(javax.swing.JPanel testPanel)Allow the tester to manage its own preferencesvoidclear()Free resources.protected CommanddeletePrimitivesIfNeeded(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.voidendTest()Notification of the end of the test.CommandfixError(TestError testError)Fixes the error with the appropriate commandjava.util.List<TestError>getErrors()Gets the validation errors accumulated until this moment.java.lang.StringgetName()Returns the test name.java.lang.ObjectgetSource()Returns the name of this class.voidinitialize()Initializes any global data used this tester.protected static booleanisBuilding(OsmPrimitive p)Determines if the specified primitive denotes a building.booleanisCanceled()Determines if the test has been canceled.booleanisFixable(TestError testError)Returns true if the given error can be fixed automaticallybooleanisPrimitiveUsable(OsmPrimitive p)Determines if the primitive is usable for tests.protected static booleanisResidentialArea(OsmPrimitive p)Determines if the specified primitive denotes a residential area.booleanok()Called when the used submits the preferencesvoidremoveIrrelevantErrors(java.util.Collection<? extends OsmPrimitive> given)Filter the list of errors, remove all which do not concern the given list of primitivesvoidsetBeforeUpload(boolean isUpload)Sets the flag that marks an upload checkvoidsetPartialSelection(boolean partialSelection)Flag notifying that this test is run over a partial data selectionprotected voidsetShowElements(boolean b)voidstartTest(ProgressMonitor progressMonitor)Start the test using a given progress monitorbooleantestBeforeUpload()Returns true if this plugin must check the uploaded data before uploadingvoidvisit(java.util.Collection<OsmPrimitive> selection)Visits all primitives to be tested.voidvisit(Node n)Visiting call for points.voidvisit(Relation r)Visiting call for relations.voidvisit(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:
trueif the primitive can be tested,falseotherwise
-
visit
public void visit(Node n)
Description copied from interface:OsmPrimitiveVisitorVisiting call for points.- Specified by:
visitin interfaceOsmPrimitiveVisitor- Parameters:
n- The node to inspect.
-
visit
public void visit(Way w)
Description copied from interface:OsmPrimitiveVisitorVisiting call for lines.- Specified by:
visitin interfaceOsmPrimitiveVisitor- Parameters:
w- The way to inspect.
-
visit
public void visit(Relation r)
Description copied from interface:OsmPrimitiveVisitorVisiting call for relations.- Specified by:
visitin 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:
trueif restart is required,falseotherwise
-
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:
trueif the test has been canceled,falseotherwise
-
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
-
-