Atom Feed SITE FEED   ADD TO GOOGLE READER

UniqueList, Bag, and Sorting 2x

I am writing a user interface for data-entry. Because data-entry sucks I am trying to make this UI as usable as possible. This includes accelerator values for each field. For example, a field to enter a car name will include buttons for each of the most popular values for that field. Clicking on such a button will populate the car name with the corresponding value:

Car:
Maxima, 300 Z, Camaro

The list of suggested values is sorted by popularity. The value that has been entered the most times is the first suggestion, and the second most popular entry is second, etc.

Now the fun part is implementing it. Traditionally this would be done with a SQL query with some GROUP BY, ORDER BY and COUNT parameters. Unfortunately I am limiting myself to EJB-QL, which is not (yet) powerful enough to do this.

This got me thinking, could I implement this using Glazed Lists? I want to take an arbitrary EventList and return a second EventList of those values, sorted by popularity.

Since UniqueList has a method to get the count of duplicates for a given value, this is possible. I simply sort the UniqueList by this duplicates count. There's still one major difficulty: UniqueList doesn't currently fire events on that duplicate count changing. But a solution is definitely possible.

Glazed Lists rules.
This is a cool problem, and one which could be easily handled by pairing UniqueList with a "PopularityList". A popularity-sorted wrapper to UniqueList is almost general enough to be considered as a new feature for Glazed Lists, but that's up for discussion.

Reading this post reminded me of an old bug that UniqueList had. Bug 35 now that I look it up. Thinking back it must have been closed in error, as it describes the solution, but it seems that never made it into the code.