Java Calendar Calculate calendarIterator(final int iterateType, final Calendar startCal, final Calendar endCal)

Here you can find the source of calendarIterator(final int iterateType, final Calendar startCal, final Calendar endCal)

Description

calendar Iterator

License

Apache License

Declaration

public static Iterable<Calendar> calendarIterator(final int iterateType, final Calendar startCal,
            final Calendar endCal) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.*;

public class Main {
    public static Iterable<Calendar> calendarIterator(final int iterateType, final Calendar startCal,
            final Calendar endCal) {
        return new Iterable<Calendar>() {
            final Calendar workCal = (Calendar) startCal.clone();

            public Iterator<Calendar> iterator() {
                return new Iterator<Calendar>() {
                    public boolean hasNext() {
                        return !workCal.after(endCal);
                    }//  w  ww  .j a va 2s  .  co m

                    public Calendar next() {
                        workCal.add(iterateType, 1);
                        return (Calendar) workCal.clone();
                    }

                    public void remove() {

                    }
                };
            }
        };
    }

    /**
     * A null safe check to whether dt is after dt2.
     *
     * @return if dt2 is after dt
     */
    public static boolean after(Date dt, Date dt2) {
        return !(dt == null || dt2 == null) && dt.after(dt2);
    }
}

Related

  1. calculateMinimalDaysInFirstWeek(Calendar calendar)
  2. calculateMonthsInBetween(Calendar startPoint, Calendar endPoint)
  3. calculateRangeInDays(Calendar start, Calendar end)
  4. calculateWeeksInBetween(Calendar startPoint, Calendar endPoint)
  5. calDateOnly(Calendar iniCal)
  6. cloneCalendar(Calendar in)
  7. copyCalendar(final Calendar calendar, final boolean stripTime)
  8. decode(String timestamp, Calendar calendar)
  9. encode(Calendar calendar, boolean encodeTzOffset, StringBuilder buf)