/** * @param element * Must not be null. * @return If the given element has any child elements, return an optional containing the first child element. * Otherwise return an empty optional. */ public static Optional<Element> getFirstChildElement(final Element element) { for (final Node child : nodeIterable(element.getChildNodes())) { if (isElement(child)) { return Optional.ofNullable((Element) child); } } return Optional.empty(); }
/** * @param element * Must not be null. * @return If the given element has any child elements, return an optional containing the first child element. * Otherwise return an empty optional. */ public static Optional<Element> getFirstChildElement(final Element element) { for (final Node child : nodeIterable(element.getChildNodes())) { if (isElement(child)) { return Optional.ofNullable((Element) child); } } return Optional.empty(); }
@Override public boolean hasNext() { while (i < nodeList.getLength() && !isElement(nodeList.item(i))) { i++; } return i < nodeList.getLength(); }
/** * @param element * Must not be null. * @return If the given element has any child elements, return an optional containing the last child element. * Otherwise return an empty optional. */ public static Optional<Element> getLastChildElement(final Element element) { final NodeList children = element.getChildNodes(); for (int i = children.getLength()-1; i > -1; i--) { if (isElement(children.item(i))) { return Optional.ofNullable((Element) children.item(i)); } } return Optional.empty(); }
/** * @param element * Must not be null. * @return If the given element has any child elements, return an optional containing the last child element. * Otherwise return an empty optional. */ public static Optional<Element> getLastChildElement(final Element element) { final NodeList children = element.getChildNodes(); for (int i = children.getLength()-1; i > -1; i--) { if (isElement(children.item(i))) { return Optional.ofNullable((Element) children.item(i)); } } return Optional.empty(); }
@Override public boolean hasNext() { while (i < nodeList.getLength() && !isElement(nodeList.item(i))) { i++; } return i < nodeList.getLength(); }