At work we are working on a project that involves pushing out correspondence to students. This necessitates sorting by multiple factors, including name, homeroom, etc. This is trivial when using SQL ORDER BY
, but I already had all the information I needed in the business objects, so I really needed to implement a mult-field sort in Java.
The algorithm works off of the same principals as ORDER BY
. A list of field names and objects are passed in and then the objects are hierarchically (i.e. recursively) sorted using reflection and each of the field names passed in. It’s pretty sweet in that the field list can be arbitrarily deep and it is not tied to a specific object type.
As I was trying to solve a specific problem, there are several limitations: Read the rest of this entry »