reset password
Author Message
talisunep
Posts: 140
Posted 22:04 Jan 22, 2013 |

Dr Sun
how do we go about to sort the  Days To Go in ascending order in the display table, do we need to create a seperate Array List to sort this?
 

shussain
Posts: 21
Posted 00:15 Jan 23, 2013 |

Y dont u use Comparator class to sort the properties of u r class i.e days to go...dat works fine with my code...compare two entries of the table and arrange them in ascending order...hope u got me..

 

 

for reference u can go to below link

http://docs.oracle.com/javase/6/docs/api/java/util/Comparator.html

talisunep
Posts: 140
Posted 00:39 Jan 23, 2013 |

thank you for the share? did  this work for you? and does it display sorted in the project table when you want to display by order? 

shussain
Posts: 21
Posted 00:41 Jan 23, 2013 |

Yes it did show me days to go in sorted way in project table...

talisunep
Posts: 140
Posted 00:44 Jan 23, 2013 |

thats awesome... will have to go through the class and sort this out tonight...i was wondering to display sorted did you put the comparator code in a for loop in the doGet of the main servlet?

shussain
Posts: 21
Posted 00:48 Jan 23, 2013 |

well not der i fact but at top of it indeed...first i thought of putting der but it didnt work out...

cysun
Posts: 2935
Posted 08:36 Jan 23, 2013 |

I wouldn't recommend having a "Days To Go"  field in your Project class because Days To Go changes every day.

I'd suggest that you use an End Date field, which is Start Date + Funding Duration. Keep your list of Projects sorted on End Date, which would be the same order as Days To Go. Also it's easy to determine which project is still in its funding period by checking End Date > Current Date.

PabloS
Posts: 20
Posted 12:40 Jan 23, 2013 |

If reading documentation confuses anybody, I found this great tutorial that explains, in simple terms, how to use the Comparable interface and Comparator. For this particular assignment I found implementing Comparable is the easiest way to go (for now).

 

http://www.mkyong.com/java/java-object-sorting-example-comparable-and-comparator/

 

talisunep
Posts: 140
Posted 23:20 Jan 24, 2013 |

Comparable did the job for me thats for the share and the example