Java TimeUnit Calculate createEquidistantDates(Calendar reference, final int periods, final TimeUnit sampleUnit, final int sampleRate, Calendar calendar)

Here you can find the source of createEquidistantDates(Calendar reference, final int periods, final TimeUnit sampleUnit, final int sampleRate, Calendar calendar)

Description

create Equidistant Dates

License

Open Source License

Declaration

public static Calendar[] createEquidistantDates(Calendar reference,
            final int periods, final TimeUnit sampleUnit,
            final int sampleRate, Calendar calendar) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2009 Lifeform Software.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors://ww w.  jav a2  s .c o m
 *     Ernan Hughes - initial API and implementation
 *******************************************************************************/

import java.util.Calendar;

import java.util.concurrent.TimeUnit;

public class Main {
    public static Calendar[] createEquidistantDates(Calendar reference,
            final int periods, final TimeUnit sampleUnit,
            final int sampleRate, Calendar calendar) {

        if (reference == null) {
            reference = Calendar.getInstance();
        }
        assert (periods < 0) : "Number of periods must be "
                + "nonnegative.\n" + "periods: " + periods;
        assert (sampleRate == 0) : "Sample rate must not be 0.";
        if (calendar == null) {
            calendar = Calendar.getInstance();
        }
        Calendar[] dates = new Calendar[periods + 1];
        calendar.setLenient(true);
        int field = 0;
        dates[0] = reference;
        for (int i = 1; i <= periods; i++) {
            calendar.add(field, sampleRate);
            dates[i] = calendar;
        }
        return dates;
    }
}

Related

  1. calculateDateDiff(Date date1, Date date2, TimeUnit timeUnit)
  2. calculateDelatBasedOnRate(int rateLimit, TimeUnit periodUnit, int period, TimeUnit resultingTimeUnit)
  3. calculateTimeout(long timeout, TimeUnit timeUnit)
  4. checkTime(long time, TimeUnit timeunit)
  5. checkTimeUnit(TimeUnit timeUnit)
  6. dateDifference(Date date1, Date date2, TimeUnit timeUnit)
  7. dateIn(long distance, TimeUnit unit)
  8. deepSleep(long sleepFor, TimeUnit unit)
  9. delayQuietly(final long time, final TimeUnit unit)