com.arsdigita.util
Class PriorityQueue

java.lang.Object
  extended bycom.arsdigita.util.PriorityQueue

public class PriorityQueue
extends Object

A simple priority queue that is implemented by a backing tree set. Ordering of the dequeues (ascending or descending) is specified at creation time. Note that this class defers synchronization to the user.

Since:
4.7
Version:
$Id: //core-platform/dev/src/com/arsdigita/util/PriorityQueue.java#8 $
Author:
Patrick McNeill

Constructor Summary
PriorityQueue()
          Creates a new PriorityQueue that orders dequeues in ascending order (lowest priority first)
PriorityQueue(boolean ascending)
          Creates a new PriorityQueue that orders dequeues in either ascending or descending order.
 
Method Summary
 Object dequeue()
          Return the next object in the queue, removing it from the queue.
 void enqueue(Object object, int priority)
          Adds a new object to the queue with a given priority.
 boolean isEmpty()
          Returns true if the queue is empty, false otherwise
 Object peek()
          Return the next object in the queue.
 void setAscending(boolean ascending)
          Changes the dequeue ordering.
 int size()
          Returns the number of objects in the queue
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PriorityQueue

public PriorityQueue()
Creates a new PriorityQueue that orders dequeues in ascending order (lowest priority first)


PriorityQueue

public PriorityQueue(boolean ascending)
Creates a new PriorityQueue that orders dequeues in either ascending or descending order.

Parameters:
ascending - true for ascending order, false otherwise
Method Detail

dequeue

public Object dequeue()
Return the next object in the queue, removing it from the queue.

Returns:
the next object in the queue
Throws:
NoSuchElementException - if the queue is empty

peek

public Object peek()
Return the next object in the queue.

Returns:
the next object in the queue
Throws:
NoSuchElementException - if the queue is empty

enqueue

public void enqueue(Object object,
                    int priority)
Adds a new object to the queue with a given priority.

Parameters:
object - the Object to add
priority - the Object's priority in the queue

isEmpty

public boolean isEmpty()
Returns true if the queue is empty, false otherwise

Returns:
true if the queue is empty, false otherwise

setAscending

public void setAscending(boolean ascending)
Changes the dequeue ordering.

Parameters:
ascending - true for ascending order, false for descending

size

public int size()
Returns the number of objects in the queue

Returns:
the number of objects in the queue


Copyright (c) 2004 Red Hat, Inc. Corporation. All Rights Reserved. Generated at July 20 2004:2337 UTC