org.openstreetmap.josm.data.validation
Class Test

java.lang.Object
  extended by org.openstreetmap.josm.data.osm.visitor.AbstractVisitor
      extended by org.openstreetmap.josm.data.validation.Test
All Implemented Interfaces:
Visitor
Direct Known Subclasses:
BuildingInBuilding, Coastlines, CrossingWays, DeprecatedTags, DuplicatedWayNodes, DuplicateNode, DuplicateRelation, DuplicateWay, MultipolygonTest, NameMismatch, NodesDuplicatingWayTags, NodesWithSameName, OverlappingAreas, OverlappingWays, PowerLines, RelationChecker, SelfIntersectingWay, SimilarNamedWays, TagChecker, TurnrestrictionTest, UnclosedWays, UnconnectedWays, UntaggedNode, UntaggedWay, WayConnectedToArea, WronglyOrderedWays

public class Test
extends AbstractVisitor

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.


Field Summary
protected  javax.swing.JCheckBox checkBeforeUpload
          The preferences check for validation on upload
protected  javax.swing.JCheckBox checkEnabled
          The preferences check for validation
protected  java.lang.String description
          Description of the test
 boolean enabled
          Whether this test is enabled.
protected  java.util.List<TestError> errors
          The list of errors
protected  boolean isBeforeUpload
          Whether this test is performing just before an upload
protected  java.lang.String name
          Name of the test
protected  boolean partialSelection
          Whether the test is run on a partial selection data
protected  ProgressMonitor progressMonitor
          the progress monitor to use
 boolean testBeforeUpload
          Whether this test must check before upload.
 
Constructor Summary
Test(java.lang.String name)
          Constructor
Test(java.lang.String name, java.lang.String description)
          Constructor
 
Method Summary
 void addGui(javax.swing.JPanel testPanel)
          Allow the tester to manage its own preferences
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 command
 java.util.List<TestError> getErrors()
          Gets the validation errors accumulated until this moment.
 java.lang.String getName()
           
 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()
           
 boolean isFixable(TestError testError)
          Returns true if the given error can be fixed automatically
 boolean ok()
          Called when the used submits the preferences
 void setBeforeUpload(boolean isUpload)
          Sets the flag that marks an upload check
 void setPartialSelection(boolean partialSelection)
          Flag notifying that this test is run over a partial data selection
 void startTest(ProgressMonitor progressMonitor)
          Start the test using a given progress monitor
 boolean testBeforeUpload()
          Returns true if this plugin must check the uploaded data before uploading
 void 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.
 
Methods inherited from class org.openstreetmap.josm.data.osm.visitor.AbstractVisitor
visit
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

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


errors

protected java.util.List<TestError> errors
The list of errors


partialSelection

protected boolean partialSelection
Whether the test is run on a partial selection data


progressMonitor

protected ProgressMonitor progressMonitor
the progress monitor to use

Constructor Detail

Test

public Test(java.lang.String name,
            java.lang.String description)
Constructor

Parameters:
name - Name of the test
description - Description of the test

Test

public Test(java.lang.String name)
Constructor

Parameters:
name - Name of the test
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 call super.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

visit

public void visit(Node n)
Description copied from interface: Visitor
Visiting call for points.

Parameters:
n - The node to inspect.

visit

public void visit(Way w)
Description copied from interface: Visitor
Visiting call for lines.

Parameters:
w - The way to inspect.

visit

public void visit(Relation r)
Description copied from interface: Visitor
Visiting call for relations.

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


fixError

public Command fixError(TestError testError)
Fixes the error with the appropriate command

Parameters:
testError -
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()

isCanceled

public boolean isCanceled()

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


JOSM