ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/main/java/util/AbstractQueue.java
Revision: 1.8
Committed: Mon Jul 28 19:53:49 2003 UTC (20 years, 9 months ago) by tim
Branch: MAIN
Changes since 1.7: +2 -2 lines
Log Message:
Removed "throws NoSuchElementException" from signatures.

File Contents

# User Rev Content
1 dl 1.2 /*
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.
5     */
6    
7 tim 1.1 package java.util;
8    
9     /**
10     * AbstractQueue provides default implementations of add, remove, and
11     * element based on offer, poll, and peek, respectively but that throw
12     * exceptions instead of indicating failure via false or null returns.
13     * The provided implementations all assume that the base implementation
14 brian 1.3 * does <em>not</em> allow <tt>null</tt> elements.
15 dl 1.4 * @since 1.5
16     * @author Doug Lea
17 tim 1.1 */
18 tim 1.5
19 tim 1.1 public abstract class AbstractQueue<E> extends AbstractCollection<E> implements Queue<E> {
20    
21     public boolean add(E x) {
22     if (offer(x))
23     return true;
24     else
25     throw new IllegalStateException("Queue full");
26     }
27    
28 tim 1.8 public E remove() {
29 tim 1.1 E x = poll();
30     if (x != null)
31     return x;
32     else
33     throw new NoSuchElementException();
34     }
35    
36 tim 1.8 public E element() {
37 tim 1.1 E x = peek();
38     if (x != null)
39     return x;
40     else
41     throw new NoSuchElementException();
42     }
43    
44     public void clear() {
45     while (poll() != null)
46     ;
47     }
48    
49 tim 1.7 // XXX Remove this redundant declaration, pending response from Neal Gafter.
50 tim 1.5 public abstract Iterator<E> iterator();
51 tim 1.1 }
52 dholmes 1.6
53    
54    
55    
56