24 |
|
*/ |
25 |
|
|
26 |
|
package java.util; |
27 |
+ |
|
28 |
|
import java.util.function.Consumer; |
29 |
|
import java.util.stream.Stream; |
29 |
– |
import java.util.stream.Streams; |
30 |
|
|
31 |
|
/** |
32 |
|
* An unbounded priority {@linkplain Queue queue} based on a priority heap. |
66 |
|
* java.util.concurrent.PriorityBlockingQueue} class. |
67 |
|
* |
68 |
|
* <p>Implementation note: this implementation provides |
69 |
< |
* O(log(n)) time for the enqueing and dequeing methods |
69 |
> |
* O(log(n)) time for the enqueuing and dequeuing methods |
70 |
|
* ({@code offer}, {@code poll}, {@code remove()} and {@code add}); |
71 |
|
* linear time for the {@code remove(Object)} and {@code contains(Object)} |
72 |
|
* methods; and constant time for the retrieval methods |
78 |
|
* |
79 |
|
* @since 1.5 |
80 |
|
* @author Josh Bloch, Doug Lea |
81 |
< |
* @param <E> the type of elements held in this collection |
81 |
> |
* @param <E> the type of elements held in this queue |
82 |
|
*/ |
83 |
|
public class PriorityQueue<E> extends AbstractQueue<E> |
84 |
|
implements java.io.Serializable { |
100 |
|
/** |
101 |
|
* The number of elements in the priority queue. |
102 |
|
*/ |
103 |
< |
private int size = 0; |
103 |
> |
private int size; |
104 |
|
|
105 |
|
/** |
106 |
|
* The comparator, or null if priority queue uses elements' |
394 |
|
* @return {@code true} if this queue contains the specified element |
395 |
|
*/ |
396 |
|
public boolean contains(Object o) { |
397 |
< |
return indexOf(o) != -1; |
397 |
> |
return indexOf(o) >= 0; |
398 |
|
} |
399 |
|
|
400 |
|
/** |
477 |
|
* Index (into queue array) of element to be returned by |
478 |
|
* subsequent call to next. |
479 |
|
*/ |
480 |
< |
private int cursor = 0; |
480 |
> |
private int cursor; |
481 |
|
|
482 |
|
/** |
483 |
|
* Index of element returned by most recent call to next, |
497 |
|
* We expect that most iterations, even those involving removals, |
498 |
|
* will not need to store elements in this field. |
499 |
|
*/ |
500 |
< |
private ArrayDeque<E> forgetMeNot = null; |
500 |
> |
private ArrayDeque<E> forgetMeNot; |
501 |
|
|
502 |
|
/** |
503 |
|
* Element returned by the most recent call to next iff that |
504 |
|
* element was drawn from the forgetMeNot list. |
505 |
|
*/ |
506 |
< |
private E lastRetElt = null; |
506 |
> |
private E lastRetElt; |
507 |
|
|
508 |
|
/** |
509 |
|
* The modCount value that the iterator believes that the backing |
744 |
|
* emitted (int), followed by all of its elements |
745 |
|
* (each an {@code Object}) in the proper order. |
746 |
|
* @param s the stream |
747 |
+ |
* @throws java.io.IOException if an I/O error occurs |
748 |
|
*/ |
749 |
|
private void writeObject(java.io.ObjectOutputStream s) |
750 |
|
throws java.io.IOException { |
764 |
|
* (that is, deserializes it). |
765 |
|
* |
766 |
|
* @param s the stream |
767 |
+ |
* @throws ClassNotFoundException if the class of a serialized object |
768 |
+ |
* could not be found |
769 |
+ |
* @throws java.io.IOException if an I/O error occurs |
770 |
|
*/ |
771 |
|
private void readObject(java.io.ObjectInputStream s) |
772 |
|
throws java.io.IOException, ClassNotFoundException { |