Here’s the deal :
I have Publication objets in my application.
I also have Vote objet (forOrAgainst,author,linkedPublication)
I want to sort publication by date, title… and also by number of votes.
I cant directly sort my list of publication as i dont have the number of vote in that list.
How can i sort my list of publication without adding method to the publication object.
What is the best way to link them ?
Should i return a hashmap ? a treeset ? an array ?
It’s kinda messy in my brain now…
Here’s an example of using
Comparatorto sort based on an external criteria:This uses just
Stringfor publication for simplicity; you’d want to sortPublicationin your application. This also uses a simpleintto get the vote count, but essentially there has to be a tally service that gives you, given aPublication, what itsVotecount is.Then you can sort, using, say,
TreeSet.This prints: