1 |
< |
package java.util.concurrent; |
1 |
> |
/* |
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 |
+ |
package java.util.concurrent; |
8 |
|
import java.util.*; |
9 |
|
|
10 |
|
/** |
11 |
< |
* An unbounded blocking priority queue. Ordering follows the |
11 |
> |
* A blocking priority queue. Ordering follows the |
12 |
|
* 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 |
< |
public class PriorityBlockingQueue<E> extends AbstractCollection<E> |
17 |
> |
public class PriorityBlockingQueue<E> extends AbstractBlockingQueueFromQueue<E> |
18 |
|
implements BlockingQueue<E>, java.io.Serializable { |
19 |
|
|
20 |
< |
public PriorityBlockingQueue() {} |
21 |
< |
public PriorityBlockingQueue(Comparator comparator) {} |
22 |
< |
|
23 |
< |
public void put(E x) { |
24 |
< |
} |
25 |
< |
public boolean offer(E x) { |
26 |
< |
return false; |
27 |
< |
} |
28 |
< |
public boolean remove(Object x) { |
29 |
< |
return false; |
30 |
< |
} |
31 |
< |
public E remove() { |
32 |
< |
return null; |
33 |
< |
} |
34 |
< |
|
35 |
< |
public E element() { |
36 |
< |
return null; |
37 |
< |
} |
38 |
< |
public boolean offer(E x, long timeout, TimeUnit granularity) { |
39 |
< |
return false; |
40 |
< |
} |
41 |
< |
public E take() throws InterruptedException { |
42 |
< |
return null; |
43 |
< |
} |
44 |
< |
public boolean add(E x) { |
45 |
< |
return false; |
46 |
< |
} |
47 |
< |
public E poll() { |
48 |
< |
return null; |
49 |
< |
} |
50 |
< |
public E poll(long timeout, TimeUnit granularity) throws InterruptedException { |
51 |
< |
return null; |
52 |
< |
} |
53 |
< |
public E peek() { |
54 |
< |
return null; |
55 |
< |
} |
56 |
< |
public boolean isEmpty() { |
57 |
< |
return false; |
58 |
< |
} |
59 |
< |
public int size() { |
60 |
< |
return 0; |
61 |
< |
} |
62 |
< |
public Object[] toArray() { |
63 |
< |
return null; |
64 |
< |
} |
65 |
< |
|
66 |
< |
public <T> T[] toArray(T[] array) { |
67 |
< |
return null; |
20 |
> |
/** |
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 |
|
} |
71 |
|
|
65 |
– |
public Iterator<E> iterator() { |
66 |
– |
return null; |
67 |
– |
} |
72 |
|
} |