package com.tandbergtv.watchpoint.pmm.web.util;


/**
 * Represents an option bean to be used for html select option.
 *  
 * @author Raj Prakash
 */
public class HTMLOption implements Comparable<HTMLOption> {
	private String label, value;
	
	/**
	 * Constructor.
	 */
	public HTMLOption(String label, String value) {
		this.label = label;
		this.value = value;
	}
	
	public HTMLOption(String value) {
		this.label = value;
		this.value = value;
	}
	
	/**
	 * Gets the label of the option.
	 */
	public String getLabel() {
		return label;
	}

	/**
	 * Gets the value of the option.
	 */
	public String getValue() {
		return value;
	}
	
	/**
	 * Compares the HTMLOption Entity object with the input object to see if they are equal.
	 * 
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (obj instanceof HTMLOption) {
			HTMLOption htmlOptionObj = (HTMLOption) obj;

			if (htmlOptionObj.getLabel() != null && this.getLabel() != null &&
					htmlOptionObj.getValue() != null && this.getValue()!= null)	{
				return (htmlOptionObj.getLabel().equals(this.getLabel()) && 
						htmlOptionObj.getValue().equals(this.getValue()));
			} else {
				return super.equals(obj);
			}
		}
		return false;
	}
	
	/**
	 * Returns the Hashcode for this object
	 * 
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode()	{
		int hashCode;
		if (this.getLabel() != null && this.getValue() != null) {
			long hash = this.getLabel().hashCode() * this.getValue().hashCode();
			hashCode = new Long(hash).hashCode();
		} else {
			hashCode = super.hashCode();
		}
		return hashCode;
	}

	public int compareTo(HTMLOption obj) {
		return this.label.compareTo(obj.label);
	}
}


