문제

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