Before I mostly had to loop between days in a certain period and I used loops like this:
for(LocalDate iDate = gv.firstDate; iDate.isBefore(gv.lastDate); iDate = iDate.plusDays(1)) {
...
}
Now I have a TreeMap like this:
TreeMap<LocalDate, ArrayList<Email>> dates;
I want to loop over all months from gv.firstDate to gv.lastDate and get all Emails that are within that month.
Does anyone know of a good way to do this using Joda-Time?
edit:
Having it combined with this will be great, so now get from emails from the dates TreeMap.
for(int y = 2004; y < 2011; y++) {
for(int m = 0; m < 12; m++) {
// get all of that month
}
}
As you are using a TreeMap you could use method http://docs.oracle.com/javase/6/docs/api/java/util/NavigableMap.html#subMap%28K,%20boolean,%20K,%20boolean%29
Returns a view of the portion of this map whose keys range from fromKey to toKey.
If the keys defining the interval are not guaranteed to be in the map you can get a map containing only the values you want by doing