@Test public void elementSelectorsAreQueriedInSequenceWithConditionalSelector() { Element control1 = doc.createElement("a"); control1.appendChild(doc.createTextNode("foo")); Element control2 = doc.createElement("a"); control2.appendChild(doc.createTextNode("bar")); Element test1 = doc.createElement("a"); test1.appendChild(doc.createTextNode("baz")); Element test2 = doc.createElement("a"); test2.appendChild(doc.createTextNode("foo")); DefaultNodeMatcher m = new DefaultNodeMatcher(ElementSelectors.selectorForElementNamed("a", ElementSelectors.byNameAndText), ElementSelectors.byName); List<Map.Entry<Node, Node>> result = Linqy.asList(m.match(Arrays.<Node>asList(control1, control2), Arrays.<Node>asList(test1, test2))); assertEquals(2, result.size()); assertSame(control1, result.get(0).getKey()); assertSame(test2, result.get(0).getValue()); assertSame(control2, result.get(1).getKey()); assertSame(test1, result.get(1).getValue()); }
@Override public Iterable<Map.Entry<Node, Node>> match(Iterable<Node> controlNodes, Iterable<Node> testNodes) { Map<Node, Node> matches = new LinkedHashMap<Node, Node>(); List<Node> controlList = Linqy.asList(controlNodes); List<Node> testList = Linqy.asList(testNodes); final int testSize = testList.size(); Set<Integer> unmatchedTestIndexes = new HashSet<Integer>(); for (int i = 0; i < testSize; i++) { unmatchedTestIndexes.add(Integer.valueOf(i)); } final int controlSize = controlList.size(); Set<Integer> unmatchedControlIndexes = new HashSet<Integer>(); for (int i = 0; i < controlSize; i++) { unmatchedControlIndexes.add(Integer.valueOf(i)); } for (ElementSelector e : elementSelectors) { Match lastMatch = new Match(null, -1); for (int i = 0; i < controlSize; i++) { if (!unmatchedControlIndexes.contains(Integer.valueOf(i))) { continue; } Node control = controlList.get(i); Match testMatch = findMatchingNode(control, testList, lastMatch.index, unmatchedTestIndexes, e); if (testMatch != null) { unmatchedControlIndexes.remove(Integer.valueOf(i)); unmatchedTestIndexes.remove(testMatch.index); matches.put(control, testMatch.node); } } } return matches.entrySet(); }
DefaultNodeMatcher implements NodeMatcher { @Override public Iterable<Map.Entry<Node, Node>> match(Iterable<Node> controlNodes, Iterable<Node> testNodes) { Map<Node, Node> matches = new LinkedHashMap<Node, Node>(); List<Node> controlList = Linqy.asList(controlNodes); List<Node> testList = Linqy.asList(testNodes); final int testSize = testList.size(); Set<Integer> unmatchedTestIndexes = new HashSet<Integer>(); for (int i = 0; i < testSize; i++) { unmatchedTestIndexes.add(Integer.valueOf(i)); } final int controlSize = controlList.size(); Set<Integer> unmatchedControlIndexes = new HashSet<Integer>(); for (int i = 0; i < controlSize; i++) { unmatchedControlIndexes.add(Integer.valueOf(i)); } for (ElementSelector e : elementSelectors) { Match lastMatch = new Match(null, -1); for (int i = 0; i < controlSize; i++) { if (!unmatchedControlIndexes.contains(Integer.valueOf(i))) { continue; } Node control = controlList.get(i); Match testMatch = findMatchingNode(control, testList, lastMatch.index, unmatchedTestIndexes, e); if (testMatch != null) { unmatchedControlIndexes.remove(Integer.valueOf(i)); unmatchedTestIndexes.remove(testMatch.index); matches.put(control, testMatch.node); } } } return matches.entrySet(); } }
DefaultNodeMatcher implements NodeMatcher { @Override public Iterable<Map.Entry<Node, Node>> match(Iterable<Node> controlNodes, Iterable<Node> testNodes) { Map<Node, Node> matches = new LinkedHashMap<Node, Node>(); List<Node> controlList = Linqy.asList(controlNodes); List<Node> testList = Linqy.asList(testNodes); final int testSize = testList.size(); Set<Integer> unmatchedTestIndexes = new HashSet<Integer>(); for (int i = 0; i < testSize; i++) { unmatchedTestIndexes.add(Integer.valueOf(i)); } final int controlSize = controlList.size(); Set<Integer> unmatchedControlIndexes = new HashSet<Integer>(); for (int i = 0; i < controlSize; i++) { unmatchedControlIndexes.add(Integer.valueOf(i)); } for (ElementSelector e : elementSelectors) { Match lastMatch = new Match(null, -1); for (int i = 0; i < controlSize; i++) { if (!unmatchedControlIndexes.contains(Integer.valueOf(i))) { continue; } Node control = controlList.get(i); Match testMatch = findMatchingNode(control, testList, lastMatch.index, unmatchedTestIndexes, e); if (testMatch != null) { unmatchedControlIndexes.remove(Integer.valueOf(i)); unmatchedTestIndexes.remove(testMatch.index); matches.put(control, testMatch.node); } } } return matches.entrySet(); } DefaultNodeMatcher();  DefaultNodeMatcher(ElementSelector... es);  DefaultNodeMatcher(NodeTypeMatcher ntm, ElementSelector... es); }
DefaultNodeMatcher implements NodeMatcher { @Override public Iterable<Map.Entry<Node, Node>> match(Iterable<Node> controlNodes, Iterable<Node> testNodes) { Map<Node, Node> matches = new LinkedHashMap<Node, Node>(); List<Node> controlList = Linqy.asList(controlNodes); List<Node> testList = Linqy.asList(testNodes); final int testSize = testList.size(); Set<Integer> unmatchedTestIndexes = new HashSet<Integer>(); for (int i = 0; i < testSize; i++) { unmatchedTestIndexes.add(Integer.valueOf(i)); } final int controlSize = controlList.size(); Set<Integer> unmatchedControlIndexes = new HashSet<Integer>(); for (int i = 0; i < controlSize; i++) { unmatchedControlIndexes.add(Integer.valueOf(i)); } for (ElementSelector e : elementSelectors) { Match lastMatch = new Match(null, -1); for (int i = 0; i < controlSize; i++) { if (!unmatchedControlIndexes.contains(Integer.valueOf(i))) { continue; } Node control = controlList.get(i); Match testMatch = findMatchingNode(control, testList, lastMatch.index, unmatchedTestIndexes, e); if (testMatch != null) { unmatchedControlIndexes.remove(Integer.valueOf(i)); unmatchedTestIndexes.remove(testMatch.index); matches.put(control, testMatch.node); } } } return matches.entrySet(); } DefaultNodeMatcher();  DefaultNodeMatcher(ElementSelector... es);  DefaultNodeMatcher(NodeTypeMatcher ntm, ElementSelector... es); @Override Iterable<Map.Entry<Node, Node>> match(Iterable<Node> controlNodes,
                                                 Iterable<Node> testNodes); }
