ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/main/java/util/AbstractQueue.java
(Generate patch)

Comparing jsr166/src/main/java/util/AbstractQueue.java (file contents):
Revision 1.19 by dl, Sun Oct 5 22:59:21 2003 UTC vs.
Revision 1.31 by jsr166, Mon Jul 18 19:14:17 2005 UTC

# Line 1 | Line 1
1   /*
2   * Written by Doug Lea with assistance from members of JCP JSR-166
3 < * Expert Group and released to the public domain. Use, modify, and
4 < * redistribute this code in any way without acknowledgement.
3 > * Expert Group and released to the public domain, as explained at
4 > * http://creativecommons.org/licenses/publicdomain
5   */
6  
7   package java.util;
8 + import java.util.*; // for javadoc (till 6280605 is fixed)
9  
10   /**
11   * This class provides skeletal implementations of some {@link Queue}
# Line 25 | Line 26 | package java.util;
26   * as well. If these requirements cannot be met, consider instead
27   * subclassing {@link AbstractCollection}.
28   *
29 + * <p>This class is a member of the
30 + * <a href="{@docRoot}/../guide/collections/index.html">
31 + * Java Collections Framework</a>.
32 + *
33   * @since 1.5
34   * @author Doug Lea
35 + * @param <E> the type of elements held in this collection
36   */
37   public abstract class AbstractQueue<E>
38      extends AbstractCollection<E>
# Line 38 | Line 44 | public abstract class AbstractQueue<E>
44      protected AbstractQueue() {
45      }
46  
41
47      /**
48 <     * Adds the specified element to this queue. This implementation
49 <     * returns <tt>true</tt> if <tt>offer</tt> succeeds, else
50 <     * throws an IllegalStateException.
51 <     *
47 <     * @param o the element
48 <     * @return <tt>true</tt> (as per the general contract of
49 <     *         <tt>Collection.add</tt>).
48 >     * Inserts the specified element into this queue if it is possible to do so
49 >     * immediately without violating capacity restrictions, returning
50 >     * <tt>true</tt> upon success and throwing an <tt>IllegalStateException</tt>
51 >     * if no space is currently available.
52       *
53 <     * @throws NullPointerException if the specified element is <tt>null</tt>
54 <     * @throws IllegalStateException if element cannot be added
53 >     * <p>This implementation returns <tt>true</tt> if <tt>offer</tt> succeeds,
54 >     * else throws an <tt>IllegalStateException</tt>.
55 >     *
56 >     * @param e the element to add
57 >     * @return <tt>true</tt> (as specified by {@link Collection#add})
58 >     * @throws IllegalStateException if the element cannot be added at this
59 >     *         time due to capacity restrictions
60 >     * @throws ClassCastException if the class of the specified element
61 >     *         prevents it from being added to this queue
62 >     * @throws NullPointerException if the specified element is null and
63 >     *         this queue not permit null elements
64 >     * @throws IllegalArgumentException if some property of this element
65 >     *         prevents it from being added to this queue
66       */
67 <    public boolean add(E o) {
68 <        if (offer(o))
67 >    public boolean add(E e) {
68 >        if (offer(e))
69              return true;
70          else
71              throw new IllegalStateException("Queue full");
72      }
73  
74      /**
75 <     * Retrieves and removes the head of this queue.
76 <     * This implementation returns the result of <tt>poll</tt>
75 >     * Retrieves and removes the head of this queue.  This method differs
76 >     * from {@link #poll poll} only in that it throws an exception if this
77 >     * queue is empty.
78 >     *
79 >     * <p>This implementation returns the result of <tt>poll</tt>
80       * unless the queue is empty.
81       *
82 <     * @return the head of this queue.
83 <     * @throws NoSuchElementException if this queue is empty.
82 >     * @return the head of this queue
83 >     * @throws NoSuchElementException if this queue is empty
84       */
85      public E remove() {
86          E x = poll();
# Line 74 | Line 90 | public abstract class AbstractQueue<E>
90              throw new NoSuchElementException();
91      }
92  
77
93      /**
94 <     * Retrieves, but does not remove, the head of this queue.  
95 <     * This implementation returns the result of <tt>peek</tt>
94 >     * Retrieves, but does not remove, the head of this queue.  This method
95 >     * differs from {@link #peek peek} only in that it throws an exception if
96 >     * this queue is empty.
97 >     *
98 >     * <p>This implementation returns the result of <tt>peek</tt>
99       * unless the queue is empty.
100       *
101 <     * @return the head of this queue.
102 <     * @throws NoSuchElementException if this queue is empty.
101 >     * @return the head of this queue
102 >     * @throws NoSuchElementException if this queue is empty
103       */
104      public E element() {
105          E x = peek();
# Line 92 | Line 110 | public abstract class AbstractQueue<E>
110      }
111  
112      /**
113 <     * Removes all of the elements from this collection.
114 <     * The collection will be empty after this call returns.
113 >     * Removes all of the elements from this queue.
114 >     * The queue will be empty after this call returns.
115 >     *
116       * <p>This implementation repeatedly invokes {@link #poll poll} until it
117       * returns <tt>null</tt>.
118       */
# Line 111 | Line 130 | public abstract class AbstractQueue<E>
130       *
131       * <p>This implementation iterates over the specified collection,
132       * and adds each element returned by the iterator to this
133 <     * collection, in turn.  A runtime exception encountered while
133 >     * queue, in turn.  A runtime exception encountered while
134       * trying to add an element (including, in particular, a
135       * <tt>null</tt> element) may result in only some of the elements
136       * having been successfully added when the associated exception is
137       * thrown.
138       *
139 <     * @param c collection whose elements are to be added to this collection.
140 <     * @return <tt>true</tt> if this collection changed as a result of the
141 <     *         call.
142 <     * @throws NullPointerException if the specified collection, or
143 <     * any of its elements are null.
144 <     * @throws IllegalArgumentException if c is this queue.
145 <     *
139 >     * @param c collection containing elements to be added to this queue
140 >     * @return <tt>true</tt> if this queue changed as a result of the call
141 >     * @throws ClassCastException if the class of an element of the specified
142 >     *         collection prevents it from being added to this queue
143 >     * @throws NullPointerException if the specified collection contains a
144 >     *         null element and this queue does not permit null elements,
145 >     *         or if the specified collection is null
146 >     * @throws IllegalArgumentException if some property of an element of the
147 >     *         specified collection prevents it from being added to this
148 >     *         queue, or if the specified collection is this queue
149 >     * @throws IllegalStateException if not all the elements can be added at
150 >     *         this time due to insertion restrictions
151       * @see #add(Object)
152       */
153      public boolean addAll(Collection<? extends E> c) {
# Line 131 | Line 155 | public abstract class AbstractQueue<E>
155              throw new NullPointerException();
156          if (c == this)
157              throw new IllegalArgumentException();
158 <        boolean modified = false;
159 <        Iterator<? extends E> e = c.iterator();
160 <        while (e.hasNext()) {
161 <            if (add(e.next()))
162 <                modified = true;
163 <        }
164 <        return modified;
158 >        boolean modified = false;
159 >        Iterator<? extends E> e = c.iterator();
160 >        while (e.hasNext()) {
161 >            if (add(e.next()))
162 >                modified = true;
163 >        }
164 >        return modified;
165      }
166  
167   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines