Class DefaultNodeMatcher
- java.lang.Object
-
- org.xmlunit.diff.DefaultNodeMatcher
-
- All Implemented Interfaces:
NodeMatcher
public class DefaultNodeMatcher extends java.lang.Object implements NodeMatcher
Default implemetation ofNodeMatcher
that matches control and tests nodes for comparison with the help ofDefaultNodeMatcher.NodeTypeMatcher
andElementSelector
s.There is an important difference between using
ElementSelectors.or(org.xmlunit.diff.ElementSelector...)
to combine multipleElementSelector
s and usingDefaultNodeMatcher
's constructor with multipleElementSelector
s:Consider
ElementSelector
se1
ande2
and two control and test nodes each. Assumee1
would match the first control node to the second test node and vice versa if used alone, whilee2
would match the nodes in order (the first control node to the first test and so on).ElementSelectors.or(org.xmlunit.diff.ElementSelector...)
creates a combinedElementSelector
that is willing to match the first control node to both of the test nodes - and the same for the second control node. Since nodes are compared in order when possible the result will be the same as runninge2
alone.DefaultNodeMatcher
with twoElementSelector
s will consult theElementSelector
s separately and only invokee2
if there are any nodes not matched bye1
at all. In this case the result will be the same as runninge1
alone.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
DefaultNodeMatcher.DefaultNodeTypeMatcher
DefaultNodeMatcher.NodeTypeMatcher
that marks pairs of nodes of the same node type as well as pairs of CDATA sections and text nodes as eligible.private static class
DefaultNodeMatcher.Match
static interface
DefaultNodeMatcher.NodeTypeMatcher
Determines whether two Nodes are eligible for comparison based on their node type.
-
Field Summary
Fields Modifier and Type Field Description private static short
CDATA
private ElementSelector[]
elementSelectors
private DefaultNodeMatcher.NodeTypeMatcher
nodeTypeMatcher
private static short
TEXT
-
Constructor Summary
Constructors Constructor Description DefaultNodeMatcher()
Creates a matcher usingElementSelectors.Default
andDefaultNodeMatcher.DefaultNodeTypeMatcher
.DefaultNodeMatcher(DefaultNodeMatcher.NodeTypeMatcher ntm, ElementSelector... es)
Creates a matcher using the givenElementSelector
s andDefaultNodeMatcher.NodeTypeMatcher
.DefaultNodeMatcher(ElementSelector... es)
Creates a matcher using the givenElementSelector
s andDefaultNodeMatcher.DefaultNodeTypeMatcher
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private DefaultNodeMatcher.Match
findMatchingNode(org.w3c.dom.Node searchFor, java.util.List<org.w3c.dom.Node> searchIn, int indexOfLastMatch, java.util.Set<java.lang.Integer> availableIndexes)
java.lang.Iterable<java.util.Map.Entry<org.w3c.dom.Node,org.w3c.dom.Node>>
match(java.lang.Iterable<org.w3c.dom.Node> controlNodes, java.lang.Iterable<org.w3c.dom.Node> testNodes)
Matches control and test nodes against each other, returns the matching pairs.private boolean
nodesMatch(org.w3c.dom.Node n1, org.w3c.dom.Node n2, ElementSelector elementSelector)
private DefaultNodeMatcher.Match
searchIn(org.w3c.dom.Node searchFor, java.util.List<org.w3c.dom.Node> searchIn, java.util.Set<java.lang.Integer> availableIndexes, int fromInclusive, int toExclusive)
private DefaultNodeMatcher.Match
searchIn(org.w3c.dom.Node searchFor, java.util.List<org.w3c.dom.Node> searchIn, java.util.Set<java.lang.Integer> availableIndexes, int fromInclusive, int toExclusive, ElementSelector e)
-
-
-
Field Detail
-
TEXT
private static final short TEXT
- See Also:
- Constant Field Values
-
CDATA
private static final short CDATA
- See Also:
- Constant Field Values
-
elementSelectors
private final ElementSelector[] elementSelectors
-
nodeTypeMatcher
private final DefaultNodeMatcher.NodeTypeMatcher nodeTypeMatcher
-
-
Constructor Detail
-
DefaultNodeMatcher
public DefaultNodeMatcher()
Creates a matcher usingElementSelectors.Default
andDefaultNodeMatcher.DefaultNodeTypeMatcher
.
-
DefaultNodeMatcher
public DefaultNodeMatcher(ElementSelector... es)
Creates a matcher using the givenElementSelector
s andDefaultNodeMatcher.DefaultNodeTypeMatcher
.
-
DefaultNodeMatcher
public DefaultNodeMatcher(DefaultNodeMatcher.NodeTypeMatcher ntm, ElementSelector... es)
Creates a matcher using the givenElementSelector
s andDefaultNodeMatcher.NodeTypeMatcher
.The
ElementSelector
s are consulted in order so that the secondElementSelector
only gets to match the nodes that the first one couldn't match to any test nodes ate all and so on.
-
-
Method Detail
-
match
public java.lang.Iterable<java.util.Map.Entry<org.w3c.dom.Node,org.w3c.dom.Node>> match(java.lang.Iterable<org.w3c.dom.Node> controlNodes, java.lang.Iterable<org.w3c.dom.Node> testNodes)
Description copied from interface:NodeMatcher
Matches control and test nodes against each other, returns the matching pairs.Nodes passed in as attributes but not returned as member of any pair will cause
ComparisonType.CHILD_LOOKUP
differences}.- Specified by:
match
in interfaceNodeMatcher
-
findMatchingNode
private DefaultNodeMatcher.Match findMatchingNode(org.w3c.dom.Node searchFor, java.util.List<org.w3c.dom.Node> searchIn, int indexOfLastMatch, java.util.Set<java.lang.Integer> availableIndexes)
-
searchIn
private DefaultNodeMatcher.Match searchIn(org.w3c.dom.Node searchFor, java.util.List<org.w3c.dom.Node> searchIn, java.util.Set<java.lang.Integer> availableIndexes, int fromInclusive, int toExclusive)
-
searchIn
private DefaultNodeMatcher.Match searchIn(org.w3c.dom.Node searchFor, java.util.List<org.w3c.dom.Node> searchIn, java.util.Set<java.lang.Integer> availableIndexes, int fromInclusive, int toExclusive, ElementSelector e)
-
nodesMatch
private boolean nodesMatch(org.w3c.dom.Node n1, org.w3c.dom.Node n2, ElementSelector elementSelector)
-
-