ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/main/java/util/concurrent/PriorityBlockingQueue.java
Revision: 1.2
Committed: Tue May 27 18:14:40 2003 UTC (21 years ago) by dl
Branch: MAIN
Changes since 1.1: +58 -54 lines
Log Message:
re-check-in initial implementations

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.concurrent;
8     import java.util.*;
9    
10     /**
11 dl 1.2 * A blocking priority queue. Ordering follows the
12 tim 1.1 * java.util.Collection conventions: Either the elements must be
13     * Comparable, or a Comparator must be supplied. Elements with tied
14     * priorities are returned in arbitrary order. Comparison failures
15     * throw ClassCastExceptions during insertions and extractions.
16     **/
17 dl 1.2 public class PriorityBlockingQueue<E> extends AbstractBlockingQueueFromQueue<E>
18 tim 1.1 implements BlockingQueue<E>, java.io.Serializable {
19    
20 dl 1.2 /**
21     * Create a new priority queue with the default initial capacity (11)
22     * that orders its elements according to their natural ordering.
23     */
24     public PriorityBlockingQueue() {
25     super(new PriorityQueue<E>(), Integer.MAX_VALUE);
26     }
27    
28     /**
29     * Create a new priority queue with the specified initial capacity
30     * that orders its elements according to their natural ordering.
31     *
32     * @param initialCapacity the initial capacity for this priority queue.
33     */
34     public PriorityBlockingQueue(int initialCapacity) {
35     super(new PriorityQueue<E>(initialCapacity, null), Integer.MAX_VALUE);
36     }
37    
38     /**
39     * Create a new priority queue with the specified initial capacity (11)
40     * that orders its elements according to the specified comparator.
41     *
42     * @param initialCapacity the initial capacity for this priority queue.
43     * @param comparator the comparator used to order this priority queue.
44     */
45     public PriorityBlockingQueue(int initialCapacity, Comparator comparator) {
46     super(new PriorityQueue<E>(initialCapacity, comparator), Integer.MAX_VALUE);
47     }
48    
49     /**
50     * Create a new priority queue containing the elements in the specified
51     * collection. The priority queue has an initial capacity of 110% of the
52     * size of the specified collection. If the specified collection
53     * implements the {@link Sorted} interface, the priority queue will be
54     * sorted according to the same comparator, or according to its elements'
55     * natural order if the collection is sorted according to its elements'
56     * natural order. If the specified collection does not implement the
57     * <tt>Sorted</tt> interface, the priority queue is ordered according to
58     * its elements' natural order.
59     *
60     * @param initialElements the collection whose elements are to be placed
61     * into this priority queue.
62     * @throws ClassCastException if elements of the specified collection
63     * cannot be compared to one another according to the priority
64     * queue's ordering.
65     * @throws NullPointerException if the specified collection or an
66     * element of the specified collection is <tt>null</tt>.
67     */
68     public PriorityBlockingQueue(Collection<E> initialElements) {
69     super(new PriorityQueue<E>(initialElements), Integer.MAX_VALUE);
70 tim 1.1 }
71    
72     }