Perhaps the best way to show the
simplicity of GComp is by way of example. Consider we need a comparator
to sort a collection of orders (as specified in the above diagram)
according to customer number.
All we need is one of the following:
new
GComp("getOrderNo"); // method syntax
new
GComp("orderNo"); // property syntax
Suppose we need a comparator that will sort the orders according to a
customer's date of birth:
new
GComp("customer.dateOfBirth");
// ascending order
new
GComp("customer.dateOfBirth@order=desc");
//
descending order
new
GComp("customer.dateOfBirth@order=desc,nulls=first");
// descending order, placing first those orders for which
// the
customer's date of birth is unknown
A comparator that will sort the orders according to a
customer's last name and then first name for those customers with the
same last name:
new
GComp("customer.lastName|customer.firstName");
// sort
according to last name then first name
new
GComp("customer.lastName@order=asc|customer.firstName@order=desc");
// last name ascending, first name descending
new
GComp("customer.lastName.toLowerCase|customer.firstName.toLowerCase");
// ignoring case
Summary:
GComp provides a simple to use comparator that should suffice
for most of the usual ordering situations that Java programmers can
expect to encounter. Find it at
www.sourgeforge.net/projects/gcomp.