Hello EveryOne, I have a tricky question in sorting with collection.
I have a HashMap which contains some thing like the following
HashMap<String,QuoteBean> mapToSort=new HashMap<<String,QuoteBean>();
QuoteBean is basically a java bean which has properties with setter and getter methods Which looks like the following.
//class QuoteBean defination
Class QuoteBean implements Serializable{
private BigDecimal currentPricel
private BigDecimal change;
private BigDecimal TotalChange;
private String symbol;
//with getter and setter methods
}//end of the class
Now when i get the values from the map i usually get it like this
Collection values=mapToSort.values();//which will return all the values in the map
This values is basically a collection of QuoteBean objects. I want to sort the beans before sending it to the client. Now i can use the comparator interface and sort it .. But the problem is the sorting criteria changes frequently . I mean some time the client wants to sort with symbol,some times the client wants with change some times with total gain. The criteria changes very often. Is there a way to write the " compare " function to overload and which will satisfy all the conditions...
Is there any good way of solving this problem..
I would really appreciate if some one can reply to this topic
Thanks,