/*
 * Copyright (c) 2011, Patrik Dufresne. All rights reserved.
 * Patrik Dufresne PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */
package com.planimod.core;

import java.util.Date;

/**
 * Concrete implementation of TimeRange.
 * 
 * @author Patrik Dufresne
 * 
 */
public class ConcreteTimeRange implements TimeRange {

	private Date end;

	private Date start;

	/**
	 * Create a new time range from a starting and ending date. The dates can't
	 * be null.
	 * 
	 * @param start
	 * @param end
	 */
	public ConcreteTimeRange(Date start, Date end) {
		if (start == null || end == null) {
			throw new IllegalArgumentException();
		}
		this.start = start;
		this.end = end;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		ConcreteTimeRange other = (ConcreteTimeRange) obj;
		if (!this.end.equals(other.end))
			return false;
		if (!this.start.equals(other.start))
			return false;
		return true;
	}

	/**
	 * Return the ending date.
	 */
	@Override
	public Date getEndDate() {
		return this.end;
	}

	/**
	 * Return the starting date.
	 */
	@Override
	public Date getStartDate() {
		return this.start;
	}

	/**
	 * This implementation return a hash code using the starting and ending
	 * dates.
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + this.end.hashCode();
		result = prime * result + this.start.hashCode();
		return result;
	}

	@Override
	public String toString() {
		return "ConcreteTimeRange [from:" + this.start + ", to:" + this.end + "]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
	}

}