/*
 * Created on Jul 23, 2008 (C) Copyright TANDBERG Television Ltd.
 */

package com.tandbergtv.watchpoint.pmm.title.provider;

import java.util.HashMap;
import java.util.Map;

/**
 * Represents an instance of a Title Provider. Contains a set of properties for the provider that
 * can be used when attempting to communicate with this Instance for getting Title information.
 * 
 * @author Vijay Silva
 */
public class TitleProviderInstance implements ITitleProviderInstance {

	/* The Key for the Provider which is unique for all instances for the parent Provider */
	private String key;

	/* Display name for the Provider Instance */
	private String name;

	/* Set of properties for a provider instance */
	private Map<String, String> properties = new HashMap<String, String>();

	/**
	 * Creates a TitleProviderInstance
	 */
	public TitleProviderInstance() {
		super();
	}

	/**
	 * Creates a TitleProviderInstance
	 * @param key
	 * @param name
	 * @param properties
	 */
	public TitleProviderInstance(String key, String name, Map<String, String> properties) {
		this.key = key;
		this.name = name;
		this.properties = properties;
	}

	/**
	 * {@inheritDoc}
	 */
	public String getKey() {
		return key;
	}

	/**
	 * {@inheritDoc}
	 */
	public void setKey(String key) {
		this.key = key;
	}

	/**
	 * {@inheritDoc}
	 */
	public String getName() {
		return name;
	}

	/**
	 * {@inheritDoc}
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * {@inheritDoc}
	 */
	public Map<String, String> getProperties() {
		return properties;
	}

	/**
	 * {@inheritDoc}
	 */
	public void setProperties(Map<String, String> properties) {
		this.properties = properties;
	}

	/**
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		/* Check if key defined */
		if (this.key == null)
			return super.hashCode();

		final int prime = 11;
		int shift = -438;
		int result = key.hashCode() * prime + shift;
		return result;
	}

	/**
	 * Checks if an object is a ITitleProviderInstance and checks if its key is equal to this key.
	 * 
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (!(obj instanceof ITitleProviderInstance))
			return false;

		/* If either key is null, don't compare the keys */
		ITitleProviderInstance other = (ITitleProviderInstance) obj;
		if (this.key == null || other.getKey() == null) {
			return super.equals(obj);
		}

		return this.key.equals(other.getKey());
	}
}
