Class NodeUtil

java.lang.Object
org.broadleafcommerce.common.util.NodeUtil

public class NodeUtil extends Object
An API for w3c.Nodes manipulation
Author:
gdiaz
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static 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
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • NodeUtil

      public NodeUtil()
  • Method Details

    • filterByAttribute

      public 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
      Parameters:
      primaryNodes - the original array of nodes. All nodes are assumed to at least have attributes
      attributeName - the attribute name
      Returns:
    • findNode

      public 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
      Parameters:
      arrNodes - the haystack
      testNode - the needle
      attributeName - the attribute used for comparison
      sortArray - 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 appended
      list1 - the original list to merge
      list2 - the second list to merge which will overwrite values from list1
      attributeName -