DefaultNodeMatcher implements NodeMatcher { @Override public Iterable<Map.Entry<Node, Node>> match(Iterable<Node> controlNodes, Iterable<Node> testNodes) { Map<Node, Node> matches = new LinkedHashMap<Node, Node>(); List<Node> controlList = Linqy.asList(controlNodes); List<Node> testList = Linqy.asList(testNodes); final int testSize = testList.size(); Set<Integer> unmatchedTestIndexes = new HashSet<Integer>(); for (int i = 0; i < testSize; i++) { unmatchedTestIndexes.add(Integer.valueOf(i)); } final int controlSize = controlList.size(); Set<Integer> unmatchedControlIndexes = new HashSet<Integer>(); for (int i = 0; i < controlSize; i++) { unmatchedControlIndexes.add(Integer.valueOf(i)); } for (ElementSelector e : elementSelectors) { Match lastMatch = new Match(null, -1); for (int i = 0; i < controlSize; i++) { if (!unmatchedControlIndexes.contains(Integer.valueOf(i))) { continue; } Node control = controlList.get(i); Match testMatch = findMatchingNode(control, testList, lastMatch.index, unmatchedTestIndexes, e); if (testMatch != null) { unmatchedControlIndexes.remove(Integer.valueOf(i)); unmatchedTestIndexes.remove(testMatch.index); matches.put(control, testMatch.node); } } } return matches.entrySet(); } DefaultNodeMatcher();  DefaultNodeMatcher(ElementSelector... es);  DefaultNodeMatcher(NodeTypeMatcher ntm, ElementSelector... es); @Override Iterable<Map.Entry<Node, Node>> match(Iterable<Node> controlNodes,
                                                 Iterable<Node> testNodes);  }