/**
 * RuleParam.java
 * Created on May 13, 2008
 * (C) Copyright TANDBERG Television Ltd.
 */
package com.tandbergtv.watchpoint.pmm.entities;

import java.io.Serializable;

/**
 * @author spuranik
 * 
 * This class represents the value supplied for the rule's rule type e.g. 3 -days/weeks, 10/25/2007 -
 * date ...
 */
public class RuleParameter implements Serializable {

	private static final long serialVersionUID = 1L;
	public static final int DEFAULT_ID = 0;
	private static final int HASHCODE_MULTIPLICATION_FACTOR = 8;
	private static final int HASHCODE_ADDITION_FACTOR = 104;

	// id in db
	private long id;

	// value provided for the rule type parameter
	private String value;

	// order in which this variable appears in the rule
	private int order;

	// rule to which this parameter belongs. required for saving the param
	private Rule rule;

	/**
	 * Default ctor
	 */
	public RuleParameter() {
	}

	/**
	 * @return the id
	 */
	public long getId() {
		return id;
	}

	/**
	 * @param id
	 *            the id to set
	 */
	public void setId(long id) {
		this.id = id;
	}

	/**
	 * @return the value
	 */
	public String getValue() {
		return value;
	}

	/**
	 * @param value
	 *            the value to set
	 */
	public void setValue(String value) {
		this.value = value;
	}

	/**
	 * @return the order
	 */
	public int getOrder() {
		return order;
	}

	/**
	 * @param order
	 *            the order to set
	 */
	public void setOrder(int order) {
		this.order = order;
	}

	/**
	 * @return the rule
	 */
	public Rule getRule() {
		return rule;
	}

	/**
	 * @param ruleId
	 *            the ruleId to set
	 */
	public void setRule(Rule rule) {
		this.rule = rule;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (obj instanceof RuleParameter) {
			RuleParameter ruleParameterObj = (RuleParameter) obj;

			if (ruleParameterObj.getId() != DEFAULT_ID && this.getId() != DEFAULT_ID) {
				return (ruleParameterObj.getId() == this.getId());
			} else {
				return super.equals(obj);
			}
		}
		return false;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		long hash = this.id * HASHCODE_MULTIPLICATION_FACTOR + HASHCODE_ADDITION_FACTOR;
		int hashCode = new Long(hash).hashCode();
		if (this.id == DEFAULT_ID) {
			hashCode = super.hashCode();
		}
		return hashCode;
	}

}
