Class Dom4jNodeListComparator

java.lang.Object
org.dlese.dpc.xml.Dom4jNodeListComparator
All Implemented Interfaces:
Comparator

public class Dom4jNodeListComparator extends Object implements Comparator
Compares two dom4j nodes using an xPath. Note that a dom4j Node List can be sorted using the native method: List sortedList = document.selectNodes("/ListSets/set","setName");
Version:
$Id: Dom4jNodeListComparator.java,v 1.2 2009/03/20 23:34:01 jweather Exp $
Author:
John Weatherley
  • Field Details

  • Constructor Details

    • Dom4jNodeListComparator

      public Dom4jNodeListComparator(String xPath, int sortOrder)
      Constructor that allows setting the sort order by ascending or descending.
      Parameters:
      xPath - An xPath relative to the node root
      sortOrder - The order for sorting (ASCENDING or DESCENDING)
      See Also:
    • Dom4jNodeListComparator

      public Dom4jNodeListComparator(String xPath)
      Default constructor that sorts descending.
      Parameters:
      xPath - An xPath relative to the node root
  • Method Details

    • compare

      public int compare(Object o1, Object o2)
      Compares two dom4j Nodes for sorting by an xPath.

      Compares its two arguments for order. Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

      Specified by:
      compare in interface Comparator
      Parameters:
      o1 - The first Object.
      o2 - The second Object.
      Returns:
      An int indicating sort order.