/** * Invokes parsing on {@link DOMBuilder}. */ public Jerry parse(String content) { if (content == null) { content = StringPool.EMPTY; } Document doc = domBuilder.parse(content); return new Jerry(domBuilder, doc); } }
/** * Invokes parsing on {@link DOMBuilder}. */ public Jerry parse(final char[] content) { Document doc = domBuilder.parse(content); return new Jerry(domBuilder, doc); }
/** * 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 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); }
/** * Iterates over a jQuery object, executing a function for * each matched element. * @see #eachNode(JerryNodeFunction) */ public Jerry each(final JerryFunction function) { for (int i = 0; i < nodes.length; i++) { Node node = nodes[i]; Jerry $this = new Jerry(this, node); Boolean result = function.onNode($this, i); if (result != null && result == Boolean.FALSE) { break; } } return this; }
/** * 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); }
/** * 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); }
/** * 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); }
@Override public Jerry next() { if (!hasNext()) { throw new NoSuchElementException(); } Jerry nextJerry = new Jerry(jerry, jerry.get(index)); index++; return nextJerry; }
/** * 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 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); }
/** * 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 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); }
/** * Adds elements to the set of matched elements. */ public Jerry add(final String selector) { return new Jerry(this, nodes, root().find(selector).nodes); }
/** * 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 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); }
/** * 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 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); }
/** * 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); }