package org.treesched;

import java.io.Serializable;



/**
 * Proved a basis of common functionality for schedules.
 * 
 * @author Rob Gordon
 */


abstract public class AbstractSchedule
		implements Serializable, RefineableSchedule {

    private static final long serialVersionUID = 20050226;
    
	/** A child schedule */
	private Schedule childSchedule;

	/** limits which bound the schedule */
	private Interval limits;

	/*
	 *  (non-Javadoc)
	 * @see org.treesched.Schedule#setLimits(org.treesched.Interval)
	 */
	public void setLimits(Interval limits) {
	    this.limits = limits;
	}
	
	/**
	 * Get any limits set for this schedule.
	 * 
	 * @return The limits, may be null.
	 */
	public Interval getLimits() {
	    return limits;
	}
	
	/**
	 * Set the child schedule.
	 * 
	 * @param schedule The child schedule.
	 */
	public void setChildSchedule(Schedule schedule) {
		this.childSchedule = schedule;
	}
	
	/*
	 *  (non-Javadoc)
	 * @see org.treesched.RefineableSchedule#addChildSchedule(org.treesched.Schedule)
	 */
	public void addChildSchedule(Schedule schedule) {		
		if (childSchedule == null) {
			childSchedule = new ScheduleList();
		}
		else if (!(childSchedule instanceof ScheduleList)) {
			throw new IllegalStateException("Child schedule of " + childSchedule 
				+ " already exists for " + this);
		}		
		((ScheduleList)childSchedule).addChildSchedule(schedule);
	}
	
	/**
	 * Return the child schedule.
	 * 
	 * @return The child schedule.
	 */	
	public Schedule getChildSchedule() {	
		return childSchedule;
	}

	/*
	 *  (non-Javadoc)
	 * @see org.treesched.Schedule#reset()
	 */
	public void reset() {
	}
}
