net.sf.jsort.queue
Class PriorityQueue

java.lang.Object
  extended by net.sf.jsort.queue.PriorityQueue
All Implemented Interfaces:
Queue

public final class PriorityQueue
extends java.lang.Object
implements Queue

The priority queue keeps the queue ordered by the "priority" of its elements.

The priority is defined by the comparison of each element with the relation of other elements (i.e. using the Comparable or Comparator interface).

Instances of this class are threadsafe.

Author:
Domingos Creado

Constructor Summary
PriorityQueue()
          Create a PriorityQueue that its elements will be instances of Comparable.
PriorityQueue(java.util.Collection elements)
          Create a PriorityQueue that its elements will be instances of Comparable.
PriorityQueue(java.util.Comparator comparator)
          Create an empty PriorityQueue.
PriorityQueue(java.util.Comparator comparator, java.util.Collection elements)
          Create an already populated PriorityQueue.
 
Method Summary
 void insert(java.lang.Object newElement)
          Insert the new element at queue.
 boolean isEmpty()
           
 java.lang.Object remove()
          Take a element from queue.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PriorityQueue

public PriorityQueue()
Create a PriorityQueue that its elements will be instances of Comparable.


PriorityQueue

public PriorityQueue(java.util.Collection elements)
Create a PriorityQueue that its elements will be instances of Comparable. It is started with the specified elements.


PriorityQueue

public PriorityQueue(java.util.Comparator comparator)
Create an empty PriorityQueue.

Parameters:
comparator - the priority calculation element

PriorityQueue

public PriorityQueue(java.util.Comparator comparator,
                     java.util.Collection elements)
Create an already populated PriorityQueue.

Parameters:
comparator - the priority calculation element
Method Detail

insert

public void insert(java.lang.Object newElement)
Description copied from interface: Queue
Insert the new element at queue.

Specified by:
insert in interface Queue

remove

public java.lang.Object remove()
Description copied from interface: Queue
Take a element from queue.

Specified by:
remove in interface Queue
Returns:

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface Queue
Returns:
if there is any element at queue.


Copyright © 2005-2008 Domingos Creado. All Rights Reserved.