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?

有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top