ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/main/java/util/concurrent/PriorityBlockingQueue.java
(Generate patch)

Comparing jsr166/src/main/java/util/concurrent/PriorityBlockingQueue.java (file contents):
Revision 1.40 by jsr166, Mon May 2 08:35:49 2005 UTC vs.
Revision 1.41 by dl, Sun May 8 21:49:27 2005 UTC

# Line 21 | Line 21 | import java.util.*;
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&lt;E extends Comparable&lt;? super E&gt;&gt;
42 > *    implements Comparable&lt;FIFOEntry&lt;E&gt;&gt; {
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&lt;E&gt; other) {
52 > *     int res = entry.compareTo(other.entry);
53 > *     if (res == 0 && other.entry != this.entry)
54 > *       res = (seqNum &lt; 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">

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines