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

java.lang.Object
  extended by fi.joensuu.cs.tra.AssignablePriorityQueue<E>

public class AssignablePriorityQueue<E>
extends Object

AssignablePriorityQueue is a wrapper for java.util.PriorityQueue that allows specifying an float priority for each element. For example

  AssignablePriorityQueue apq =
    new AssignablePriorityQueue();
 
  apq.add("four", 4);
  apq.add("eighteen", 18);
  apq.add("gazillion", -1);
  apq.add("two", 2);

  String polled;
  while ((polled = apq.poll()) != null) {
    System.out.print(polled);
    System.out.print(" ");
  }
  System.out.println();
 
would produce
   gazillion two four eighteen
 

See Also:
PriorityQueue

Constructor Summary
AssignablePriorityQueue()
          Creates an AssignablePriorityQueue with the default initial capacity (11) that orders its elements according to the natural ordering of their assigned priorities.
AssignablePriorityQueue(int initialCapacity)
          Creates an AssignablePriorityQueue with the specified initial capacity (11) that orders its elements according to the natural ordering of their assigned priorities.
 
Method Summary
 boolean add(E element, float priority)
          Inserts a specified element to the priority queue with the specified priority.
 boolean add(float priority, E element)
          Deprecated. Use add(E element, float priority) instead.
 void clear()
          Remove all elements from the priority queue.
 Iterator<E> iterator()
          Returns an iterator over the elements in this queue.
 E peek()
          Retrieves, but does not remove, the head of this queue, returning null if this queue is empty.
 E poll()
          Removes and returns the head of this queue, or null if this queue is empty.
 int size()
          Returns the number of elements in this queue.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AssignablePriorityQueue

public AssignablePriorityQueue()
Creates an AssignablePriorityQueue with the default initial capacity (11) that orders its elements according to the natural ordering of their assigned priorities.


AssignablePriorityQueue

public AssignablePriorityQueue(int initialCapacity)
Creates an AssignablePriorityQueue with the specified initial capacity (11) that orders its elements according to the natural ordering of their assigned priorities.

Method Detail

add

public boolean add(float priority,
                   E element)
Deprecated. Use add(E element, float priority) instead.

Inserts a specified element to the priority queue with the specified priority.

Parameters:
priority - the priority to be assigned to the element
element - the element to be inserted
Throws:
NullPointerException - if the specified element is null

add

public boolean add(E element,
                   float priority)
Inserts a specified element to the priority queue with the specified priority.

Parameters:
priority - the priority to be assigned to the element
element - the element to be inserted
Throws:
NullPointerException - if the specified element is null

iterator

public Iterator<E> iterator()
Returns an iterator over the elements in this queue. The iterator does not return the elements in any particular order.

Returns:
an iterator over the elements in this queue.

size

public int size()
Returns the number of elements in this queue. If the queue contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.

Returns:
the number of elements in this collection.

clear

public void clear()
Remove all elements from the priority queue.


poll

public E poll()
Removes and returns the head of this queue, or null if this queue is empty.

Returns:
the head of this queue, or null if this queue is empty.

peek

public E peek()
Retrieves, but does not remove, the head of this queue, returning null if this queue is empty.

Returns:
the head of this queue, or null if this queue is empty.