com.taleo.integration.client.customstep.util.csv
Class HierarchicalRowComparator

java.lang.Object
  extended by com.taleo.integration.client.customstep.util.csv.HierarchicalRowComparator
All Implemented Interfaces:
java.util.Comparator

public class HierarchicalRowComparator
extends java.lang.Object
implements java.util.Comparator

Comparator to sort CSV rows in hierarchical order (parent/child). Rows are of type String[].

Must be initialized by setting the parent key for each key, using the setParent(String, Sting) method. Row key does not have to be unique, many rows with the same key will be sorted equal. However, two rows with the same key but different parents, will cause an error.

Does not detect circular relationships and will not fail if that happens.

Author:
Romain Guay, Taleo Corporation

Constructor Summary
HierarchicalRowComparator(int keyIndex)
          Constructor with the column index of the row key.
HierarchicalRowComparator(int keyIndex, boolean topDown)
          Constructor with the column index of the row key and the sort order.
HierarchicalRowComparator(int keyIndex, boolean topDown, boolean ignoreCase)
          Constructor with the column index of the row key, the sort order and the case sensitiveness.
 
Method Summary
 int compare(java.util.List row1, java.util.List row2)
          Compare rows as List.
 int compare(java.lang.Object obj1, java.lang.Object obj2)
           
 int compare(java.lang.String[] row1, java.lang.String[] row2)
          Compare rows as String[].
 java.lang.String getParent(java.lang.String key)
          Get the parent key for a given child key.
 void setParent(java.lang.String key, java.lang.String parentKey)
          Set the parent key for a given child key.
 
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
 

Constructor Detail

HierarchicalRowComparator

public HierarchicalRowComparator(int keyIndex)
Constructor with the column index of the row key.

Parameters:
keyIndex - The column index of the row key.

HierarchicalRowComparator

public HierarchicalRowComparator(int keyIndex,
                                 boolean topDown)
Constructor with the column index of the row key and the sort order.

Parameters:
keyIndex - The column index of the row key.
topDown - true for top down (parent first) sorting.

HierarchicalRowComparator

public HierarchicalRowComparator(int keyIndex,
                                 boolean topDown,
                                 boolean ignoreCase)
Constructor with the column index of the row key, the sort order and the case sensitiveness.

Parameters:
keyIndex - The column index of the row key.
topDown - true for top down (parent first) sorting.
ignoreCase - Indicate if case is considered when comparing keys.
Method Detail

setParent

public void setParent(java.lang.String key,
                      java.lang.String parentKey)
Set the parent key for a given child key. Parent key can be null if at the top of the hierarchy.

Parameters:
key - The child key.
parentKey - The parent key.

getParent

public java.lang.String getParent(java.lang.String key)
Get the parent key for a given child key.

Parameters:
key - The child key.
Returns:
The parent key.

compare

public int compare(java.lang.Object obj1,
                   java.lang.Object obj2)
Specified by:
compare in interface java.util.Comparator

compare

public int compare(java.lang.String[] row1,
                   java.lang.String[] row2)
Compare rows as String[].

Parameters:
row1 -
row2 -
Returns:

compare

public int compare(java.util.List row1,
                   java.util.List row2)
Compare rows as List.

Parameters:
row1 -
row2 -
Returns: