Question

Object timeline after sorting

This is my object order after I've finished sorting them by date using jodatime's DateTime objects. I tried using java.util.Date and Calendar too, but the result is the same. I use a PriorityQueue with a custom comparator (o1.getTime().compareTo(o2.getTime()), which should work, but as you can see - it doesn't. For some reason, whatever I try, I always end up with a screwy timeline. The objects are never rightly arranged. I tried comparing them by DayOfMonth, and then by HourOfDay if the days matched but again the result remains the same.

I've been banging my head over this for about 3 days. Does anyone have any idea as to why this is happening?

Was it helpful?

Solution

Inner data structure does (as you can see it in debugger) does not represent the order you'll get items from PriorityQueue. Try to go through PriorityQueue using poll() method and you'll get the dates properly arranged.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top