java.util
Class PriorityQueue<E>
- Collection<E>, Iterable<E>, Queue<E>, Serializable
boolean | addAll(E> c) - Adds all of the elements in the specified collection to this
queue.
|
void | clear() - Removes all of the elements from this queue.
|
Iterator | iterator() - Returns an iterator for the collection.
|
boolean | offer(E o) - Inserts the specified element into this queue if it is possible to do
so immediately without violating capacity restrictions.
|
E | peek() - Retrieves, but does not remove, the head of this queue,
or returns null if this queue is empty.
|
E | poll() - Retrieves and removes the head of this queue,
or returns null if this queue is empty.
|
boolean | remove(Object o)
|
int | size()
|
Comparator | super E> comparator()
|
T[] toArray , add , addAll , clear , contains , containsAll , isEmpty , iterator , remove , removeAll , retainAll , size , toArray , toString |
clone , equals , extends Object> getClass , finalize , hashCode , notify , notifyAll , toString , wait , wait , wait |
PriorityQueue
public PriorityQueue()
Constructor for use by subclasses.
addAll
public boolean addAll(E> c)
Adds all of the elements in the specified collection to this
queue. Attempts to addAll of a queue to itself result in
IllegalArgumentException. Further, the behavior of
this operation is undefined if the specified collection is
modified while the operation is in progress.
This implementation iterates over the specified collection,
and adds each element returned by the iterator to this
queue, in turn. A runtime exception encountered while
trying to add an element (including, in particular, a
null element) may result in only some of the elements
having been successfully added when the associated exception is
thrown.
- addAll in interface Collection<E>
- addAll in interface AbstractQueue<E>
c
- collection containing elements to be added to this queue
- true if this queue changed as a result of the call
ClassCastException
- if the class of an element of the specified
collection prevents it from being added to this queueNullPointerException
- if the specified collection contains a
null element and this queue does not permit null elements,
or if the specified collection is nullIllegalArgumentException
- if some property of an element of the
specified collection prevents it from being added to this
queue, or if the specified collection is this queueIllegalStateException
- if not all the elements can be added at
this time due to insertion restrictions
clear
public void clear()
Removes all of the elements from this queue.
The queue will be empty after this call returns.
This implementation repeatedly invokes
poll
until it
returns
null.
- clear in interface Collection<E>
- clear in interface AbstractQueue<E>
offer
public boolean offer(E o)
Inserts the specified element into this queue if it is possible to do
so immediately without violating capacity restrictions.
When using a capacity-restricted queue, this method is generally
preferable to
Queue.add(E)
, which can fail to insert an element only
by throwing an exception.
- offer in interface Queue<E>
- true if the element was added to this queue, else
false
peek
public E peek()
Retrieves, but does not remove, the head of this queue,
or returns null if this queue is empty.
- peek in interface Queue<E>
- the head of this queue, or null if this queue is empty
poll
public E poll()
Retrieves and removes the head of this queue,
or returns null if this queue is empty.
- poll in interface Queue<E>
- the head of this queue, or null if this queue is empty
PriorityQueue.java -- Unbounded priority queue
Copyright (C) 2004, 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version.