[cvs] / jsr166 / src / main / java / util / PriorityQueue.java Repository:
ViewVC logotype

Diff of /jsr166/src/main/java/util/PriorityQueue.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.39, Sun Sep 7 15:06:19 2003 UTC revision 1.40, Fri Sep 12 15:38:26 2003 UTC
# Line 14  Line 14 
14   * and {@link java.util.TreeMap}: elements are ordered either according to   * and {@link java.util.TreeMap}: elements are ordered either according to
15   * their <i>natural order</i> (see {@link Comparable}), or according to a   * their <i>natural order</i> (see {@link Comparable}), or according to a
16   * {@link java.util.Comparator}, depending on which constructor is used.   * {@link java.util.Comparator}, depending on which constructor is used.
17     *
18   * <p>The <em>head</em> of this queue is the <em>least</em> element with   * <p>The <em>head</em> of this queue is the <em>least</em> element with
19   * respect to the specified ordering.  If multiple elements are tied for least   * respect to the specified ordering.  If multiple elements are tied for least
20   * value, the head is one of those elements. A priority queue does not permit   * value, the head is one of those elements. A priority queue does not permit
# Line 25  Line 26 
26   * <p>The {@link #element()} and {@link #peek()} methods return, but do   * <p>The {@link #element()} and {@link #peek()} methods return, but do
27   * not delete, the head of the queue.   * not delete, the head of the queue.
28   *   *
29   * <p>A priority queue has a <i>capacity</i>.  The capacity is the   * <p>A priority queue is unbounded, but has a <i>capacity</i>.  The
30   * size of the array used internally to store the elements on the   * capacity is the size of the array used internally to store the
31   * queue.   * elements on the queue.  It is always at least as large as the queue
32   * It is always at least as large as the queue size.  As   * size.  As elements are added to a priority queue, its capacity
33   * elements are added to a priority queue, its capacity grows   * grows automatically.  The details of the growth policy are not
34   * automatically.  The details of the growth policy are not specified.   * specified.
35   *   *
36   * <p>The Iterator provided in method {@link #iterator()} is <em>not</em>   * <p>The Iterator provided in method {@link #iterator()} is <em>not</em>
37   * guaranteed to traverse the elements of the PriorityQueue in any   * guaranteed to traverse the elements of the PriorityQueue in any
# Line 277  Line 278 
278      }      }
279    
280    
     // Queue Methods  
   
281      /**      /**
282       * Add the specified element to this priority queue.       * Inserts the specified element to this priority queue.
283       *       *
284       * @return <tt>true</tt>       * @return <tt>true</tt>
285       * @throws ClassCastException if the specified element cannot be compared       * @throws ClassCastException if the specified element cannot be compared
# Line 303  Line 302 
302          return true;          return true;
303      }      }
304    
305      public E poll() {      public E peek() {
306          if (size == 0)          if (size == 0)
307              return null;              return null;
         return remove();  
     }  
   
     public E peek() {  
308          return (E) queue[1];          return (E) queue[1];
309      }      }
310    
# Line 320  Line 315 
315       * @return <tt>true</tt> (as per the general contract of       * @return <tt>true</tt> (as per the general contract of
316       * <tt>Collection.add</tt>).       * <tt>Collection.add</tt>).
317       *       *
318       * @throws NullPointerException {@inheritDoc}       * @throws NullPointerException if the specified element is <tt>null</tt>.
319       * @throws ClassCastException if the specified element cannot be compared       * @throws ClassCastException if the specified element cannot be compared
320       * with elements currently in the priority queue according       * with elements currently in the priority queue according
321       * to the priority queue's ordering.       * to the priority queue's ordering.
# Line 339  Line 334 
334       * <p>       * <p>
335       * This implementation iterates over the specified collection, and adds       * This implementation iterates over the specified collection, and adds
336       * each object returned by the iterator to this collection, in turn.       * each object returned by the iterator to this collection, in turn.
337       * @throws NullPointerException {@inheritDoc}       * @param c collection whose elements are to be added to this queue
338         * @return <tt>true</tt> if this queue changed as a result of the
339         *         call.
340         * @throws NullPointerException if <tt>c</tt> or any element in <tt>c</tt>
341         * is <tt>null</tt>
342       * @throws ClassCastException if any element cannot be compared       * @throws ClassCastException if any element cannot be compared
343       * with elements currently in the priority queue according       * with elements currently in the priority queue according
344       * to the priority queue's ordering.       * to the priority queue's ordering.
# Line 348  Line 347 
347          return super.addAll(c);          return super.addAll(c);
348      }      }
349    
   
     /**  
      * Removes a single instance of the specified element from this  
      * queue, if it is present.  More formally,  
      * removes an element <tt>e</tt> such that <tt>(o==null ? e==null :  
      * o.equals(e))</tt>, if the queue contains one or more such  
      * elements.  Returns <tt>true</tt> if the queue contained the  
      * specified element (or equivalently, if the queue changed as a  
      * result of the call).  
      *  
      * <p>This implementation iterates over the queue looking for the  
      * specified element.  If it finds the element, it removes the element  
      * from the queue using the iterator's remove method.<p>  
      *  
      */  
350      public boolean remove(Object o) {      public boolean remove(Object o) {
351          if (o == null)          if (o == null)
352              return false;              return false;
# Line 506  Line 490 
490          size = 0;          size = 0;
491      }      }
492    
493      /**      public E poll() {
      * Removes and returns the first element from queue.  
      */  
     public E remove() {  
494          if (size == 0)          if (size == 0)
495              throw new NoSuchElementException();              return null;
496          modCount++;          modCount++;
497    
498          E result = (E) queue[1];          E result = (E) queue[1];

Legend:
Removed from v.1.39  
changed lines
  Added in v.1.40

Doug Lea
ViewVC Help
Powered by ViewVC 1.0.8