public static Iterator getCalendarIterator(Date focus, int rangeStyle) { GregorianCalendar gval = new GregorianCalendar(); gval.setTime(focus); return getCalendarIterator(gval, rangeStyle);
public static Iterator getCalendarIterator(Calendar focus, int rangeStyle) { Calendar start = null; Calendar end = null; int startCutoff = Calendar.SUNDAY; int endCutoff = Calendar.SATURDAY; switch (rangeStyle) { case RANGE_MONTH_SUNDAY: case RANGE_MONTH_MONDAY:  start = trunc(focus, Calendar.MONTH);  end = (Calendar) start.clone(); end.add(Calendar.MONTH, 1); end.add(Calendar.DATE, -1);  if (rangeStyle == RANGE_MONTH_MONDAY) { startCutoff = Calendar.MONDAY; endCutoff = Calendar.SUNDAY; } break; case RANGE_WEEK_SUNDAY: case RANGE_WEEK_MONDAY: case RANGE_WEEK_RELATIVE: case RANGE_WEEK_CENTER:  start = trunc(focus, Calendar.DATE); end = trunc(focus, Calendar.DATE); switch (rangeStyle) { case RANGE_WEEK_SUNDAY:  break; case RANGE_WEEK_MONDAY: startCutoff = Calendar.MONDAY; endCutoff = Calendar.SUNDAY; break; case RANGE_WEEK_RELATIVE: startCutoff = focus.get(Calendar.DAY_OF_WEEK); endCutoff = startCutoff - 1; break; case RANGE_WEEK_CENTER: startCutoff = focus.get(Calendar.DAY_OF_WEEK) - 3; endCutoff = focus.get(Calendar.DAY_OF_WEEK) + 3; break; } break; default: throw new RuntimeException("The range style " + rangeStyle + " is not valid."); } if (startCutoff < Calendar.SUNDAY) { startCutoff += 7; } if (endCutoff > Calendar.SATURDAY) { endCutoff -= 7; } while (start.get(Calendar.DAY_OF_WEEK) != startCutoff) { start.add(Calendar.DATE, -1); } while (end.get(Calendar.DAY_OF_WEEK) != endCutoff) { end.add(Calendar.DATE, 1); } final Calendar startFinal = start; final Calendar endFinal = end; Iterator it = new Iterator() { Calendar spot = null; { spot = startFinal; spot.add(Calendar.DATE, -1); }  public boolean hasNext() { return spot.before(endFinal); }  public Object next() { if (spot.equals(endFinal)) { throw new NoSuchElementException(); } spot.add(Calendar.DATE, 1); return spot.clone(); }  public void remove() { throw new UnsupportedOperationException(); } }; return it;
    public static Iterator getCalendarIterator(Date focus, int rangeStyle) {        GregorianCalendar gval = new GregorianCalendar();        gval.setTime(focus);        return getCalendarIterator(gval, rangeStyle);    }