/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package schedule;

import java.util.Date;

/**
 * This class contains method necessary for scheduling and executing various
 * tasks. Class contains time iterator which is used to determine time at which
 * run() method of other stored object is invoked.
 * 
 * @author Marcel Duris
 */
public class Task implements ITask {
    private ISchedulable time;
    private Runnable task;

    /**
     * Constructor takes instance of runnable class and parameters that specify
     * time at which class should be run.
     * 
     * @param task instance of Runnable interface
     * @param dayOfMonth number of day of month or wildcard
     * @param dayOfWeek number of day of week or wildcard
     * @param hour hour of execution
     * @param minute minute of execution
     * @see schedule.ISchedulable
     * @see schedule.TaskTime
     */
    public Task(Runnable task, int dayOfMonth, int dayOfWeek, int hour, int minute) {
        time = new TaskTime(dayOfMonth, dayOfWeek, hour, minute);
        this.task = task;
    }

    /**
     * Starts runnable class.
     */
    public void run() {
        this.task.run();
    }


    public Date nextDue() {
        return time.nextDue();
    }

    public boolean accepts(Date date) {
        return time.accepts(date);
    }

}
