/**
 * ProtectionKey.java
 * Created on Aug 7, 2006
 * (C) Copyright TANDBERG Television Ltd.
 */
package com.tandbergtv.workflow.auth.domain;

/**
 * The Protection Key associated with a resource group and a template
 * 
 * @author Vlada Jakobac
 *
 */
public class ProtectionKey
{
	private int id=-1;
	
	private String name="";

	private static final int HASHCODE_MULTIPLICATION_FACTOR = 11;

	private static final int HASHCODE_ADDITION_FACTOR = 731;

	public ProtectionKey()
	{
	}

	public ProtectionKey(int id)
	{
		this.id = id;
	}
	
	/**
	 * @param name
	 */
	public ProtectionKey(String name)
	{
		this.name = name;
	}

	/**
	 * @return Returns the id.
	 */
	public int getId()
	{
		return id;
	}

	/**
	 * @param id The id to set.
	 */
	public void setId(int id)
	{
		this.id = id;
	}

	/**
	 * @return Returns the name.
	 */
	public String getName()
	{
		return name;
	}

	/**
	 * @param name The name to set.
	 */
	public void setName(String name)
	{
		this.name = name;
	}

	/**
	 * Returns the Hashcode for this object
	 * 
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode()
	{
		int hashCode = this.id * HASHCODE_MULTIPLICATION_FACTOR
				+ HASHCODE_ADDITION_FACTOR;

		if (this.id == -1)
		{
			hashCode = super.hashCode();
		}

		return hashCode;
	}

	/**
	 * Compares the ProcessPriority 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 ProtectionKey)
		{
			ProtectionKey pkObj = (ProtectionKey) obj;

			if (pkObj.getId()!= -1 && this.getId() != -1)
			{
				return (pkObj.getId() == this.getId());
			}
			else
			{
				return super.equals(obj);
			}
		}

		return false;
	}
}
