[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.22, Tue Aug 5 12:11:08 2003 UTC revision 1.23, Wed Aug 6 01:57:53 2003 UTC
# Line 1  Line 1 
1   package java.util;   package java.util;
2    
3  /**  /**
4   * An unbounded priority queue based on a priority heap.  This queue orders   * An unbounded priority {@linkplain Queue queue} based on a priority heap.
5     * This queue orders
6   * elements according to an order specified at construction time, which is   * elements according to an order specified at construction time, which is
7   * specified in the same manner as {@link java.util.TreeSet} and   * specified in the same manner as {@link java.util.TreeSet} and
8   * {@link java.util.TreeMap}: elements are ordered   * {@link java.util.TreeMap}: elements are ordered
# Line 92  Line 93 
93       * (using <tt>Comparable</tt>.)       * (using <tt>Comparable</tt>.)
94       *       *
95       * @param initialCapacity the initial capacity for this priority queue.       * @param initialCapacity the initial capacity for this priority queue.
96         * @throws IllegalArgumentException if <tt>initialCapacity</tt> is less
97         * than 1
98       */       */
99      public PriorityQueue(int initialCapacity) {      public PriorityQueue(int initialCapacity) {
100          this(initialCapacity, null);          this(initialCapacity, null);
# Line 108  Line 111 
111       * @throws IllegalArgumentException if <tt>initialCapacity</tt> is less       * @throws IllegalArgumentException if <tt>initialCapacity</tt> is less
112       * than 1       * than 1
113       */       */
114      public PriorityQueue(int initialCapacity, Comparator<? super E> comparator) {      public PriorityQueue(int initialCapacity,
115                             Comparator<? super E> comparator) {
116          if (initialCapacity < 1)          if (initialCapacity < 1)
117              throw new IllegalArgumentException();              throw new IllegalArgumentException();
118          this.queue = new Object[initialCapacity + 1];          this.queue = new Object[initialCapacity + 1];
# Line 256  Line 260 
260    
261      // Queue Methods      // Queue Methods
262    
263    
264    
265      /**      /**
266       * Add the specified element to this priority queue.       * Add the specified element to this priority queue.
267       *       *
# Line 290  Line 296 
296          return (E) queue[1];          return (E) queue[1];
297      }      }
298    
299      // Collection Methods      // Collection Methods - the first two override to update docs
   
     // these first two override just to get the throws docs  
300    
301      /**      /**
302       * @throws NullPointerException if the specified element is <tt>null</tt>.       * Adds the specified element to this queue.
303         * @return <tt>true</tt> (as per the general contract of
304         * <tt>Collection.add</tt>).
305         *
306         * @throws NullPointerException {@inheritDoc}
307       * @throws ClassCastException if the specified element cannot be compared       * @throws ClassCastException if the specified element cannot be compared
308       * with elements currently in the priority queue according       * with elements currently in the priority queue according
309       * to the priority queue's ordering.       * to the priority queue's ordering.
# Line 304  Line 312 
312          return super.add(o);          return super.add(o);
313      }      }
314    
315    
316      /**      /**
317         * Adds all of the elements in the specified collection to this queue.
318         * The behavior of this operation is undefined if
319         * the specified collection is modified while the operation is in
320         * progress.  (This implies that the behavior of this call is undefined if
321         * the specified collection is this queue, and this queue is nonempty.)
322         * <p>
323         * This implementation iterates over the specified collection, and adds
324         * each object returned by the iterator to this collection, in turn.
325         * @throws NullPointerException {@inheritDoc}
326       * @throws ClassCastException if any element cannot be compared       * @throws ClassCastException if any element cannot be compared
327       * with elements currently in the priority queue according       * with elements currently in the priority queue according
328       * to the priority queue's ordering.       * to the priority queue's ordering.
      * @throws NullPointerException if <tt>c</tt> or any element in <tt>c</tt>  
      * is <tt>null</tt>  
329       */       */
330      public boolean addAll(Collection<? extends E> c) {      public boolean addAll(Collection<? extends E> c) {
331          return super.addAll(c);          return super.addAll(c);
332      }      }
333    
334    
335     /**
336         * Removes a single instance of the specified element from this
337         * queue, if it is present.  More formally,
338         * removes an element <tt>e</tt> such that <tt>(o==null ? e==null :
339         * o.equals(e))</tt>, if the queue contains one or more such
340         * elements.  Returns <tt>true</tt> if the queue contained the
341         * specified element (or equivalently, if the queue changed as a
342         * result of the call).
343         *
344         * <p>This implementation iterates over the queue looking for the
345         * specified element.  If it finds the element, it removes the element
346         * from the queue using the iterator's remove method.<p>
347         *
348         */
349      public boolean remove(Object o) {      public boolean remove(Object o) {
350          if (o == null)          if (o == null)
351              return false;              return false;
# Line 337  Line 368 
368          return false;          return false;
369      }      }
370    
371        /**
372         * Returns an iterator over the elements in this queue. The iterator
373         * does not return the elements in any particular order.
374         *
375         * @return an iterator over the elements in this queue.
376         */
377      public Iterator<E> iterator() {      public Iterator<E> iterator() {
378          return new Itr();          return new Itr();
379      }      }
# Line 393  Line 430 
430          }          }
431      }      }
432    
     /**  
      * Returns the number of elements in this priority queue.  
      *  
      * @return the number of elements in this priority queue.  
      */  
433      public int size() {      public int size() {
434          return size;          return size;
435      }      }
# Line 495  Line 527 
527          }          }
528      }      }
529    
530    
531        /**
532         * Returns the comparator used to order this collection, or <tt>null</tt>
533         * if this collection is sorted according to its elements natural ordering
534         * (using <tt>Comparable</tt>.)
535         *
536         * @return the comparator used to order this collection, or <tt>null</tt>
537         * if this collection is sorted according to its elements natural ordering.
538         */
539      public Comparator<? super E> comparator() {      public Comparator<? super E> comparator() {
540          return comparator;          return comparator;
541      }      }

Legend:
Removed from v.1.22  
changed lines
  Added in v.1.23

Doug Lea
ViewVC Help
Powered by ViewVC 1.0.8