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

Comparing jsr166/src/main/java/util/concurrent/LinkedBlockingQueue.java (file contents):
Revision 1.13 by dholmes, Tue Aug 5 06:50:40 2003 UTC vs.
Revision 1.14 by dholmes, Wed Aug 6 01:57:53 2003 UTC

# Line 10 | Line 10 | import java.util.concurrent.locks.*;
10   import java.util.*;
11  
12   /**
13 < * An optionally-bounded {@link BlockingQueue blocking queue} based on
13 > * An optionally-bounded {@linkplain BlockingQueue blocking queue} based on
14   * linked nodes.
15   * This queue orders elements FIFO (first-in-first-out).
16   * The <em>head</em> of the queue is that element that has been on the
# Line 167 | Line 167 | public class LinkedBlockingQueue<E> exte
167  
168      /**
169       * Creates a <tt>LinkedBlockingQueue</tt> with a capacity of
170 <     * {@link Integer#MAX_VALUE}, initially holding the elements of the
170 >     * {@link Integer#MAX_VALUE}, initially containing the elements of the
171       * given collection,
172       * added in traversal order of the collection's iterator.
173       * @param c the collection of elements to initially contain
# Line 180 | Line 180 | public class LinkedBlockingQueue<E> exte
180              add(it.next());
181      }
182  
183 <
184 <    // Have to override just to update the javadoc for @throws
183 >    // Have to override just to update the javadoc
184  
185      /**
186 +     * Adds the specified element to the tail of this queue.
187 +     * @return <tt>true</tt> (as per the general contract of
188 +     * <tt>Collection.add</tt>).
189       * @throws IllegalStateException {@inheritDoc}
190       * @throws NullPointerException {@inheritDoc}
191       */
# Line 192 | Line 194 | public class LinkedBlockingQueue<E> exte
194      }
195  
196      /**
197 +     * Adds all of the elements in the specified collection to this queue.
198 +     * The behavior of this operation is undefined if
199 +     * the specified collection is modified while the operation is in
200 +     * progress.  (This implies that the behavior of this call is undefined if
201 +     * the specified collection is this queue, and this queue is nonempty.)
202 +     * <p>
203 +     * This implementation iterates over the specified collection, and adds
204 +     * each object returned by the iterator to this queue's tail, in turn.
205       * @throws IllegalStateException {@inheritDoc}
206       * @throws NullPointerException {@inheritDoc}
207       */
# Line 199 | Line 209 | public class LinkedBlockingQueue<E> exte
209          return super.addAll(c);
210      }
211  
202
212      // this doc comment is overridden to remove the reference to collections
213      // greater in size than Integer.MAX_VALUE
214      /**
# Line 231 | Line 240 | public class LinkedBlockingQueue<E> exte
240       * necessary for space to become available.
241       * @throws NullPointerException {@inheritDoc}
242       */
243 <    public void put(E x) throws InterruptedException {
244 <        if (x == null) throw new NullPointerException();
243 >    public void put(E o) throws InterruptedException {
244 >        if (o == null) throw new NullPointerException();
245          // Note: convention in all put/take/etc is to preset
246          // local var holding count  negative to indicate failure unless set.
247          int c = -1;
# Line 255 | Line 264 | public class LinkedBlockingQueue<E> exte
264                  notFull.signal(); // propagate to a non-interrupted thread
265                  throw ie;
266              }
267 <            insert(x);
267 >            insert(o);
268              c = count.getAndIncrement();
269              if (c + 1 < capacity)
270                  notFull.signal();
# Line 272 | Line 281 | public class LinkedBlockingQueue<E> exte
281       * necessary up to the specified wait time for space to become available.
282       * @throws NullPointerException {@inheritDoc}
283       */
284 <    public boolean offer(E x, long timeout, TimeUnit unit)
284 >    public boolean offer(E o, long timeout, TimeUnit unit)
285          throws InterruptedException {
286  
287 <        if (x == null) throw new NullPointerException();
287 >        if (o == null) throw new NullPointerException();
288          long nanos = unit.toNanos(timeout);
289          int c = -1;
290          putLock.lockInterruptibly();
291          try {
292              for (;;) {
293                  if (count.get() < capacity) {
294 <                    insert(x);
294 >                    insert(o);
295                      c = count.getAndIncrement();
296                      if (c + 1 < capacity)
297                          notFull.signal();
# Line 313 | Line 322 | public class LinkedBlockingQueue<E> exte
322      *
323      * @throws NullPointerException {@inheritDoc}
324      */
325 <    public boolean offer(E x) {
326 <        if (x == null) throw new NullPointerException();
325 >    public boolean offer(E o) {
326 >        if (o == null) throw new NullPointerException();
327          if (count.get() == capacity)
328              return false;
329          int c = -1;
330          putLock.lock();
331          try {
332              if (count.get() < capacity) {
333 <                insert(x);
333 >                insert(o);
334                  c = count.getAndIncrement();
335                  if (c + 1 < capacity)
336                      notFull.signal();
# Line 435 | Line 444 | public class LinkedBlockingQueue<E> exte
444          }
445      }
446  
447 +    /**
448 +     * Removes a single instance of the specified element from this
449 +     * queue, if it is present.  More formally,
450 +     * removes an element <tt>e</tt> such that <tt>(o==null ? e==null :
451 +     * o.equals(e))</tt>, if the queue contains one or more such
452 +     * elements.  Returns <tt>true</tt> if the queue contained the
453 +     * specified element (or equivalently, if the queue changed as a
454 +     * result of the call).
455 +     *
456 +     * <p>This implementation iterates over the queue looking for the
457 +     * specified element.  If it finds the element, it removes the element
458 +     * from the queue using the iterator's remove method.<p>
459 +     *
460 +     */
461      public boolean remove(Object o) {
462          if (o == null) return false;
463          boolean removed = false;
# Line 506 | Line 529 | public class LinkedBlockingQueue<E> exte
529          }
530      }
531  
532 +    /**
533 +     * Returns an iterator over the elements in this queue in proper sequence.
534 +     *
535 +     * @return an iterator over the elements in this queue in proper sequence.
536 +     */
537      public Iterator<E> iterator() {
538        return new Itr();
539      }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines