@SuppressWarnings({"rawtypes", "unchecked"})
public int compare(DynamicDataRow leftRow,
DynamicDataRow rightRow) {
int comparison = 0;
for ( int index = 0; index < sortConfig.size(); index++ ) {
SortConfiguration sc = sortConfig.get( index );
Comparable leftColumnValue = leftRow.get( sc.getColumnIndex() );
Comparable rightColumnValue = rightRow.get( sc.getColumnIndex() );
comparison =
(leftColumnValue == rightColumnValue) ? 0
: (leftColumnValue == null) ? -1
: (rightColumnValue == null) ? 1
: leftColumnValue.compareTo( rightColumnValue );
if ( comparison != 0 ) {
switch ( sc.getSortDirection() ) {
case ASCENDING :
break;
case DESCENDING :
comparison = -comparison;
break;
default :
throw new IllegalStateException(
"Sorting can only be enabled for ASCENDING or"
+ " DESCENDING, not sortDirection ("
+ sc.getSortDirection()
+ ") ." );
}
return comparison;
}
}