/** * Reduces the set of matched elements to the last in the set. */ public Jerry last() { List<Node> result = new NodeList(nodes.length); if (nodes.length > 0) { result.add(nodes[nodes.length - 1]); } 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); }
/** * Reduces the set of matched elements to the one at an index less * than specified index. */ public Jerry lt(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); }
/** * Reduces the set of matched elements to the last in the set. */ public Jerry last() { List<Node> result = new NodeList(nodes.length); if (nodes.length > 0) { result.add(nodes[nodes.length - 1]); } 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); if (nodes.length > 0) { for (Node node : nodes) { result.add(node.getParentNode()); } } return new Jerry(this, result); }
/** * 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 the specified index. */ public Jerry eq(final int value) { List<Node> result = new NodeList(1); int matchingIndex = value >= 0 ? value : nodes.length + value; if (nodes.length > 0) { int index = 0; for (Node node : nodes) { if (index == matchingIndex) { result.add(node); break; } index++; } } return new Jerry(this, result); }
/** * Reduce the set of matched elements to those that have a descendant that * matches the selector or DOM element. */ public Jerry has(final String cssSelectors) { List<Node> result = new NodeList(nodes.length); if (nodes.length > 0) { for (Node node : nodes) { NodeSelector nodeSelector = createNodeSelector(node); List<Node> selectedNodes = nodeSelector.select(cssSelectors); if (!selectedNodes.isEmpty()) { result.add(node); } } } return new Jerry(this, result); }
/** * Reduces the set of matched elements to those that pass the * {@link JerryFunction function's} test. */ public Jerry filter(final JerryFunction jerryFunction) { List<Node> result = new NodeList(nodes.length); for (int i = 0; i < nodes.length; i++) { Node node = nodes[i]; Node parentNode = node.getParentNode(); if (parentNode == null) { continue; } Jerry $this = new Jerry(this, node); boolean accept = jerryFunction.onNode($this, i); if (accept) { result.add(node); } } return new Jerry(this, result); }
/** * Get all preceding siblings of each element in the set of matched * elements, optionally filtered by a selector. */ public Jerry prevAll() { List<Node> result = new NodeList(nodes.length); if (nodes.length > 0) { for (Node node : nodes) { Node currentSiblingElement = node.getPreviousSiblingElement(); while (currentSiblingElement != null) { result.add(currentSiblingElement); currentSiblingElement = currentSiblingElement.getPreviousSiblingElement(); } } } 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); }
/** * Get all following siblings of each element in the set of matched * elements, optionally filtered by a selector. */ public Jerry nextAll() { List<Node> result = new NodeList(nodes.length); if (nodes.length > 0) { for (Node node : nodes) { Node currentSiblingElement = node.getNextSiblingElement(); while (currentSiblingElement != null) { result.add(currentSiblingElement); currentSiblingElement = currentSiblingElement.getNextSiblingElement(); } } } 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); }
/** * 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); }
/** * 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 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 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 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); }
/** * Gets the parent of each element in the current set of matched elements. */ public Jerry parent() { List<Node> result = new NodeList(nodes.length); if (nodes.length > 0) { for (Node node : nodes) { result.add(node.getParentNode()); } } return new Jerry(this, result); }