代码拉取完成,页面将自动刷新
package chap12;
/**
* PrioritizedObject represents a node in a priority queue containing a
* comparable object, arrival order, and a priority value.
*
* @author Lewis and Chase
* @version 4.0
*/
public class PrioritizedObject<T> implements Comparable<PrioritizedObject>
{
private static int nextOrder = 0;
private int priority;
private int arrivalOrder;
private T element;
/**
* Creates a new PrioritizedObject with the specified data.
*
* @param element the element of the new priority queue node
* @param priority the priority of the new queue node
*/
public PrioritizedObject(T element, int priority)
{
this.element = element;
this.priority = priority;
arrivalOrder = nextOrder;
nextOrder++;
}
/**
* Returns the element in this node.
*
* @return the element contained within the node
*/
public T getElement()
{
return element;
}
/**
* Returns the priority value for this node.
*
* @return the integer priority for this node
*/
public int getPriority()
{
return priority;
}
/**
* Returns the arrival order for this node.
*
* @return the integer arrival order for this node
*/
public int getArrivalOrder()
{
return arrivalOrder;
}
/**
* Returns a string representation for this node.
*
*/
public String toString()
{
return (element + " " + priority + " " + arrivalOrder);
}
/**
* Returns 1 if the this object has higher priority than
* the given object and -1 otherwise.
*
* @param obj the object to compare to this node
* @return the result of the comparison of the given object and
* this one
*/
public int compareTo(PrioritizedObject obj)
{
int result;
if (priority > obj.getPriority())
result = 1;
else if (priority < obj.getPriority())
result = -1;
else if (arrivalOrder > obj.getArrivalOrder())
result = 1;
else
result = -1;
return result;
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。