package de.uka.ipd.consensus.impl;

import java.util.Date;

import de.uka.ipd.consensus.foundation.schema.Version;
import de.uka.ipd.consensus.foundation.schema.Versionable;

/**
 * TODO
 * @author Thomas Much
 * @version 2006-06-14
 */
public class VersionImpl implements Version {

	private Versionable versionable;
	private Date        date;


	protected VersionImpl(Versionable versionable) {
		this.versionable = versionable;
		this.date        = new Date();
	}


	protected VersionImpl(Versionable versionable, long date) {
		this.versionable = versionable;
		this.date        = new Date( date );
	}


	protected void inc() {
		this.date = new Date();
	}


	/**
	 * TODO
	 */
	public boolean after(Version ver) {
		return this.date.after( ((VersionImpl)ver).date );
	}

	
	/**
	 * TODO
	 */
	public boolean before(Version ver) {
		return this.date.before( ((VersionImpl)ver).date );
	}

	
	/**
	 * TODO
	 */
	public int compareTo(Object obj) {
		return this.date.compareTo( ((VersionImpl)obj).date );
	}

	
	/**
	 * TODO
	 */
	public boolean equals(Object obj) {

		if (obj == null) return false;
		
		if (this.getClass() != obj.getClass()) return false;

		VersionImpl other = (VersionImpl)obj;
		
		return this.date.equals( other.date ) && this.versionable.equals( other.versionable );
	}

	
	/**
	 * TODO
	 */
	public int hashCode() {
		return this.date.hashCode() ^ this.versionable.hashCode();
	}

	
	/**
	 * TODO
	 */
	public String toString() {
		return "Version \"" + this.date + "\"";
	}

	
	/**
	 * TODO
	 */
	public Versionable getVersionable() {
		return this.versionable;
	}

	
	public Date getDate() {
		return date;
	}

}
