Class DefaultNodeMatcher
- java.lang.Object
-
- org.xmlunit.diff.DefaultNodeMatcher
-
- All Implemented Interfaces:
NodeMatcher
public class DefaultNodeMatcher extends java.lang.Object implements NodeMatcher
Default implemetation ofNodeMatcherthat matches control and tests nodes for comparison with the help ofDefaultNodeMatcher.NodeTypeMatcherandElementSelectors.There is an important difference between using
ElementSelectors.or(org.xmlunit.diff.ElementSelector...)to combine multipleElementSelectors and usingDefaultNodeMatcher's constructor with multipleElementSelectors:Consider
ElementSelectorse1ande2and two control and test nodes each. Assumee1would match the first control node to the second test node and vice versa if used alone, whilee2would match the nodes in order (the first control node to the first test and so on).ElementSelectors.or(org.xmlunit.diff.ElementSelector...)creates a combinedElementSelectorthat 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 runninge2alone.DefaultNodeMatcherwith twoElementSelectors will consult theElementSelectors separately and only invokee2if there are any nodes not matched bye1at all. In this case the result will be the same as runninge1alone.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classDefaultNodeMatcher.DefaultNodeTypeMatcherDefaultNodeMatcher.NodeTypeMatcherthat marks pairs of nodes of the same node type as well as pairs of CDATA sections and text nodes as eligible.private static classDefaultNodeMatcher.Matchstatic interfaceDefaultNodeMatcher.NodeTypeMatcherDetermines whether two Nodes are eligible for comparison based on their node type.
-
Field Summary
Fields Modifier and Type Field Description private static shortCDATAprivate ElementSelector[]elementSelectorsprivate DefaultNodeMatcher.NodeTypeMatchernodeTypeMatcherprivate static shortTEXT
-
Constructor Summary
Constructors Constructor Description DefaultNodeMatcher()Creates a matcher usingElementSelectors.DefaultandDefaultNodeMatcher.DefaultNodeTypeMatcher.DefaultNodeMatcher(DefaultNodeMatcher.NodeTypeMatcher ntm, ElementSelector... es)Creates a matcher using the givenElementSelectors andDefaultNodeMatcher.NodeTypeMatcher.DefaultNodeMatcher(ElementSelector... es)Creates a matcher using the givenElementSelectors andDefaultNodeMatcher.DefaultNodeTypeMatcher.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private DefaultNodeMatcher.MatchfindMatchingNode(org.w3c.dom.Node searchFor, java.util.List<org.w3c.dom.Node> searchIn, int indexOfLastMatch, java.util.Set<java.lang.Integer> availableIndexes, ElementSelector e)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 booleannodesMatch(org.w3c.dom.Node n1, org.w3c.dom.Node n2, ElementSelector elementSelector)private DefaultNodeMatcher.MatchsearchIn(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.DefaultandDefaultNodeMatcher.DefaultNodeTypeMatcher.
-
DefaultNodeMatcher
public DefaultNodeMatcher(ElementSelector... es)
Creates a matcher using the givenElementSelectors andDefaultNodeMatcher.DefaultNodeTypeMatcher.
-
DefaultNodeMatcher
public DefaultNodeMatcher(DefaultNodeMatcher.NodeTypeMatcher ntm, ElementSelector... es)
Creates a matcher using the givenElementSelectors andDefaultNodeMatcher.NodeTypeMatcher.The
ElementSelectors are consulted in order so that the secondElementSelectoronly 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:NodeMatcherMatches 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_LOOKUPdifferences}.- Specified by:
matchin 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, ElementSelector e)
-
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)
-
-