clazz) {
+ return childNodes.stream()
+ .filter(clazz::isInstance)
+ .map(clazz::cast)
+ .collect(Collectors.collectingAndThen(Collectors.toList(), Collections::unmodifiableList));
+ }
+
/**
* Get this element's child text nodes. The list is unmodifiable but the text nodes may be manipulated.
*
@@ -428,12 +436,7 @@ public Stream stream() {
*
*/
public List textNodes() {
- List textNodes = new ArrayList<>();
- for (Node node : childNodes) {
- if (node instanceof TextNode)
- textNodes.add((TextNode) node);
- }
- return Collections.unmodifiableList(textNodes);
+ return filterNodes(TextNode.class);
}
/**
@@ -446,12 +449,7 @@ public List textNodes() {
* @see #data()
*/
public List dataNodes() {
- List dataNodes = new ArrayList<>();
- for (Node node : childNodes) {
- if (node instanceof DataNode)
- dataNodes.add((DataNode) node);
- }
- return Collections.unmodifiableList(dataNodes);
+ return filterNodes(DataNode.class);
}
/**