/** * Reduces the set of matched elements to those that match the selector. */ public Jerry filter(final String cssSelectors) { List<Node> result = new NodeList(nodes.length); if (nodes.length > 0) { for (Node node : nodes) { Node parentNode = node.getParentNode(); if (parentNode == null) { continue; } NodeSelector nodeSelector = createNodeSelector(parentNode); List<Node> selectedNodes = nodeSelector.select(cssSelectors); for (Node selected : selectedNodes) { if (node == selected) { result.add(node); } } } } return new Jerry(this, result); }
/** * Reduces the set of matched elements to the one at an index greater * than specified index. */ public Jerry gt(final int value) { List<Node> result = new NodeList(nodes.length); if (nodes.length > 0) { int index = 0; for (Node node : nodes) { if (index > value) { result.add(node); } index++; } } return new Jerry(this, result); }
/** * Gets the siblings of each element in the set of matched elements. */ public Jerry siblings() { List<Node> result = new NodeList(nodes.length); if (nodes.length > 0) { for (Node node : nodes) { Node[] allElements = node.getParentNode().getChildElements(); for (Node sibling : allElements) { if (sibling != node) { result.add(sibling); } } } } return new Jerry(this, result); }
/** * Reduces the set of matched elements to the one at an index greater * than specified index. */ public Jerry gt(int value) { List<Node> result = new NodeList(nodes.length); int index = 0; for (Node node : nodes) { if (index > value) { result.add(node); } index++; } return new Jerry(this, result); }
/** * Reduces the set of matched elements to the one at an index less * than specified index. */ public Jerry lt(int value) { List<Node> result = new NodeList(nodes.length); int index = 0; for (Node node : nodes) { if (index < value) { result.add(node); } index++; } return new Jerry(this, result); }
/** * Gets the siblings of each element in the set of matched elements. */ public Jerry siblings() { List<Node> result = new NodeList(nodes.length); for (Node node : nodes) { Node[] allElements = node.getParentNode().getChildElements(); for (Node sibling : allElements) { if (sibling != node) { result.add(sibling); } } } return new Jerry(this, result); }
/** * Removes elements from the set of matched elements. */ public Jerry not(final String cssSelector) { Node[] notNodes = root().find(cssSelector).nodes; List<Node> result = new NodeList(nodes.length); if (nodes.length > 0) { for (Node node : nodes) { if (!ArraysUtil.contains(notNodes, node)) { result.add(node); } } } return new Jerry(this, result); }
/** * Gets the descendants of each element in the current set of matched elements, * filtered by a selector. */ public Jerry find(final String cssSelector) { final List<Node> result = new NodeList(); if (nodes.length > 0) { for (Node node : nodes) { NodeSelector nodeSelector = createNodeSelector(node); List<Node> filteredNodes = nodeSelector.select(cssSelector); result.addAll(filteredNodes); } } return new Jerry(this, result); }
/** * Gets the parent of each element in the current set of matched elements. */ public Jerry parent() { List<Node> result = new NodeList(nodes.length); for (Node node : nodes) { result.add(node.getParentNode()); } return new Jerry(this, result); }
/** * Gets the immediately preceding sibling of each element in the * set of matched elements. */ public Jerry prev() { List<Node> result = new NodeList(nodes.length); if (nodes.length > 0) { for (Node node : nodes) { result.add(node.getPreviousSiblingElement()); } } return new Jerry(this, result); }
/** * Gets the immediately following sibling of each element in the * set of matched elements. */ public Jerry next() { List<Node> result = new NodeList(nodes.length); if (nodes.length > 0) { for (Node node : nodes) { result.add(node.getNextSiblingElement()); } } return new Jerry(this, result); }
/** * Gets the immediate children of each element in the set of matched elements. */ public Jerry children() { List<Node> result = new NodeList(nodes.length); if (nodes.length > 0) { for (Node node : nodes) { Node[] children = node.getChildElements(); Collections.addAll(result, children); } } return new Jerry(this, result); }
/** * Removes elements from the set of matched elements. */ public Jerry not(String cssSelector) { Node[] notNodes = root().find(cssSelector).nodes; List<Node> result = new NodeList(nodes.length); for (Node node : nodes) { if (ArraysUtil.contains(notNodes, node) == false) { result.add(node); } } return new Jerry(this, result); }
/** * Reduces the set of matched elements to the first in the set. */ public Jerry first() { List<Node> result = new NodeList(nodes.length); if (nodes.length > 0) { result.add(nodes[0]); } return new Jerry(this, result); }
/** * Gets the immediate children of each element in the set of matched elements. */ public Jerry children() { List<Node> result = new NodeList(nodes.length); for (Node node : nodes) { Node[] children = node.getChildElements(); Collections.addAll(result, children); } return new Jerry(this, result); }
/** * Reduces the set of matched elements to the first in the set. */ public Jerry first() { List<Node> result = new NodeList(nodes.length); if (nodes.length > 0) { result.add(nodes[0]); } return new Jerry(this, result); }
/** * Gets the immediately preceding sibling of each element in the * set of matched elements. */ public Jerry prev() { List<Node> result = new NodeList(nodes.length); for (Node node : nodes) { result.add(node.getPreviousSiblingElement()); } return new Jerry(this, result); }
/** * Gets the immediately following sibling of each element in the * set of matched elements. */ public Jerry next() { List<Node> result = new NodeList(nodes.length); for (Node node : nodes) { result.add(node.getNextSiblingElement()); } return new Jerry(this, result); }
/** * Get the children of each element in the set of matched elements, * including text and comment nodes. */ public Jerry contents() { List<Node> result = new NodeList(nodes.length); if (nodes.length > 0) { for (Node node : nodes) { Node[] contents = node.getChildNodes(); Collections.addAll(result, contents); } } return new Jerry(this, result); }
/** * Gets the descendants of each element in the current set of matched elements, * filtered by a selector. */ public Jerry find(String cssSelector) { final List<Node> result = new NodeList(); for (Node node : nodes) { NodeSelector nodeSelector = createNodeSelector(node); List<Node> filteredNodes = nodeSelector.select(cssSelector); result.addAll(filteredNodes); } return new Jerry(this, result); }