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.
  • Field Details

  • Constructor Details

    • AbstractDifferenceEngine

      protected AbstractDifferenceEngine()
  • Method Details

    • addComparisonListener

      public void addComparisonListener(ComparisonListener l)
      Description copied from interface: DifferenceEngine
      Registers a listener that is notified of each comparison.
      Specified by:
      addComparisonListener in interface DifferenceEngine
    • addMatchListener

      public void addMatchListener(ComparisonListener l)
      Description copied from interface: DifferenceEngine
      Registers a listener that is notified of each comparison with outcome ComparisonResult.EQUAL.
      Specified by:
      addMatchListener in interface DifferenceEngine
    • addDifferenceListener

      public void addDifferenceListener(ComparisonListener l)
      Description copied from interface: DifferenceEngine
      Registers a listener that is notified of each comparison with outcome other than ComparisonResult.EQUAL.
      Specified by:
      addDifferenceListener in interface DifferenceEngine
    • setNodeMatcher

      public void setNodeMatcher(NodeMatcher n)
      Description copied from interface: DifferenceEngine
      Sets the strategy for selecting nodes to compare.
      Specified by:
      setNodeMatcher in interface DifferenceEngine
    • 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 interface DifferenceEngine
    • 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 interface DifferenceEngine
    • getComparisonController

      protected ComparisonController getComparisonController()
      Provides access to the configured ComparisonController.
    • setNamespaceContext

      public void setNamespaceContext(Map<String,String> prefix2uri)
      Description copied from interface: DifferenceEngine
      Establish a namespace context that will be used in Comparison.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 interface DifferenceEngine
      Parameters:
      prefix2uri - maps from prefix to namespace URI.
    • getNamespaceContext

      protected Map<String,String> getNamespaceContext()
      Provides access to the configured namespace context.
    • setAttributeFilter

      public void setAttributeFilter(Predicate<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 interface DifferenceEngine
    • getAttributeFilter

      protected Predicate<Attr> getAttributeFilter()
      Provides access to the configured ComparisonController.
    • setNodeFilter

      public void setNodeFilter(Predicate<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 interface DifferenceEngine
    • getNodeFilter

      protected Predicate<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 String getXPath(XPathContext ctx)
      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.