All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class COM.objectspace.jgl.PriorityQueue

java.lang.Object
   |
   +----COM.objectspace.jgl.PriorityQueue

public class PriorityQueue
extends Object
implements Container
A PriorityQueue is an adapter that allows you to access items in a sorted order. It allows you to specify a comparator that is used to sort the items. The object with the highest priority will be the last item in the collection when sorted using the given comparator.

For example, the following code fragment:

   PriorityQueue pqueue = new PriorityQueue( new GreaterNumber() );
   pqueue.push( new Integer( 3 ) );
   pqueue.push( new Integer( 1 ) );
   pqueue.push( new Integer( 2 ) );
   while ( !pqueue.isEmpty() )
     System.out.println( "popped " + pqueue.pop() );
 
will have the resulting output:
   popped 1
   popped 2
   popped 3
 

A PriorityQueue accesses its underlying Array as a heap. This means that although objects will always pop in the order determined by the comparator, the objects are not necessarily stored in that order.

See Also:
Array, Heap, PriorityQueueExamples

Constructor Index

 o PriorityQueue()
Construct myself to be an empty PriorityQueue.
 o PriorityQueue(BinaryPredicate)
Construct myself to be an empty PriorityQueue.
 o PriorityQueue(PriorityQueue)
Construct myself to be a shallow copy of a specified PriorityQueue.

Method Index

 o add(Object)
Push an object.
 o clear()
Remove all of my objects.
 o clone()
Return a shallow copy of myself.
 o copy(PriorityQueue)
Become a shallow copy of a specified PriorityQueue.
 o elements()
Return an Enumeration of my elements.
 o equals(Object)
Return true if object is a PriorityQueue whose underlying sequence is equal to mine.
 o equals(PriorityQueue)
Return true if a specified PriorityQueue's sequence is equal to mine.
 o finish()
Return an iterator positioned immediately afer my last item.
 o getComparator()
Return my comparator.
 o hashCode()
Return my hash code for support of hashing containers
 o isEmpty()
Return true if I contain no objects.
 o maxSize()
Return the maximum number of objects that I can contain.
 o pop()
Pop the last object that was pushed onto me.
 o push(Object)
Push an object.
 o remove(Enumeration)
Remove the element at a particular position.
 o remove(Enumeration, Enumeration)
Remove the elements in the specified range.
 o size()
Return the number of objects that I contain.
 o start()
Return an iterator positioned at my first item.
 o swap(PriorityQueue)
Swap my contents with another PriorityQueue.
 o top()
Return my top object.
 o toString()
Return a string that describes me.

Constructors

 o PriorityQueue
 public PriorityQueue()
Construct myself to be an empty PriorityQueue. Order elements based on their hash code.

 o PriorityQueue
 public PriorityQueue(BinaryPredicate comparator)
Construct myself to be an empty PriorityQueue. Order elements using the specified comparator.

Parameters:
comparator - The comparator to be used for comparing elements.
 o PriorityQueue
 public PriorityQueue(PriorityQueue queue)
Construct myself to be a shallow copy of a specified PriorityQueue. A shallow copy is made of its underlying sequence.

Parameters:
queue - The instance of PriorityQueue to be copied.

Methods

 o toString
 public synchronized String toString()
Return a string that describes me. Although objects will always pop in the order determined by the comparator, the objects are not necessarily stored in that order; as a result, the order they appear in a String may not be in the expected order.

Overrides:
toString in class Object
 o clone
 public synchronized Object clone()
Return a shallow copy of myself.

Overrides:
clone in class Object
 o copy
 public synchronized void copy(PriorityQueue queue)
Become a shallow copy of a specified PriorityQueue. By underlying data structure becomes a shallow copy of the specified PriorityQueue's data structure.

Parameters:
queue - The PriorityQueue to be copied.
 o equals
 public boolean equals(Object object)
Return true if object is a PriorityQueue whose underlying sequence is equal to mine.

Parameters:
object - Any object.
Overrides:
equals in class Object
 o equals
 public synchronized boolean equals(PriorityQueue queue)
Return true if a specified PriorityQueue's sequence is equal to mine.

Parameters:
queue - The PriorityQueue to compare myself against.
 o hashCode
 public synchronized int hashCode()
Return my hash code for support of hashing containers

Overrides:
hashCode in class Object
 o isEmpty
 public boolean isEmpty()
Return true if I contain no objects.

 o size
 public int size()
Return the number of objects that I contain.

 o maxSize
 public int maxSize()
Return the maximum number of objects that I can contain.

 o clear
 public synchronized void clear()
Remove all of my objects.

 o getComparator
 public synchronized BinaryPredicate getComparator()
Return my comparator.

 o elements
 public synchronized Enumeration elements()
Return an Enumeration of my elements.

 o start
 public synchronized ForwardIterator start()
Return an iterator positioned at my first item.

 o finish
 public synchronized ForwardIterator finish()
Return an iterator positioned immediately afer my last item.

 o top
 public synchronized Object top()
Return my top object.

Throws: InvalidOperationException
If the PriorityQueue is empty.
 o add
 public Object add(Object object)
Push an object. Add always works so return null.

Parameters:
object - The object to push.
 o push
 public synchronized void push(Object object)
Push an object.

Parameters:
object - The object to push.
 o pop
 public synchronized Object pop()
Pop the last object that was pushed onto me.

Throws: InvalidOperationException
If the PriorityQueue is empty.
 o swap
 public synchronized void swap(PriorityQueue queue)
Swap my contents with another PriorityQueue.

Parameters:
queue - The PriorityQueue that I will swap my contents with.
 o remove
 public Object remove(Enumeration pos)
Remove the element at a particular position.

Parameters:
pos - The enumeration representing of the object to remove.
Throws: InvalidOperationException
Thrown by default.
 o remove
 public int remove(Enumeration first,
                   Enumeration last)
Remove the elements in the specified range.

Parameters:
pos - The enumeration representing of the object to remove.
Throws: InvalidOperationException
Thrown by default.

All Packages  Class Hierarchy  This Package  Previous  Next  Index