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 classAbstractDifferenceEngine.ComparisonStateEncapsulates the current result and a flag that indicates whether comparison should be stopped.protected static interfaceAbstractDifferenceEngine.DeferredComparisonEncapsulates a comparison that may or may not be performed.protected classAbstractDifferenceEngine.FinishedComparisonStateprotected classAbstractDifferenceEngine.OngoingComparisonState
-
Field Summary
Fields Modifier and Type Field Description private Predicate<org.w3c.dom.Attr>attributeFilterprivate ComparisonControllercomparisonControllerprivate DifferenceEvaluatordiffEvaluatorprivate static java.lang.StringLISTENER_MUST_NOT_BE_NULLprivate ComparisonListenerSupportlistenersprivate Predicate<org.w3c.dom.Node>nodeFilterprivate NodeMatchernodeMatcherprivate static java.lang.StringNOT_BE_NULLprivate java.util.Map<java.lang.String,java.lang.String>prefix2uri
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractDifferenceEngine()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddComparisonListener(ComparisonListener l)Registers a listener that is notified of each comparison.voidaddDifferenceListener(ComparisonListener l)Registers a listener that is notified of each comparison with outcome other thanComparisonResult.EQUAL.voidaddMatchListener(ComparisonListener l)Registers a listener that is notified of each comparison with outcomeComparisonResult.EQUAL.protected AbstractDifferenceEngine.ComparisonStatecompare(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 ComparisonControllergetComparisonController()Provides access to the configured ComparisonController.protected DifferenceEvaluatorgetDifferenceEvaluator()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 NodeMatchergetNodeMatcher()Provides access to the configured NodeMatcher.protected static java.lang.StringgetParentXPath(XPathContext ctx)Returns a string representation of the given XPathContext's parent context.protected static java.lang.StringgetXPath(XPathContext ctx)Returns a string representation of the given XPathContext.voidsetAttributeFilter(Predicate<org.w3c.dom.Attr> af)Sets the optional strategy that decides which attributes to consider and which to ignore during comparison.voidsetComparisonController(ComparisonController c)Determines whether the comparison should stop after given difference has been found.voidsetDifferenceEvaluator(DifferenceEvaluator e)Evaluates the severity of a difference.voidsetNamespaceContext(java.util.Map<java.lang.String,java.lang.String> prefix2uri)Establish a namespace context that will be used inComparison.Detail#getXPath.voidsetNodeFilter(Predicate<org.w3c.dom.Node> nf)Sets the optional strategy that decides which nodes to consider and which to ignore during comparison.voidsetNodeMatcher(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:DifferenceEngineRegisters a listener that is notified of each comparison.- Specified by:
addComparisonListenerin interfaceDifferenceEngine
-
addMatchListener
public void addMatchListener(ComparisonListener l)
Description copied from interface:DifferenceEngineRegisters a listener that is notified of each comparison with outcomeComparisonResult.EQUAL.- Specified by:
addMatchListenerin interfaceDifferenceEngine
-
addDifferenceListener
public void addDifferenceListener(ComparisonListener l)
Description copied from interface:DifferenceEngineRegisters a listener that is notified of each comparison with outcome other thanComparisonResult.EQUAL.- Specified by:
addDifferenceListenerin interfaceDifferenceEngine
-
setNodeMatcher
public void setNodeMatcher(NodeMatcher n)
Description copied from interface:DifferenceEngineSets the strategy for selecting nodes to compare.- Specified by:
setNodeMatcherin interfaceDifferenceEngine
-
getNodeMatcher
protected NodeMatcher getNodeMatcher()
Provides access to the configured NodeMatcher.
-
setDifferenceEvaluator
public void setDifferenceEvaluator(DifferenceEvaluator e)
Description copied from interface:DifferenceEngineEvaluates the severity of a difference.- Specified by:
setDifferenceEvaluatorin interfaceDifferenceEngine
-
getDifferenceEvaluator
protected DifferenceEvaluator getDifferenceEvaluator()
Provides access to the configured DifferenceEvaluator.
-
setComparisonController
public void setComparisonController(ComparisonController c)
Description copied from interface:DifferenceEngineDetermines whether the comparison should stop after given difference has been found.- Specified by:
setComparisonControllerin 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:DifferenceEngineEstablish 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:
setNamespaceContextin 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:DifferenceEngineSets 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:
setAttributeFilterin 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:DifferenceEngineSets 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:
setNodeFilterin 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.
-
-