*/
private Set<Node> check(List<Selector> parts) throws NodeSelectorException {
Set<Node> result = new LinkedHashSet<Node>();
result.add(root);
for (Selector selector : parts) {
NodeTraversalChecker checker = new TagChecker(selector);
result = checker.check(result, root);
if (selector.hasSpecifiers()) {
for (Specifier specifier : selector.getSpecifiers()) {
switch (specifier.getType()) {
case ATTRIBUTE:
checker = new AttributeSpecifierChecker((AttributeSpecifier) specifier);
break;
case PSEUDO:
if (specifier instanceof PseudoClassSpecifier) {
checker = new PseudoClassSpecifierChecker((PseudoClassSpecifier) specifier);
} else if (specifier instanceof PseudoNthSpecifier) {
checker = new PseudoNthSpecifierChecker((PseudoNthSpecifier) specifier);
}
break;
case NEGATION:
final Set<Node> negationNodes = checkNegationSpecifier((NegationSpecifier) specifier);
checker = new NodeTraversalChecker() {
@Override
public Set<Node> check(Set<Node> nodes, Node root) throws NodeSelectorException {
Set<Node> set = new LinkedHashSet<Node>(nodes);
set.removeAll(negationNodes);
return set;
}
};
break;
}
result = checker.check(result, root);
if (result.isEmpty()) {
// Bail out early.
return result;
}
}