package simulator;

/*
 * PrioritizedElement.java
 * Created on Jan 21, 2005
 *
 */

/**
 * This is the class that will be put into the actual priority queue.
 * This class was created in order to encapsulate a separate priority
 * value.
 *
 * Note: This priority value MUST implement the Comparable interface.
 *
 * It is a templated class with 2 types, T for the element, P for
 * the type of the priority
 * @author Ping
 */
public class PrioritizedElement<T, P extends Comparable<P>> implements Cloneable,
    Comparable<PrioritizedElement<T, P>>
{
    protected T element;
    protected P priority;

    public PrioritizedElement(T element, P priority /*P comparator*/)
    {
        this.element = element;
        this.priority = priority;
    }

    /**
     * This function returns the element associated with this instance
     * @return
     */
    public T getElement()
    {
        return element;
    }

    /**
     * This function returns the priority assigned to this element.
     * @return
     */
    public P getPriority()
    {
        return priority;
    }
    /**
     * Note: this is just a shallow clone!
     */
    public Object clone() throws CloneNotSupportedException
    {
        return super.clone();
    }

    public boolean equals(Object o)
    {
        if(o instanceof PrioritizedElement)
        {
            PrioritizedElement<?, ?> e = (PrioritizedElement<?, ?>)o;
            return e.element.equals(this.element) &&
                   e.priority.equals(this.priority);
        }
        return false;
    }

    /* (non-Javadoc)
     * @see java.lang.Comparable#compareTo(java.lang.Object)
     */
    public int compareTo(PrioritizedElement<T, P> arg0)
    {
        return this.priority.compareTo(arg0.priority);
    }
}