DLESE Tools
v1.6.0

org.dlese.dpc.xml
Class Dom4jNodeListComparator

java.lang.Object
  extended by 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 Summary
static int ASCENDING
          Sort ascending.
static int DESCENDING
          Sort descending.
 
Constructor Summary
Dom4jNodeListComparator(String xPath)
          Default constructor that sorts descending.
Dom4jNodeListComparator(String xPath, int sortOrder)
          Constructor that allows setting the sort order by ascending or descending.
 
Method Summary
 int compare(Object o1, Object o2)
          Compares two dom4j Nodes for sorting by an xPath.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.Comparator
equals
 

Field Detail

ASCENDING

public static final int ASCENDING
Sort ascending.

See Also:
Constant Field Values

DESCENDING

public static final int DESCENDING
Sort descending.

See Also:
Constant Field Values
Constructor Detail

Dom4jNodeListComparator

public Dom4jNodeListComparator(String xPath,
                               int sortOrder)
Constructor that allows setting the sort order by ascending or descending.

Parameters:
sortOrder - The order for sorting (ASCENDING or DESCENDING)
xPath - An xPath relative to the node root
See Also:
ASCENDING, DESCENDING

Dom4jNodeListComparator

public Dom4jNodeListComparator(String xPath)
Default constructor that sorts descending.

Parameters:
xPath - An xPath relative to the node root
Method Detail

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.

DLESE Tools
v1.6.0