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.10 by tim, Thu Jul 31 14:43:27 2003 UTC vs.
Revision 1.17 by dl, Sat Sep 13 22:28:58 2003 UTC

# Line 7 | Line 7
7   package java.util;
8  
9   /**
10 < * <tt>AbstractQueue</tt> provides default implementations of
11 < * {@link #add add}, {@link #remove remove}, and {@link #element element}
12 < * based on
13 < * {@link #offer offer}, {@link #poll poll}, and {@link #peek peek},
14 < * respectively but that
15 < * throw exceptions instead of indicating failure via <tt>false</tt> or
10 > * This class provides skeletal implementations of some {@link Queue}
11 > * operations. The implementations in this class are appropriate when
12 > * the base implementation does <em>not</em> allow <tt>null</tt>
13 > * elements.  Methods {@link #add add}, {@link #remove remove}, and
14 > * {@link #element element} are based on {@link #offer offer}, {@link
15 > * #poll poll}, and {@link #peek peek}, respectively but throw
16 > * exceptions instead of indicating failure via <tt>false</tt> or
17   * <tt>null</tt> returns.
18 < * <p>The provided implementations all assume that the base implementation
19 < * does <em>not</em> allow <tt>null</tt> elements.
18 > *
19 > * <p> A <tt>Queue</tt> implementation that extends this class must
20 > * minimally define a method {@link Queue#offer} which does not permit
21 > * insertion of <tt>null</tt> elements, along with methods {@link
22 > * Queue#peek}, {@link Queue#poll}, {@link Collection#size}, and a
23 > * {@link Collection#iterator} supporting {@link
24 > * Iterator#remove}. Typically, additional methods will be overriden
25 > * as well. If these requirements cannot be met, consider instead
26 > * subclassing {@link AbstractCollection}.
27 > *
28   * @since 1.5
29   * @author Doug Lea
30   */
# Line 23 | Line 32 | public abstract class AbstractQueue<E>
32      extends AbstractCollection<E>
33      implements Queue<E> {
34  
35 <    // note that optional methods are not optional here or in our subclasses,
36 <    // so we redefine each optional method to document that it is not optional
37 <    // We also inherit, or define, all necessary @throws comments
35 >    /**
36 >     * Constructor for use by subclasses.
37 >     */
38 >    protected AbstractQueue() {
39 >    }
40 >
41  
42      /**
43 <     * Adds the specified element to this queue.
43 >     * Adds the specified element to this queue. This implementation
44 >     * returns <tt>true</tt> if <tt>offer</tt> succeeds, else
45 >     * throws an IllegalStateException.
46 >     *
47 >     * @param o the element
48       * @return <tt>true</tt> (as per the general contract of
49 <     * <tt>Collection.add</tt>).
49 >     *         <tt>Collection.add</tt>).
50       *
51 <     * @throws NullPointerException if the element is null
51 >     * @throws NullPointerException if the specified element is <tt>null</tt>
52 >     * @throws IllegalStateException if element cannot be added
53       */
54      public boolean add(E o) {
55          if (offer(o))
# Line 42 | Line 59 | public abstract class AbstractQueue<E>
59      }
60  
61      /**
62 <     * Adds all of the elements in the specified collection to this queue.
63 <     * The behavior of this operation is undefined if
64 <     * the specified collection is modified while the operation is in
48 <     * progress.  (This implies that the behavior of this call is undefined if
49 <     * the specified collection is this queue, and this queue is nonempty.)
50 <     * <p>
51 <     * This implementation iterates over the specified collection, and adds
52 <     * each object returned by the iterator to this collection, in turn.
53 <     *
54 <     * @param c collection whose elements are to be added to this queue
55 <     * @return <tt>true</tt> if this collection changed as a result of the
56 <     *         call.
57 <     * @throws NullPointerException if <tt>c</tt> is <tt>null</tt>
62 >     * Retrieves and removes the head of this queue.
63 >     * This implementation returns the result of <tt>poll</tt>
64 >     * unless the queue is empty.
65       *
66 +     * @return the head of this queue.
67 +     * @throws NoSuchElementException if this queue is empty.
68       */
60    public boolean addAll(Collection<? extends E> c) {
61        return super.addAll(c);
62    }
63
64    /** @throws NoSuchElementException {@inheritDoc} */
69      public E remove() {
70          E x = poll();
71          if (x != null)
# Line 70 | Line 74 | public abstract class AbstractQueue<E>
74              throw new NoSuchElementException();
75      }
76  
77 <    /** @throws NoSuchElementException {@inheritDoc} */
77 >
78 >    /**
79 >     * Retrieves, but does not remove, the head of this queue.  
80 >     * This implementation returns the result of <tt>peek</tt>
81 >     * unless the queue is empty.
82 >     *
83 >     * @return the head of this queue.
84 >     * @throws NoSuchElementException if this queue is empty.
85 >     */
86      public E element() {
87          E x = peek();
88          if (x != null)
# Line 89 | Line 101 | public abstract class AbstractQueue<E>
101          while (poll() != null)
102              ;
103      }
92
93    // XXX Remove this redundant declaration, pending response from Neal Gafter.
94    public abstract Iterator<E> iterator();
104   }
96
97
98
99
100

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines