package de.uka.ipd.consensus.impl;

import java.util.Collection;

import de.uka.ipd.consensus.foundation.rating.RatingManagerException;
import de.uka.ipd.consensus.foundation.rights.DynamicRightsManagerException;
import de.uka.ipd.consensus.foundation.schema.Association;
import de.uka.ipd.consensus.foundation.schema.Rating;
import de.uka.ipd.consensus.foundation.schema.SuperSubclass;
import de.uka.ipd.consensus.foundation.schema.Topic;
import de.uka.ipd.consensus.foundation.schema.User;

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

	private Topic       superclass;
	private Topic       subclass;
	private Association assoc;


	protected SuperSubclassImpl(Topic subclass, Topic superclass, Association assoc) {
		// assoc must be unique!
		this.subclass   = subclass;
		this.superclass = superclass;
		this.assoc      = assoc;
	}


	public Topic getSuperclass() {
		return this.superclass;
	}


	public Topic getSubclass() {
		return this.subclass;
	}


	public String getId() {
		return assoc.getId();
	}

	
	public Rating addRating(User rater, double value) throws RatingManagerException, DynamicRightsManagerException {
		return assoc.addRating( rater, value );
	}

	
	public Collection getRatings() {
		return assoc.getRatings();
	}

	
	public int getRatingsCount() {
		return assoc.getRatingsCount();
	}

	
	public Rating getRating(User rater) {
		return assoc.getRating( rater );
	}

	
	public double getAverageRatingValue() {
		return assoc.getAverageRatingValue();
	}
	
	
	public boolean equals(Object other) {
		if (other == null) return false;
		if (this.getClass().equals( other.getClass() )) {
			return this.getId().equals( ((SuperSubclassImpl)other).getId() );
		}
		return super.equals( other );
	}


	public int hashCode() {
		if (this.getId() == null) {
			return super.hashCode();
		}
		return this.getId().hashCode();
	}


	public int compareTo(Object other) {
		return this.superclass.compareTo( ((SuperSubclassImpl)other).superclass );
	}
	
	
	public String toString() {
		return "Superclass " + this.superclass + " (for subclass " + this.subclass + ")";
	}

}
