br.usp.ime.klava.segmentit.structures
Class PriorityQueue<T>

java.lang.Object
  extended by br.usp.ime.klava.segmentit.structures.PriorityQueue<T>
Type Parameters:
T - the type of elements held in this queue

public class PriorityQueue<T>
extends java.lang.Object

Implements a priority queue, using a First In, First Out policy and priorities given by non-negative integer numbers. Smaller priority numbers represents higher priorities.

Author:
Bruno Klava

Constructor Summary
PriorityQueue(int maxPriority)
          Creates an priority queue to store elements with priorities up to maxPriority.
 
Method Summary
 void add(T element, int priority)
          Appends the specified element to the queue with the given priority.
 void clear()
          Removes all of the elements from this queue.
 int getMinPriority()
          Returns the priority of the element with the highest prSmaller priority numbers represents higher priorities.iority.
 boolean isEmpty()
          Returns true if this queue contains no elements.
 T remove()
          Returns the element with the highest priority, removing it.
 void remove(T element, int priority)
          Removes the first occurrence of the specified element with the given priority, if it is present.
 int size()
          Returns the number of elements in this queue.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PriorityQueue

public PriorityQueue(int maxPriority)
Creates an priority queue to store elements with priorities up to maxPriority.

Parameters:
maxPriority - the maximum priority given to an element in this queue
Method Detail

remove

public T remove()
Returns the element with the highest priority, removing it.

Returns:
the element with the highest priority, null if this queue is empty

getMinPriority

public int getMinPriority()
Returns the priority of the element with the highest prSmaller priority numbers represents higher priorities.iority.

Returns:
the priority of the element with the highest priority, -1 if this queue is empty

add

public void add(T element,
                int priority)
Appends the specified element to the queue with the given priority. Smaller priority numbers represents higher priorities.

Parameters:
element - element to be appended to this queue
priority - priority given to the element to be appended

remove

public void remove(T element,
                   int priority)
Removes the first occurrence of the specified element with the given priority, if it is present.

Parameters:
element - element to be removed from this queue
priority - priority of the element to be removed

isEmpty

public boolean isEmpty()
Returns true if this queue contains no elements.

Returns:
true if this queue contains no elements

size

public int size()
Returns the number of elements in this queue.

Returns:
the number of elements in this queue

clear

public void clear()
Removes all of the elements from this queue.