21 |
|
* |
22 |
|
* <p>This class and its iterator implement all of the |
23 |
|
* <em>optional</em> methods of the {@link Collection} and {@link |
24 |
< |
* Iterator} interfaces. |
25 |
< |
* The Iterator provided in method {@link #iterator()} is |
26 |
< |
* <em>not</em> guaranteed to traverse the elements of the |
27 |
< |
* PriorityBlockingQueue in any particular order. If you need ordered |
28 |
< |
* traversal, consider using <tt>Arrays.sort(pq.toArray())</tt>. |
24 |
> |
* Iterator} interfaces. The Iterator provided in method {@link |
25 |
> |
* #iterator()} is <em>not</em> guaranteed to traverse the elements of |
26 |
> |
* the PriorityBlockingQueue in any particular order. If you need |
27 |
> |
* ordered traversal, consider using |
28 |
> |
* <tt>Arrays.sort(pq.toArray())</tt>. Also, method <tt>drainTo</tt> |
29 |
> |
* can be used to <em>remove</em> some or all elements in priority |
30 |
> |
* order and place them in another collection. |
31 |
> |
* |
32 |
> |
* <p>Operations on this class make no guarantees about the ordering |
33 |
> |
* of elements with equal priority. If you need to enforce an |
34 |
> |
* ordering, you can define custom classes or comparators that use a |
35 |
> |
* secondary key to break ties in primary priority values. For |
36 |
> |
* example, here is a class that applies first-in-first-out |
37 |
> |
* tie-breaking to comparable elements. To use it, you would insert a |
38 |
> |
* <tt>new FIFOEntry(anEntry)</tt> instead of a plain entry object. |
39 |
> |
* |
40 |
> |
* <pre> |
41 |
> |
* class FIFOEntry<E extends Comparable<? super E>> |
42 |
> |
* implements Comparable<FIFOEntry<E>> { |
43 |
> |
* static AtomicLong seq = new AtomicLong(); |
44 |
> |
* final long seqNum; |
45 |
> |
* final E entry; |
46 |
> |
* public FIFOEntry(E entry) { |
47 |
> |
* seqNum = seq.getAndIncrement(); |
48 |
> |
* this.entry = entry; |
49 |
> |
* } |
50 |
> |
* public E getEntry() { return entry; } |
51 |
> |
* public int compareTo(FIFOEntry<E> other) { |
52 |
> |
* int res = entry.compareTo(other.entry); |
53 |
> |
* if (res == 0 && other.entry != this.entry) |
54 |
> |
* res = (seqNum < other.seqNum ? -1 : 1); |
55 |
> |
* return res; |
56 |
> |
* } |
57 |
> |
* } |
58 |
> |
* </pre> |
59 |
|
* |
60 |
|
* <p>This class is a member of the |
61 |
|
* <a href="{@docRoot}/../guide/collections/index.html"> |