Package org.dlese.dpc.xml
Class Dom4jNodeListComparator
java.lang.Object
org.dlese.dpc.xml.Dom4jNodeListComparator
- All Implemented Interfaces:
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
FieldsModifier and TypeFieldDescriptionstatic final intSort ascending.static final intSort descending. -
Constructor Summary
ConstructorsConstructorDescriptionDom4jNodeListComparator(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
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.Comparator
equals, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
-
Field Details
-
ASCENDING
public static final int ASCENDINGSort ascending.- See Also:
-
DESCENDING
public static final int DESCENDINGSort descending.- See Also:
-
-
Constructor Details
-
Dom4jNodeListComparator
Constructor that allows setting the sort order by ascending or descending.- Parameters:
xPath- An xPath relative to the node rootsortOrder- The order for sorting (ASCENDING or DESCENDING)- See Also:
-
Dom4jNodeListComparator
Default constructor that sorts descending.- Parameters:
xPath- An xPath relative to the node root
-
-
Method Details
-
compare
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:
comparein interfaceComparator- Parameters:
o1- The first Object.o2- The second Object.- Returns:
- An int indicating sort order.
-