public class NodeUtil extends Object
| Modifier and Type | Class and Description |
|---|---|
static class |
NodeUtil.NodeComparatorBySingleAttribute
a simple implementation of the Comparator interface, (applied to the Node class) that uses the value of a given
node attribute as comparison criterion.
|
| Constructor and Description |
|---|
NodeUtil() |
| Modifier and Type | Method and Description |
|---|---|
static Node[] |
filterByAttribute(Node[] primaryNodes,
String attributeName)
given an array of nodes, returns a subarray containing only those nodes having a non-null specified attribute
|
static int |
findNode(Node[] arrNodes,
Node testNode,
String attributeName,
boolean sortArray)
tries to find a test Node within an array of nodes
The array is assumed sorted according to a custom comparator by single attribute, but if can be optionally sorted inside the method
|
static void |
mergeNodeLists(Node targetNode,
NodeList list1,
NodeList list2,
String attributeName)
creates a sorted list of nodes, with the merged nodes of 2 NodeLists
The comparison criteria is a single-attribute comparator, whose attribute name is also given as a parameter
The original NodeLists are not modified.
|
public static Node[] filterByAttribute(Node[] primaryNodes, String attributeName)
primaryNodes - the original array of nodes. All nodes are assumed to at least have attributesattributeName - the attribute namepublic static int findNode(Node[] arrNodes, Node testNode, String attributeName, boolean sortArray)
arrNodes - the haystacktestNode - the needleattribute - the attribute used for comparisonsortArray - true if the array needs to be sorted, false if it comes already sortedpublic static void mergeNodeLists(Node targetNode, NodeList list1, NodeList list2, String attributeName)
Node - the target node (assumed childless, and within the same document) to which the merged children will be appendedlist1 - the original list to mergelist2 - the second list to merge which will overwrite values from list1attribute - Copyright © 2019. All rights reserved.