Package org.xmlunit.diff
Class AbstractDifferenceEngine
- java.lang.Object
-
- org.xmlunit.diff.AbstractDifferenceEngine
-
- All Implemented Interfaces:
DifferenceEngine
- Direct Known Subclasses:
DOMDifferenceEngine
public abstract class AbstractDifferenceEngine extends java.lang.Object implements DifferenceEngine
Useful base-implementation of some parts of the DifferenceEngine interface.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
AbstractDifferenceEngine.ComparisonState
Encapsulates the current result and a flag that indicates whether comparison should be stopped.protected static interface
AbstractDifferenceEngine.DeferredComparison
Encapsulates a comparison that may or may not be performed.protected class
AbstractDifferenceEngine.FinishedComparisonState
protected class
AbstractDifferenceEngine.OngoingComparisonState
-
Field Summary
Fields Modifier and Type Field Description private Predicate<org.w3c.dom.Attr>
attributeFilter
private ComparisonController
comparisonController
private DifferenceEvaluator
diffEvaluator
private static java.lang.String
LISTENER_MUST_NOT_BE_NULL
private ComparisonListenerSupport
listeners
private Predicate<org.w3c.dom.Node>
nodeFilter
private NodeMatcher
nodeMatcher
private static java.lang.String
NOT_BE_NULL
private java.util.Map<java.lang.String,java.lang.String>
prefix2uri
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractDifferenceEngine()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addComparisonListener(ComparisonListener l)
Registers a listener that is notified of each comparison.void
addDifferenceListener(ComparisonListener l)
Registers a listener that is notified of each comparison with outcome other thanComparisonResult.EQUAL
.void
addMatchListener(ComparisonListener l)
Registers a listener that is notified of each comparison with outcomeComparisonResult.EQUAL
.protected AbstractDifferenceEngine.ComparisonState
compare(Comparison comp)
Compares the detail values for object equality, lets the difference evaluator and comparison controller evaluate the result, notifies all listeners and returns the outcome.protected Predicate<org.w3c.dom.Attr>
getAttributeFilter()
Provides access to the configured ComparisonController.protected ComparisonController
getComparisonController()
Provides access to the configured ComparisonController.protected DifferenceEvaluator
getDifferenceEvaluator()
Provides access to the configured DifferenceEvaluator.protected java.util.Map<java.lang.String,java.lang.String>
getNamespaceContext()
Provides access to the configured namespace context.protected Predicate<org.w3c.dom.Node>
getNodeFilter()
Provides access to the configured ComparisonController.protected NodeMatcher
getNodeMatcher()
Provides access to the configured NodeMatcher.protected static java.lang.String
getParentXPath(XPathContext ctx)
Returns a string representation of the given XPathContext's parent context.protected static java.lang.String
getXPath(XPathContext ctx)
Returns a string representation of the given XPathContext.void
setAttributeFilter(Predicate<org.w3c.dom.Attr> af)
Sets the optional strategy that decides which attributes to consider and which to ignore during comparison.void
setComparisonController(ComparisonController c)
Determines whether the comparison should stop after given difference has been found.void
setDifferenceEvaluator(DifferenceEvaluator e)
Evaluates the severity of a difference.void
setNamespaceContext(java.util.Map<java.lang.String,java.lang.String> prefix2uri)
Establish a namespace context that will be used inComparison.Detail#getXPath
.void
setNodeFilter(Predicate<org.w3c.dom.Node> nf)
Sets the optional strategy that decides which nodes to consider and which to ignore during comparison.void
setNodeMatcher(NodeMatcher n)
Sets the strategy for selecting nodes to compare.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.xmlunit.diff.DifferenceEngine
compare
-
-
-
-
Field Detail
-
NOT_BE_NULL
private static final java.lang.String NOT_BE_NULL
- See Also:
- Constant Field Values
-
LISTENER_MUST_NOT_BE_NULL
private static final java.lang.String LISTENER_MUST_NOT_BE_NULL
- See Also:
- Constant Field Values
-
listeners
private final ComparisonListenerSupport listeners
-
nodeMatcher
private NodeMatcher nodeMatcher
-
diffEvaluator
private DifferenceEvaluator diffEvaluator
-
comparisonController
private ComparisonController comparisonController
-
prefix2uri
private java.util.Map<java.lang.String,java.lang.String> prefix2uri
-
attributeFilter
private Predicate<org.w3c.dom.Attr> attributeFilter
-
nodeFilter
private Predicate<org.w3c.dom.Node> nodeFilter
-
-
Method Detail
-
addComparisonListener
public void addComparisonListener(ComparisonListener l)
Description copied from interface:DifferenceEngine
Registers a listener that is notified of each comparison.- Specified by:
addComparisonListener
in interfaceDifferenceEngine
-
addMatchListener
public void addMatchListener(ComparisonListener l)
Description copied from interface:DifferenceEngine
Registers a listener that is notified of each comparison with outcomeComparisonResult.EQUAL
.- Specified by:
addMatchListener
in interfaceDifferenceEngine
-
addDifferenceListener
public void addDifferenceListener(ComparisonListener l)
Description copied from interface:DifferenceEngine
Registers a listener that is notified of each comparison with outcome other thanComparisonResult.EQUAL
.- Specified by:
addDifferenceListener
in interfaceDifferenceEngine
-
setNodeMatcher
public void setNodeMatcher(NodeMatcher n)
Description copied from interface:DifferenceEngine
Sets the strategy for selecting nodes to compare.- Specified by:
setNodeMatcher
in interfaceDifferenceEngine
-
getNodeMatcher
protected NodeMatcher getNodeMatcher()
Provides access to the configured NodeMatcher.
-
setDifferenceEvaluator
public void setDifferenceEvaluator(DifferenceEvaluator e)
Description copied from interface:DifferenceEngine
Evaluates the severity of a difference.- Specified by:
setDifferenceEvaluator
in interfaceDifferenceEngine
-
getDifferenceEvaluator
protected DifferenceEvaluator getDifferenceEvaluator()
Provides access to the configured DifferenceEvaluator.
-
setComparisonController
public void setComparisonController(ComparisonController c)
Description copied from interface:DifferenceEngine
Determines whether the comparison should stop after given difference has been found.- Specified by:
setComparisonController
in interfaceDifferenceEngine
-
getComparisonController
protected ComparisonController getComparisonController()
Provides access to the configured ComparisonController.
-
setNamespaceContext
public void setNamespaceContext(java.util.Map<java.lang.String,java.lang.String> prefix2uri)
Description copied from interface:DifferenceEngine
Establish a namespace context that will be used inComparison.Detail#getXPath
.Without a namespace context (or with an empty context) the XPath expressions will only use local names for elements and attributes.
- Specified by:
setNamespaceContext
in interfaceDifferenceEngine
- Parameters:
prefix2uri
- maps from prefix to namespace URI.
-
getNamespaceContext
protected java.util.Map<java.lang.String,java.lang.String> getNamespaceContext()
Provides access to the configured namespace context.
-
setAttributeFilter
public void setAttributeFilter(Predicate<org.w3c.dom.Attr> af)
Description copied from interface:DifferenceEngine
Sets the optional strategy that decides which attributes to consider and which to ignore during comparison.Only attributes for which the predicate returns true are part of the comparison. By default all attributes are considered.
The "special" namespace, namespace-location and schema-instance-type attributes can not be ignored this way. If you want to suppress comparison of them you'll need to implement
DifferenceEvaluator
.- Specified by:
setAttributeFilter
in interfaceDifferenceEngine
-
getAttributeFilter
protected Predicate<org.w3c.dom.Attr> getAttributeFilter()
Provides access to the configured ComparisonController.
-
setNodeFilter
public void setNodeFilter(Predicate<org.w3c.dom.Node> nf)
Description copied from interface:DifferenceEngine
Sets the optional strategy that decides which nodes to consider and which to ignore during comparison.Only nodes for which the predicate returns true are part of the comparison. By default nodes that are not document types are considered.
- Specified by:
setNodeFilter
in interfaceDifferenceEngine
-
getNodeFilter
protected Predicate<org.w3c.dom.Node> getNodeFilter()
Provides access to the configured ComparisonController.
-
compare
protected final AbstractDifferenceEngine.ComparisonState compare(Comparison comp)
Compares the detail values for object equality, lets the difference evaluator and comparison controller evaluate the result, notifies all listeners and returns the outcome.- Returns:
- the outcome as pair of result and a flag that says "stop the whole comparison process" when true.
-
getXPath
protected static java.lang.String getXPath(XPathContext ctx)
Returns a string representation of the given XPathContext.
-
getParentXPath
protected static java.lang.String getParentXPath(XPathContext ctx)
Returns a string representation of the given XPathContext's parent context.
-
-