package Model;

import java.awt.*;

/**
 * Meaning. 
 * 
 */

public class Meaning implements Comparable<Object>{

	//String Representation of the Meaning Object
	private String stringRep_;
	//Image Representation of the Meaning Object
	private Image image_;
	
	/**
	 * Explicit constructor, setting the according fields.
	 * 
	 * @param a
	 *            String representation of the Meaning object
	 */
	public Meaning(String a){
		stringRep_ = a;
	}
	
	/**
	 * Explicit constructor, setting the according fields.
	 * 
	 * @param a
	 *            String representation of the Meaning object
	 * @param b
	 * 			  Image representation of the Meaning object
	 */
	public Meaning(String a, Image b){
		stringRep_ = a;
		image_ = b;
	}
	
	/**
	 * This method overwrites the equal() method
	 * 
	 * @param other
	 *            Object which is supposed to be compared to this Meaning object
	 *            
	 * @return true if objects are equal
	 */
	public boolean equals ( Object other )
    {
		if ( other == null )
		{
			return false;
		}	
		else 
		{
			if ( other instanceof Meaning )
			{
				boolean str = stringRep_.equals(((Meaning)other).getStringRep());
				return (str );
			}	
			else
			{
				return false;
			}
		}
    }
	
	/**
	 * This mehtod overwrites the hashCode() mehtod
	 * 
	 * @return HashCode of this object
	 */
	
    public int hashCode() {
        int hashFirst = stringRep_ != null ? stringRep_.hashCode() : 0;
        int hashSecond = image_ != null ? image_.hashCode() : 0;

        return (hashFirst + hashSecond) * hashSecond + hashFirst;
    }
	
	//Setter
	public void setStringRep(String a){
		stringRep_ = a;
	}
	
	public void setImage_(Image a){
		image_ = a;
	}
	
	//Getter
	public String getStringRep(){
		return stringRep_;
	}
	
	public Image getImage(){
		return image_;
	}
	
	/**
	 * This method returns the String representation of this Meaning object.
	 * 
	 * @return String Representation of this Object
	 */
	public String toString() {
		return getStringRep();
	}

	@Override
	public int compareTo(Object anotherMeaning) {
		if (!(anotherMeaning instanceof Meaning))
			throw new ClassCastException("A Meaning object was expected.");
		String anotherStringRep=((Meaning) anotherMeaning).getStringRep();
		return this.getStringRep().compareTo(anotherStringRep);
	}
	
}
