Class NodeUtil
java.lang.Object
org.broadleafcommerce.common.util.NodeUtil
An API for w3c.Nodes manipulation
- Author:
- gdiaz
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Node[]
filterByAttribute
(Node[] primaryNodes, String attributeName) given an array of nodes, returns a subarray containing only those nodes having a non-null specified attributestatic int
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 methodstatic 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.
-
Constructor Details
-
NodeUtil
public NodeUtil()
-
-
Method Details
-
filterByAttribute
given an array of nodes, returns a subarray containing only those nodes having a non-null specified attribute- Parameters:
primaryNodes
- the original array of nodes. All nodes are assumed to at least have attributesattributeName
- the attribute name- Returns:
-
findNode
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- Parameters:
arrNodes
- the haystacktestNode
- the needleattributeName
- the attribute used for comparisonsortArray
- true if the array needs to be sorted, false if it comes already sorted- Returns:
-
mergeNodeLists
public 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. They can be null. They are not assumed to be sorted.- Parameters:
targetNode
- 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 list1attributeName
-
-