CubeTwister 2.0alpha141 2011-10-13

ch.randelshofer.util
Class PriorityQueue

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList
          extended by ch.randelshofer.util.PriorityQueue
All Implemented Interfaces:
java.io.Serializable, java.lang.Iterable, java.util.Collection, java.util.List

public class PriorityQueue
extends java.util.AbstractList
implements java.io.Serializable

JDCTechTips 2002-08-22. John Zukowski.

Author:
Werner Randelshofer
See Also:
Serialized Form

Field Summary
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
PriorityQueue()
          Constructs an empty priority queue which supports the priorities 0 to 9 (10 distinct priorities).
PriorityQueue(java.util.Collection col)
          Constructs a priority queue containing the elements of the specified collection, in the order they are returned by the collection'siterator.
PriorityQueue(java.util.Collection col, int count)
          Constructs a priority queue containing the elements of the specified collection, in the order they are returned by the collection'siterator.
PriorityQueue(int count)
          Constructs an empty priority queue which supports the specified count of priorities.
 
Method Summary
 boolean add(java.lang.Object element)
          Inserts an element to the priority queue using priority 0 (the lowest priority).
 void clear()
          Removes all of the elements from this priority queue.
 java.lang.Object get(int index)
          Returns the element at the specified position in this priority queue.
 java.lang.Object getFirst()
          Returns the first element in this priority queue.
 int getPriorityCount()
          Returns the priority count.
 void insert(java.lang.Object element, int priority)
          Inserts an element to the priority queue using the specified priority.
 java.util.Iterator iterator()
          Returns an iterator of the elements in this priority queue (elements with higher priorities first).
 java.lang.Object removeFirst()
          Returns the first element in this priority queue and returns it.
 int size()
          Returns the number of elements in this priority queue.
 java.lang.String toString()
          Returns a string representation of this collection.
 
Methods inherited from class java.util.AbstractList
add, addAll, equals, hashCode, indexOf, lastIndexOf, listIterator, listIterator, remove, removeRange, set, subList
 
Methods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray
 

Constructor Detail

PriorityQueue

public PriorityQueue()
Constructs an empty priority queue which supports the priorities 0 to 9 (10 distinct priorities).


PriorityQueue

public PriorityQueue(java.util.Collection col)
Constructs a priority queue containing the elements of the specified collection, in the order they are returned by the collection'siterator. The created PriorityQueue supports the priorities 0 to 9 (10 distinct priorities). All elements are added using priority 0 (the lowest priority).


PriorityQueue

public PriorityQueue(int count)
Constructs an empty priority queue which supports the specified count of priorities.


PriorityQueue

public PriorityQueue(java.util.Collection col,
                     int count)
Constructs a priority queue containing the elements of the specified collection, in the order they are returned by the collection'siterator. The created PriorityQueue supports count distinct priorities. All elements are added using priority 0 (the lowest priority).

Throws:
java.lang.IllegalArgumentException - if the specified priority count is is out of range count < 0.
Method Detail

add

public boolean add(java.lang.Object element)
Inserts an element to the priority queue using priority 0 (the lowest priority).

Specified by:
add in interface java.util.Collection
Specified by:
add in interface java.util.List
Overrides:
add in class java.util.AbstractList

getPriorityCount

public int getPriorityCount()
Returns the priority count.


insert

public void insert(java.lang.Object element,
                   int priority)
Inserts an element to the priority queue using the specified priority.

Throws:
java.lang.IllegalArgumentException - if the specified priority is is out of range (priority < 0 || priority >= getPriorityCount()).

getFirst

public java.lang.Object getFirst()
Returns the first element in this priority queue. Elements are returned highest priority first.


get

public java.lang.Object get(int index)
Returns the element at the specified position in this priority queue. The elements are ordered by priority.

Specified by:
get in interface java.util.List
Specified by:
get in class java.util.AbstractList
Throws:
java.lang.IndexOutOfBoundsException - if the specified index is is out of range (index < 0 || index >= size()).

clear

public void clear()
Removes all of the elements from this priority queue.

Specified by:
clear in interface java.util.Collection
Specified by:
clear in interface java.util.List
Overrides:
clear in class java.util.AbstractList

removeFirst

public java.lang.Object removeFirst()
Returns the first element in this priority queue and returns it. Elements are returned highest priority first.


size

public int size()
Returns the number of elements in this priority queue.

Specified by:
size in interface java.util.Collection
Specified by:
size in interface java.util.List
Specified by:
size in class java.util.AbstractCollection

iterator

public java.util.Iterator iterator()
Returns an iterator of the elements in this priority queue (elements with higher priorities first).

Specified by:
iterator in interface java.lang.Iterable
Specified by:
iterator in interface java.util.Collection
Specified by:
iterator in interface java.util.List
Overrides:
iterator in class java.util.AbstractList

toString

public java.lang.String toString()
Returns a string representation of this collection. The string representation consists of a list of the collection's elements in the order they are returned by its iterator, enclosed in square brackets ("[]"). Adjacent elements are separated by the characters ", " (comma and space). Elements are converted to strings as by String.valueOf(Object).

Overrides:
toString in class java.util.AbstractCollection

(c) Werner Randelshofer.
All rights reserved.