Class AbstractDifferenceEngine
- java.lang.Object
-
- org.xmlunit.diff.AbstractDifferenceEngine
-
- All Implemented Interfaces:
DifferenceEngine
- Direct Known Subclasses:
DOMDifferenceEngine
public abstract class AbstractDifferenceEngine extends 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.FinishedComparisonStateA comparison state that indicates the comparison should be stopped.protected classAbstractDifferenceEngine.OngoingComparisonStateA comparison state that indicates the comparison should perform further steps.
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractDifferenceEngine()Protected default constructor.
-
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<Attr>getAttributeFilter()Provides access to the configured attribute filter.protected ComparisonControllergetComparisonController()Provides access to the configured ComparisonController.protected DifferenceEvaluatorgetDifferenceEvaluator()Provides access to the configured DifferenceEvaluator.protected Map<String,String>getNamespaceContext()Provides access to the configured namespace context.protected Predicate<Node>getNodeFilter()Provides access to the configured nod filter.protected NodeMatchergetNodeMatcher()Provides access to the configured NodeMatcher.protected static StringgetParentXPath(XPathContext ctx)Returns a string representation of the given XPathContext's parent context.protected static StringgetXPath(XPathContext ctx)Returns a string representation of the given XPathContext.voidsetAttributeFilter(Predicate<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(Map<String,String> prefix2uri)Establish a namespace context that will be used inComparison.Detail#getXPath.voidsetNodeFilter(Predicate<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
-
-
-
-
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- Parameters:
l- the listener to add
-
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- Parameters:
l- the listener to add
-
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- Parameters:
l- the listener to add
-
setNodeMatcher
public void setNodeMatcher(NodeMatcher n)
Description copied from interface:DifferenceEngineSets the strategy for selecting nodes to compare.- Specified by:
setNodeMatcherin interfaceDifferenceEngine- Parameters:
n- the strategy to use
-
getNodeMatcher
protected NodeMatcher getNodeMatcher()
Provides access to the configured NodeMatcher.- Returns:
- the configured NodeMatcher
-
setDifferenceEvaluator
public void setDifferenceEvaluator(DifferenceEvaluator e)
Description copied from interface:DifferenceEngineEvaluates the severity of a difference.- Specified by:
setDifferenceEvaluatorin interfaceDifferenceEngine- Parameters:
e- the evaluator to use
-
getDifferenceEvaluator
protected DifferenceEvaluator getDifferenceEvaluator()
Provides access to the configured DifferenceEvaluator.- Returns:
- 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- Parameters:
c- the controller to use
-
getComparisonController
protected ComparisonController getComparisonController()
Provides access to the configured ComparisonController.- Returns:
- the configured ComparisonController
-
setNamespaceContext
public void setNamespaceContext(Map<String,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 Map<String,String> getNamespaceContext()
Provides access to the configured namespace context.- Returns:
- the configured namespace context
-
setAttributeFilter
public void setAttributeFilter(Predicate<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.Note that
NodeMatcherwill not by aware of the configured attribute filter and if its decision is based on attributes it will in general also consider attributes the filter would suppress.- Specified by:
setAttributeFilterin interfaceDifferenceEngine- Parameters:
af- the strategy to use
-
getAttributeFilter
protected Predicate<Attr> getAttributeFilter()
Provides access to the configured attribute filter.- Returns:
- the configured attribute filter
-
setNodeFilter
public void setNodeFilter(Predicate<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- Parameters:
nf- the strategy to use
-
getNodeFilter
protected Predicate<Node> getNodeFilter()
Provides access to the configured nod filter.- Returns:
- the configured node filter
-
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.- Parameters:
comp- the comparison to perform- Returns:
- the outcome as pair of result and a flag that says "stop the whole comparison process" when true.
-
getXPath
protected static String getXPath(XPathContext ctx)
Returns a string representation of the given XPathContext.- Parameters:
ctx- the XPathContext- Returns:
- a string representation of the given XPathContext
-
getParentXPath
protected static String getParentXPath(XPathContext ctx)
Returns a string representation of the given XPathContext's parent context.- Parameters:
ctx- the XPathContext- Returns:
- a string representation of the given XPathContext's parent context.
-
-