[EMAIL PROTECTED] wrote:
>
> Is it possible to sort the days of the week?
> I have a Map where the keys are days of the week. i.e. values returned
> from DateMidnight.dayOfWeek();
> I wanted to iterate over the days of the week in order and get the
> values for that day, like so
>
> Map byWeekday;
> List daysOfWeek=new ArrayList(byWeekday.keySet());
> Collections.sort(daysOfWeek);
>
> for (Iterator iterator = daysOfWeek.iterator(); iterator.hasNext();)
> {
>
> However, it turns out that DateMidnight.Property does not implement
> Comparable, so I get a ClassCastException when I try to sort the days
> of the week.
>
> It seems to make sense that the days of the week should implement
> Comparable; there may be complications with working out when the week
> starts and ends, but otherwise this seems straightforward.
>
> Or is there another way of doing this?
>
if you were storing the full DateMidnight objects then you would be able
to compare using DateTimeComparator.
However, the best you can do here is to write your own Comparator, and
pass it to the sort method.
Stephen
_______________________________________________
Joda-interest mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/joda-interest