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.Synonym;
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 SynonymImpl implements Synonym {

	private Topic       topic;
	private Topic       synonym;
	private Association assoc;
	
	
	protected SynonymImpl(Topic topic, Topic synonym, Association assoc) {
		// assoc must be unique!
		this.topic   = topic;
		this.synonym = synonym;
		this.assoc   = assoc;
	}

	
	public Topic getTopic() {
		return this.topic;
	}
	
	
	public Topic getSynonym() {
		return this.synonym;
	}

	
	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( ((SynonymImpl)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.synonym.compareTo( ((SynonymImpl)other).synonym );
	}


	public String toString() {
		return "Synonym " + this.topic + " <--> " + this.synonym;
	}
	
}
