1 7 8 package java.util; 9 10 37 public abstract class AbstractQueue<E> 38 extends AbstractCollection <E> 39 implements Queue <E> { 40 41 44 protected AbstractQueue() { 45 } 46 47 48 60 public boolean add(E o) { 61 if (offer(o)) 62 return true; 63 else 64 throw new IllegalStateException ("Queue full"); 65 } 66 67 75 public E remove() { 76 E x = poll(); 77 if (x != null) 78 return x; 79 else 80 throw new NoSuchElementException (); 81 } 82 83 84 92 public E element() { 93 E x = peek(); 94 if (x != null) 95 return x; 96 else 97 throw new NoSuchElementException (); 98 } 99 100 106 public void clear() { 107 while (poll() != null) 108 ; 109 } 110 111 135 public boolean addAll(Collection <? extends E> c) { 136 if (c == null) 137 throw new NullPointerException (); 138 if (c == this) 139 throw new IllegalArgumentException (); 140 boolean modified = false; 141 Iterator <? extends E> e = c.iterator(); 142 while (e.hasNext()) { 143 if (add(e.next())) 144 modified = true; 145 } 146 return modified; 147 } 148 149 } 150 | Popular Tags |