fi.joensuu.cs.tra
Class PriorityQueue<E>

java.lang.Object
  extended by java.util.AbstractCollection
      extended by java.util.AbstractQueue
          extended by java.util.PriorityQueue
              extended by fi.joensuu.cs.tra.PriorityQueue
All Implemented Interfaces:
Collection, Iterable, Queue, Serializable

public class PriorityQueue<E>
extends PriorityQueue<E>

PriorityQueue is a convenience extension of java.util.PriorityQueue for relocation.

See Also:
PriorityQueue, Serialized Form

Constructor Summary
PriorityQueue()
          Creates a PriorityQueue with the default initial capacity (11) that orders its elements according to their natural ordering (using Comparable).
PriorityQueue(Collection<? extends E> c)
          Creates a PriorityQueue containing the elements in the specified collection.
PriorityQueue(int initialCapacity)
          Creates a PriorityQueue with the specified initial capacity that orders its elements according to their natural ordering (using Comparable).
PriorityQueue(int initialCapacity, Comparator<? super E> comparator)
          Creates a PriorityQueue with the specified initial capacity that orders its elements according to the specified comparator.
PriorityQueue(PriorityQueue<? extends E> c)
          Creates a PriorityQueue containing the elements in the specified collection.
PriorityQueue(SortedSet<? extends E> c)
          Creates a PriorityQueue containing the elements in the specified collection.
 
Method Summary
 boolean add(E o)
          Adds the specified element to this queue.
 void clear()
          Remove all elements from the priority queue.
 Comparator<? super E> comparator()
          Returns the comparator used to order this collection, or null if this collection is sorted according to its elements natural ordering (using Comparable).
 Iterator<E> iterator()
          Returns an iterator over the elements in this queue.
 E poll()
          Retrieves and removes the head of this queue, or null if this queue is empty.
 boolean remove(Object o)
          Removes a single instance of the specified element from this collection, if it is present (optional operation).
 int size()
          Returns the number of elements in this collection.
 
Methods inherited from class java.util.PriorityQueue
offer, peek
 
Methods inherited from class java.util.AbstractQueue
addAll, element, remove
 
Methods inherited from class java.util.AbstractCollection
contains, containsAll, isEmpty, removeAll, retainAll, toArray, toArray, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Queue
element, remove
 
Methods inherited from interface java.util.Collection
addAll, contains, containsAll, equals, hashCode, isEmpty, removeAll, retainAll, toArray, toArray
 

Constructor Detail

PriorityQueue

public PriorityQueue()
Creates a PriorityQueue with the default initial capacity (11) that orders its elements according to their natural ordering (using Comparable).


PriorityQueue

public PriorityQueue(int initialCapacity)
Creates a PriorityQueue with the specified initial capacity that orders its elements according to their natural ordering (using Comparable).

Parameters:
initialCapacity - the initial capacity for this priority queue.
Throws:
IllegalArgumentException - if initialCapacity is less than 1

PriorityQueue

public PriorityQueue(int initialCapacity,
                     Comparator<? super E> comparator)
Creates a PriorityQueue with the specified initial capacity that orders its elements according to the specified comparator.

Parameters:
initialCapacity - the initial capacity for this priority queue.
comparator - the comparator used to order this priority queue. If null then the order depends on the elements' natural ordering.
Throws:
IllegalArgumentException - if initialCapacity is less than 1

PriorityQueue

public PriorityQueue(Collection<? extends E> c)
Creates a PriorityQueue containing the elements in the specified collection. The priority queue has an initial capacity of 110% of the size of the specified collection or 1 if the collection is empty. If the specified collection is an instance of a java.util.SortedSet or is another PriorityQueue, the priority queue will be sorted according to the same comparator, or according to its elements' natural order if the collection is sorted according to its elements' natural order. Otherwise, the priority queue is ordered according to its elements' natural order.

Parameters:
c - the collection whose elements are to be placed into this priority queue.
Throws:
ClassCastException - if elements of the specified collection cannot be compared to one another according to the priority queue's ordering.
NullPointerException - if c or any element within it is null

PriorityQueue

public PriorityQueue(PriorityQueue<? extends E> c)
Creates a PriorityQueue containing the elements in the specified collection. The priority queue has an initial capacity of 110% of the size of the specified collection or 1 if the collection is empty. This priority queue will be sorted according to the same comparator as the given collection, or according to its elements' natural order if the collection is sorted according to its elements' natural order.

Parameters:
c - the collection whose elements are to be placed into this priority queue.
Throws:
ClassCastException - if elements of the specified collection cannot be compared to one another according to the priority queue's ordering.
NullPointerException - if c or any element within it is null

PriorityQueue

public PriorityQueue(SortedSet<? extends E> c)
Creates a PriorityQueue containing the elements in the specified collection. The priority queue has an initial capacity of 110% of the size of the specified collection or 1 if the collection is empty. This priority queue will be sorted according to the same comparator as the given collection, or according to its elements' natural order if the collection is sorted according to its elements' natural order.

Parameters:
c - the collection whose elements are to be placed into this priority queue.
Throws:
ClassCastException - if elements of the specified collection cannot be compared to one another according to the priority queue's ordering.
NullPointerException - if c or any element within it is null
Method Detail

add

public boolean add(E o)
Description copied from class: java.util.PriorityQueue
Adds the specified element to this queue.

Specified by:
add in interface Collection
Overrides:
add in class PriorityQueue
Parameters:
o - the element
Returns:
true (as per the general contract of Collection.add).

remove

public boolean remove(Object o)
Description copied from class: java.util.AbstractCollection
Removes a single instance of the specified element from this collection, if it is present (optional operation). More formally, removes an element e such that (o==null ? e==null : o.equals(e)), if the collection contains one or more such elements. Returns true if the collection contained the specified element (or equivalently, if the collection changed as a result of the call).

This implementation iterates over the collection looking for the specified element. If it finds the element, it removes the element from the collection using the iterator's remove method.

Note that this implementation throws an UnsupportedOperationException if the iterator returned by this collection's iterator method does not implement the remove method and this collection contains the specified object.

Specified by:
remove in interface Collection
Overrides:
remove in class PriorityQueue
Parameters:
o - element to be removed from this collection, if present.
Returns:
true if the collection contained the specified element.

iterator

public Iterator<E> iterator()
Description copied from class: java.util.PriorityQueue
Returns an iterator over the elements in this queue. The iterator does not return the elements in any particular order.

Specified by:
iterator in interface Collection
Overrides:
iterator in class PriorityQueue
Returns:
an iterator over the elements in this queue.

size

public int size()
Description copied from class: java.util.AbstractCollection
Returns the number of elements in this collection. If the collection contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.

Specified by:
size in interface Collection
Overrides:
size in class PriorityQueue
Returns:
the number of elements in this collection.

clear

public void clear()
Description copied from class: java.util.PriorityQueue
Remove all elements from the priority queue.

Specified by:
clear in interface Collection
Overrides:
clear in class PriorityQueue

poll

public E poll()
Description copied from interface: java.util.Queue
Retrieves and removes the head of this queue, or null if this queue is empty.

Specified by:
poll in interface Queue
Overrides:
poll in class PriorityQueue
Returns:
the head of this queue, or null if this queue is empty.

comparator

public Comparator<? super E> comparator()
Description copied from class: java.util.PriorityQueue
Returns the comparator used to order this collection, or null if this collection is sorted according to its elements natural ordering (using Comparable).

Overrides:
comparator in class PriorityQueue
Returns:
the comparator used to order this collection, or null if this collection is sorted according to its elements natural ordering.