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
-
PriorityQueue()
- Construct myself to be an empty PriorityQueue.
-
PriorityQueue(BinaryPredicate)
- Construct myself to be an empty PriorityQueue.
-
PriorityQueue(PriorityQueue)
- Construct myself to be a shallow copy of a specified PriorityQueue.
-
add(Object)
- Push an object.
-
clear()
- Remove all of my objects.
-
clone()
- Return a shallow copy of myself.
-
copy(PriorityQueue)
- Become a shallow copy of a specified PriorityQueue.
-
elements()
- Return an Enumeration of my elements.
-
equals(Object)
- Return true if object is a PriorityQueue whose underlying sequence is equal to mine.
-
equals(PriorityQueue)
- Return true if a specified PriorityQueue's sequence is equal to mine.
-
finish()
- Return an iterator positioned immediately afer my last item.
-
getComparator()
- Return my comparator.
-
hashCode()
- Return my hash code for support of hashing containers
-
isEmpty()
- Return true if I contain no objects.
-
maxSize()
- Return the maximum number of objects that I can contain.
-
pop()
- Pop the last object that was pushed onto me.
-
push(Object)
- Push an object.
-
remove(Enumeration)
- Remove the element at a particular position.
-
remove(Enumeration, Enumeration)
- Remove the elements in the specified range.
-
size()
- Return the number of objects that I contain.
-
start()
- Return an iterator positioned at my first item.
-
swap(PriorityQueue)
- Swap my contents with another PriorityQueue.
-
top()
- Return my top object.
-
toString()
- Return a string that describes me.
PriorityQueue
public PriorityQueue()
- Construct myself to be an empty PriorityQueue.
Order elements based on their hash code.
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.
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.
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
clone
public synchronized Object clone()
- Return a shallow copy of myself.
- Overrides:
- clone in class Object
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.
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
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.
hashCode
public synchronized int hashCode()
- Return my hash code for support of hashing containers
- Overrides:
- hashCode in class Object
isEmpty
public boolean isEmpty()
- Return true if I contain no objects.
size
public int size()
- Return the number of objects that I contain.
maxSize
public int maxSize()
- Return the maximum number of objects that I can contain.
clear
public synchronized void clear()
- Remove all of my objects.
getComparator
public synchronized BinaryPredicate getComparator()
- Return my comparator.
elements
public synchronized Enumeration elements()
- Return an Enumeration of my elements.
start
public synchronized ForwardIterator start()
- Return an iterator positioned at my first item.
finish
public synchronized ForwardIterator finish()
- Return an iterator positioned immediately afer my last item.
top
public synchronized Object top()
- Return my top object.
- Throws: InvalidOperationException
- If the PriorityQueue is empty.
add
public Object add(Object object)
- Push an object. Add always works so return null.
- Parameters:
- object - The object to push.
push
public synchronized void push(Object object)
- Push an object.
- Parameters:
- object - The object to push.
pop
public synchronized Object pop()
- Pop the last object that was pushed onto me.
- Throws: InvalidOperationException
- If the PriorityQueue is empty.
swap
public synchronized void swap(PriorityQueue queue)
- Swap my contents with another PriorityQueue.
- Parameters:
- queue - The PriorityQueue that I will swap my contents with.
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.
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