As of version 0.7 JoSQL now contains a
java.util.Comparator
that takes the
ORDER BY clause of a SQL statement and applies that to a set of objects. The Comparator can be found in the
org.josql.utils
package. Use the JoSQLComparator in the same way as other Comparators, i.e.
Collections.sort (myObjs,
josqlComparator);
Arrays.sort (myObjs,
josqlComparator);
or:
Map tm = new TreeMap (josqlComparator);
Set ts = new TreeSet (josqlComparator);
One thing to understand however is that a JoSQLComparator
can throw an exception, i.e. an exception can be raised if a column cannot be accessed or if a function cannot be executed. In this case the JoSQLComparator will save the exception and when sort is complete it can be retrieved (if it occurred) via:
getException(). It is also possible to use the Comparator in "caching" mode, this should be used to provide speedup when used in
Collections.sort(List,Comparator)
. See the
JoSQLComparator for full details.