Angsuman's Java Blog

News and views from my perspective as a Chief Software Architect and CEO. Focused on Java and Web Technologies.

Thursday, February 13, 2003

Requirement: Create a Comparator for sorting based on different fields

Usage: Allow customers to sort by different columns of a data set.

cFirst = (Comparable) first.getClass().getField(cf).get(first);
cSecond = (Comparable) second.getClass().getField(cf).get(second);
return (corder.booleanValue())?cFirst.compareTo(cSecond):cSecond.compareTo(cFirst);