| Matching Statements |
| File1 Line# |
File2 Line# |
Statement |
| 8 | 7 | package java.util.concurrent |
| 10 | 9 | import java.util.concurrent.locks.* |
| 11 | 10 | import java.util.* |
| 39 | 68 | public class PriorityBlockingQueue<E> extends AbstractQueue<E> |
| 40 | 69 | implements BlockingQueue<E>, java.io.Serializable { |
| 41 | 70 | private static final long serialVersionUID = 5595510919245408276L |
| 43 | 72 | private final PriorityQueue<E> q |
| 44 | 73 | private final ReentrantLock lock = new ReentrantLock(true) |
| 45 | 74 | private final Condition notEmpty = lock.newCondition() |
| 53 | 81 | public PriorityBlockingQueue() { |
| 54 | 82 | q = new PriorityQueue<E>() |
| 67 | 94 | public PriorityBlockingQueue(int initialCapacity) { |
| 68 | 95 | q = new PriorityQueue<E>(initialCapacity, null) |
| 83 | 110 | public PriorityBlockingQueue(int initialCapacity, |
| 84 | 111 | Comparator<? super E> comparator) { |
| 85 | 112 | q = new PriorityQueue<E>(initialCapacity, comparator) |
| 107 | 131 | public PriorityBlockingQueue(Collection<? extends E> c) { |
| 108 | 132 | q = new PriorityQueue<E>(c) |
| 137 | 275 | public Comparator<? super E> comparator() { |
| 138 | 276 | return q.comparator() |
153 195 215 226 248 258 281 291 301 312 326 348 368 378 398 | 161 205 215 235 257 280 310 328 351 362 382 410 430 477 | final ReentrantLock lock = this.lock |
154 216 249 259 282 292 302 313 327 349 369 379 399 425 435 453 | 162 206 258 281 311 329 352 363 383 411 431 478 533 556 | lock.lock() |
| 157 | 165 | assert ok |
158 202 238 | 166 222 247 | notEmpty.signal() |
161 209 220 243 253 263 286 296 306 317 337 359 373 383 403 429 439 457 | 169 210 229 252 262 285 315 333 356 367 393 421 435 482 542 560 | lock.unlock() |
| 194 | 214 | public E take() throws InterruptedException { |
196 227 | 216 236 | lock.lockInterruptibly() |
| 199 | 219 | while (q.size() == 0) |
| 200 | 220 | notEmpty.await() |
201 237 | 221 246 | } catch (InterruptedException ie) { |
203 239 | 223 248 | throw ie |
205 230 | 225 239 | E x = q.poll() |
| 206 | 226 | assert x != null |
207 232 | 227 241 | return x |
| 214 | 204 | public E poll() { |
| 218 | 208 | return q.poll() |
| 224 | 233 | public E poll(long timeout, TimeUnit unit) throws InterruptedException { |
| 225 | 234 | long nanos = unit.toNanos(timeout) |
| 231 | 240 | if (x != null) |
| 233 | 242 | if (nanos <= 0) |
| 236 | 245 | nanos = notEmpty.awaitNanos(nanos) |
| 247 | 256 | public E peek() { |
| 251 | 260 | return q.peek() |
| 257 | 279 | public int size() { |
| 261 | 283 | return q.size() |
| 272 | 294 | public int remainingCapacity() { |
| 273 | 295 | return Integer.MAX_VALUE |
| 280 | 309 | public boolean remove(Object o) { |
| 284 | 313 | return q.remove(o) |
| 290 | 327 | public boolean contains(Object o) { |
| 294 | 331 | return q.contains(o) |
| 300 | 350 | public Object[] toArray() { |
| 304 | 354 | return q.toArray() |
| 311 | 361 | public String toString() { |
| 315 | 365 | return q.toString() |
| 321 | 377 | public int drainTo(Collection<? super E> c) { |
322 342 | 378 404 | if (c == null) |
323 343 | 379 405 | throw new NullPointerException() |
324 344 | 380 406 | if (c == this) |
325 345 | 381 407 | throw new IllegalArgumentException() |
329 351 | 385 413 | int n = 0 |
330 352 | 386 414 | E e |
| 331 | 387 | while ( (e = q.poll()) != null) { |
332 354 | 388 416 | c.add(e) |
333 355 | 389 417 | ++n |
335 357 | 391 419 | return n |
| 341 | 403 | public int drainTo(Collection<? super E> c, int maxElements) { |
| 346 | 408 | if (maxElements <= 0) |
| 347 | 409 | return 0 |
| 353 | 415 | while (n < maxElements && (e = q.poll()) != null) { |
| 367 | 429 | public void clear() { |
| 371 | 433 | q.clear() |
| 377 | 476 | public <T> T[] toArray(T[] a) { |
| 381 | 480 | return q.toArray(a) |
| 397 | 498 | public Iterator<E> iterator() { |
| 413 | 515 | public boolean hasNext() { |
| 423 | 519 | public E next() { |
| 433 | 526 | public void remove() { |
| 451 | 554 | private void writeObject(java.io.ObjectOutputStream s) |
| 452 | 555 | throws java.io.IOException { |
| 455 | 558 | s.defaultWriteObject() |
| Matching Comments and Strings |
| File1 Line# |
File2 Line# |
Comment/String |
| 14 | 17 | * An unbounded {@linkplain BlockingQueue blocking queue} that uses |
| 15 | 18 | * the same ordering rules as class {@link PriorityQueue} and supplies |
| 16 | 19 | * blocking retrieval operations. While this queue is logically |
| 17 | 20 | * unbounded, attempted additions may fail due to resource exhaustion |
| 18 | 21 | * (causing <tt>OutOfMemoryError</tt>). This class does not permit |
| 23 | 27 | * <p>This class and its iterator implement all of the |
| 24 | 28 | * <em>optional</em> methods of the {@link Collection} and {@link |
| 35 | 64 | * @since 1.5 |
| 36 | 65 | * @author Doug Lea |
| 37 | 66 | * @param <E> the type of elements held in this collection |
58 72 | 99 | * Creates a <tt>PriorityBlockingQueue</tt> with the specified initial |
64 80 | 91 107 | * @throws IllegalArgumentException if <tt>initialCapacity</tt> is less |
65 81 | 92 108 | * than 1 |
| 89 | 116 | * Creates a <tt>PriorityBlockingQueue</tt> containing the elements |
| 99 | 123 | * @param c the collection whose elements are to be placed |
| 101 | 125 | * @throws ClassCastException if elements of the specified collection |
| 102 | 126 | * cannot be compared to one another according to the priority |
121 146 | 140 155 178 195 | * @throws ClassCastException if the specified element cannot be compared |
| 142 | 136 151 | * Inserts the specified element into this priority queue. |
145 184 | 194 | * @return <tt>true</tt> |
167 180 | 175 189 | * unbounded this method will never block. |
175 191 | 184 201 | never need to block |
| 179 | 174 188 | * Inserts the specified element into this priority queue. As the queue is |
| 182 | 192 | * @param timeout This parameter is ignored as the method never blocks |
| 183 | 193 | * @param unit This parameter is ignored as the method never blocks |
202 238 | 222 247 | propagate to non-interrupted thread |
| 268 | 290 | * Always returns <tt>Integer.MAX_VALUE</tt> because |
| 269 | 291 | * a <tt>PriorityBlockingQueue</tt> is not capacity constrained. |
| 270 | 292 | * @return <tt>Integer.MAX_VALUE</tt> |
| 364 | 426 | * Atomically removes all of the elements from this queue. |
| 365 | 427 | * The queue will be empty after this call returns. |
| 388 | 487 | * Returns an iterator over the elements in this queue. The |
| 389 | 488 | * iterator does not return the elements in any particular order. |
| 446 | 549 | * merely wraps default serialization within lock. The |
| 447 | 550 | * serialization strategy for items is left to underlying |
| 448 | 551 | * Queue. Note that locking is not needed on deserialization, so |
| 449 | 552 | * readObject is not defined, just relying on default. |