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

Comparing jsr166/src/main/java/util/PriorityQueue.java (file contents):
Revision 1.8 by dl, Tue Jul 1 16:29:45 2003 UTC vs.
Revision 1.26 by tim, Fri Aug 8 20:05:07 2003 UTC

# Line 1 | Line 1
1   package java.util;
2  
3   /**
4 < * An unbounded priority queue based on a priority heap.  This queue orders
4 > * An unbounded priority {@linkplain Queue queue} based on a priority heap.  
5 > * This queue orders
6   * elements according to an order specified at construction time, which is
7 < * specified in the same manner as {@link TreeSet} and {@link TreeMap}: elements are ordered
7 > * specified in the same manner as {@link java.util.TreeSet} and
8 > * {@link java.util.TreeMap}: elements are ordered
9   * either according to their <i>natural order</i> (see {@link Comparable}), or
10 < * according to a {@link Comparator}, depending on which constructor is used.
11 < * The {@link #peek}, {@link #poll}, and {@link #remove} methods return the
12 < * minimal element with respect to the specified ordering.  If multiple
13 < * elements are tied for least value, no guarantees are made as to
14 < * which of these elements is returned.
10 > * according to a {@link java.util.Comparator}, depending on which
11 > * constructor is used.
12 > * <p>The <em>head</em> of this queue is the <em>least</em> element with
13 > * respect to the specified ordering.
14 > * If multiple elements are tied for least value, the
15 > * head is one of those elements. A priority queue does not permit
16 > * <tt>null</tt> elements.
17 > *
18 > * <p>The {@link #remove()} and {@link #poll()} methods remove and
19 > * return the head of the queue.
20 > *
21 > * <p>The {@link #element()} and {@link #peek()} methods return, but do
22 > * not delete, the head of the queue.
23   *
24   * <p>A priority queue has a <i>capacity</i>.  The capacity is the
25   * size of the array used internally to store the elements on the
26 < * queue.  It is always at least as large as the queue size.  As
26 > * queue.
27 > * It is always at least as large as the queue size.  As
28   * elements are added to a priority queue, its capacity grows
29   * automatically.  The details of the growth policy are not specified.
30   *
31 < *<p>Implementation note: this implementation provides O(log(n)) time
32 < *for the insertion methods (<tt>offer</tt>, <tt>poll</tt>,
33 < *<tt>remove()</tt> and <tt>add</tt>) methods; linear time for the
34 < *<tt>remove(Object)</tt> and <tt>contains(Object)</tt> methods; and
35 < *constant time for the retrieval methods (<tt>peek</tt>,
36 < *<tt>element</tt>, and <tt>size</tt>).
31 > * <p>Implementation note: this implementation provides O(log(n)) time
32 > * for the insertion methods (<tt>offer</tt>, <tt>poll</tt>,
33 > * <tt>remove()</tt> and <tt>add</tt>) methods; linear time for the
34 > * <tt>remove(Object)</tt> and <tt>contains(Object)</tt> methods; and
35 > * constant time for the retrieval methods (<tt>peek</tt>,
36 > * <tt>element</tt>, and <tt>size</tt>).
37   *
38   * <p>This class is a member of the
39   * <a href="{@docRoot}/../guide/collections/index.html">
# Line 31 | Line 42
42   * @author Josh Bloch
43   */
44   public class PriorityQueue<E> extends AbstractQueue<E>
45 <                              implements Queue<E>,
46 <                                         java.io.Serializable {
45 >    implements Queue<E>, java.io.Serializable {
46 >
47      private static final int DEFAULT_INITIAL_CAPACITY = 11;
48  
49      /**
# Line 48 | Line 59 | public class PriorityQueue<E> extends Ab
59       *
60       * queue.length must be >= 2, even if size == 0.
61       */
62 <    private transient E[] queue;
62 >    private transient Object[] queue;
63  
64      /**
65       * The number of elements in the priority queue.
# Line 59 | Line 70 | public class PriorityQueue<E> extends Ab
70       * The comparator, or null if priority queue uses elements'
71       * natural ordering.
72       */
73 <    private final Comparator<E> comparator;
73 >    private final Comparator<? super E> comparator;
74  
75      /**
76       * The number of times this priority queue has been
# Line 68 | Line 79 | public class PriorityQueue<E> extends Ab
79      private transient int modCount = 0;
80  
81      /**
82 <     * Create a new priority queue with the default initial capacity
82 >     * Creates a <tt>PriorityQueue</tt> with the default initial capacity
83       * (11) that orders its elements according to their natural
84 <     * ordering (using <tt>Comparable</tt>.)
84 >     * ordering (using <tt>Comparable</tt>).
85       */
86      public PriorityQueue() {
87 <        this(DEFAULT_INITIAL_CAPACITY);
87 >        this(DEFAULT_INITIAL_CAPACITY, null);
88      }
89  
90      /**
91 <     * Create a new priority queue with the specified initial capacity
91 >     * Creates a <tt>PriorityQueue</tt> with the specified initial capacity
92       * that orders its elements according to their natural ordering
93 <     * (using <tt>Comparable</tt>.)
93 >     * (using <tt>Comparable</tt>).
94       *
95       * @param initialCapacity the initial capacity for this priority queue.
96 +     * @throws IllegalArgumentException if <tt>initialCapacity</tt> is less
97 +     * than 1
98       */
99      public PriorityQueue(int initialCapacity) {
100          this(initialCapacity, null);
101      }
102  
103      /**
104 <     * Create a new priority queue with the specified initial capacity (11)
104 >     * Creates a <tt>PriorityQueue</tt> with the specified initial capacity
105       * that orders its elements according to the specified comparator.
106       *
107       * @param initialCapacity the initial capacity for this priority queue.
108       * @param comparator the comparator used to order this priority queue.
109 +     * If <tt>null</tt> then the order depends on the elements' natural
110 +     * ordering.
111 +     * @throws IllegalArgumentException if <tt>initialCapacity</tt> is less
112 +     * than 1
113       */
114 <    public PriorityQueue(int initialCapacity, Comparator<E> comparator) {
114 >    public PriorityQueue(int initialCapacity,
115 >                         Comparator<? super E> comparator) {
116          if (initialCapacity < 1)
117 <            initialCapacity = 1;
118 <        queue = new E[initialCapacity + 1];
117 >            throw new IllegalArgumentException();
118 >        this.queue = new Object[initialCapacity + 1];
119          this.comparator = comparator;
120      }
121  
122      /**
123 <     * Create a new priority queue containing the elements in the specified
124 <     * collection.  The priority queue has an initial capacity of 110% of the
107 <     * size of the specified collection. If the specified collection
108 <     * implements the {@link Sorted} interface, the priority queue will be
109 <     * sorted according to the same comparator, or according to its elements'
110 <     * natural order if the collection is sorted according to its elements'
111 <     * natural order.  If the specified collection does not implement
112 <     * <tt>Sorted</tt>, the priority queue is ordered according to
113 <     * its elements' natural order.
114 <     *
115 <     * @param initialElements the collection whose elements are to be placed
116 <     *        into this priority queue.
117 <     * @throws ClassCastException if elements of the specified collection
118 <     *         cannot be compared to one another according to the priority
119 <     *         queue's ordering.
120 <     * @throws NullPointerException if the specified collection or an
121 <     *         element of the specified collection is <tt>null</tt>.
123 >     * Common code to initialize underlying queue array across
124 >     * constructors below.
125       */
126 <    public PriorityQueue(Collection<E> initialElements) {
127 <        int sz = initialElements.size();
126 >    private void initializeArray(Collection<? extends E> c) {
127 >        int sz = c.size();
128          int initialCapacity = (int)Math.min((sz * 110L) / 100,
129                                              Integer.MAX_VALUE - 1);
130          if (initialCapacity < 1)
131              initialCapacity = 1;
129        queue = new E[initialCapacity + 1];
132  
133 +        this.queue = new Object[initialCapacity + 1];
134 +    }
135 +
136 +    /**
137 +     * Initially fill elements of the queue array under the
138 +     * knowledge that it is sorted or is another PQ, in which
139 +     * case we can just place the elements without fixups.
140 +     */
141 +    private void fillFromSorted(Collection<? extends E> c) {
142 +        for (Iterator<? extends E> i = c.iterator(); i.hasNext(); )
143 +            queue[++size] = i.next();
144 +    }
145 +
146 +
147 +    /**
148 +     * Initially fill elements of the queue array that is
149 +     * not to our knowledge sorted, so we must add them
150 +     * one by one.
151 +     */
152 +    private void fillFromUnsorted(Collection<? extends E> c) {
153 +        for (Iterator<? extends E> i = c.iterator(); i.hasNext(); )
154 +            add(i.next());
155 +    }
156  
157 <        if (initialElements instanceof Sorted) {
158 <            comparator = ((Sorted)initialElements).comparator();
159 <            for (Iterator<E> i = initialElements.iterator(); i.hasNext(); )
160 <                queue[++size] = i.next();
157 >    /**
158 >     * Creates a <tt>PriorityQueue</tt> containing the elements in the
159 >     * specified collection.  The priority queue has an initial
160 >     * capacity of 110% of the size of the specified collection or 1
161 >     * if the collection is empty.  If the specified collection is an
162 >     * instance of a {@link java.util.SortedSet} or is another
163 >     * <tt>PriorityQueue</tt>, the priority queue will be sorted
164 >     * according to the same comparator, or according to its elements'
165 >     * natural order if the collection is sorted according to its
166 >     * elements' natural order.  Otherwise, the priority queue is
167 >     * ordered according to its elements' natural order.
168 >     *
169 >     * @param c the collection whose elements are to be placed
170 >     *        into this priority queue.
171 >     * @throws ClassCastException if elements of the specified collection
172 >     *         cannot be compared to one another according to the priority
173 >     *         queue's ordering.
174 >     * @throws NullPointerException if <tt>c</tt> or any element within it
175 >     * is <tt>null</tt>
176 >     */
177 >    public PriorityQueue(Collection<? extends E> c) {
178 >        initializeArray(c);
179 >        if (c instanceof SortedSet<? extends E>) {
180 >            SortedSet<? extends E> s = (SortedSet<? extends E>) c;
181 >            comparator = (Comparator<? super E>)s.comparator();
182 >            fillFromSorted(s);
183 >        } else if (c instanceof PriorityQueue<? extends E>) {
184 >            PriorityQueue<? extends E> s = (PriorityQueue<? extends E>) c;
185 >            comparator = (Comparator<? super E>)s.comparator();
186 >            fillFromSorted(s);
187          } else {
188              comparator = null;
189 <            for (Iterator<E> i = initialElements.iterator(); i.hasNext(); )
139 <                add(i.next());
189 >            fillFromUnsorted(c);
190          }
191      }
192  
193 +    /**
194 +     * Creates a <tt>PriorityQueue</tt> containing the elements in the
195 +     * specified collection.  The priority queue has an initial
196 +     * capacity of 110% of the size of the specified collection or 1
197 +     * if the collection is empty.  This priority queue will be sorted
198 +     * according to the same comparator as the given collection, or
199 +     * according to its elements' natural order if the collection is
200 +     * sorted according to its elements' natural order.
201 +     *
202 +     * @param c the collection whose elements are to be placed
203 +     *        into this priority queue.
204 +     * @throws ClassCastException if elements of the specified collection
205 +     *         cannot be compared to one another according to the priority
206 +     *         queue's ordering.
207 +     * @throws NullPointerException if <tt>c</tt> or any element within it
208 +     * is <tt>null</tt>
209 +     */
210 +    public PriorityQueue(PriorityQueue<? extends E> c) {
211 +        initializeArray(c);
212 +        comparator = (Comparator<? super E>)c.comparator();
213 +        fillFromSorted(c);
214 +    }
215 +
216 +    /**
217 +     * Creates a <tt>PriorityQueue</tt> containing the elements in the
218 +     * specified collection.  The priority queue has an initial
219 +     * capacity of 110% of the size of the specified collection or 1
220 +     * if the collection is empty.  This priority queue will be sorted
221 +     * according to the same comparator as the given collection, or
222 +     * according to its elements' natural order if the collection is
223 +     * sorted according to its elements' natural order.
224 +     *
225 +     * @param c the collection whose elements are to be placed
226 +     *        into this priority queue.
227 +     * @throws ClassCastException if elements of the specified collection
228 +     *         cannot be compared to one another according to the priority
229 +     *         queue's ordering.
230 +     * @throws NullPointerException if <tt>c</tt> or any element within it
231 +     * is <tt>null</tt>
232 +     */
233 +    public PriorityQueue(SortedSet<? extends E> c) {
234 +        initializeArray(c);
235 +        comparator = (Comparator<? super E>)c.comparator();
236 +        fillFromSorted(c);
237 +    }
238 +
239 +    /**
240 +     * Resize array, if necessary, to be able to hold given index
241 +     */
242 +    private void grow(int index) {
243 +        int newlen = queue.length;
244 +        if (index < newlen) // don't need to grow
245 +            return;
246 +        if (index == Integer.MAX_VALUE)
247 +            throw new OutOfMemoryError();
248 +        while (newlen <= index) {
249 +            if (newlen >= Integer.MAX_VALUE / 2)  // avoid overflow
250 +                newlen = Integer.MAX_VALUE;
251 +            else
252 +                newlen <<= 2;
253 +        }
254 +        Object[] newQueue = new Object[newlen];
255 +        System.arraycopy(queue, 0, newQueue, 0, queue.length);
256 +        queue = newQueue;
257 +    }
258 +            
259      // Queue Methods
260  
261 +
262 +
263      /**
264 <     * Remove and return the minimal element from this priority queue
147 <     * if it contains one or more elements, otherwise return
148 <     * <tt>null</tt>.  The term <i>minimal</i> is defined according to
149 <     * this priority queue's order.
264 >     * Add the specified element to this priority queue.
265       *
266 <     * @return the minimal element from this priority queue if it contains
267 <     *         one or more elements, otherwise <tt>null</tt>.
266 >     * @return <tt>true</tt>
267 >     * @throws ClassCastException if the specified element cannot be compared
268 >     * with elements currently in the priority queue according
269 >     * to the priority queue's ordering.
270 >     * @throws NullPointerException if the specified element is <tt>null</tt>.
271       */
272 +    public boolean offer(E o) {
273 +        if (o == null)
274 +            throw new NullPointerException();
275 +        modCount++;
276 +        ++size;
277 +
278 +        // Grow backing store if necessary
279 +        if (size >= queue.length)
280 +            grow(size);
281 +
282 +        queue[size] = o;
283 +        fixUp(size);
284 +        return true;
285 +    }
286 +
287      public E poll() {
288          if (size == 0)
289              return null;
290 <        return remove(1);
290 >        return (E) remove(1);
291 >    }
292 >
293 >    public E peek() {
294 >        return (E) queue[1];
295      }
296  
297 +    // Collection Methods - the first two override to update docs
298 +
299      /**
300 <     * Return, but do not remove, the minimal element from the
301 <     * priority queue, or return <tt>null</tt> if the queue is empty.
302 <     * The term <i>minimal</i> is defined according to this priority
164 <     * queue's order.  This method returns the same object reference
165 <     * that would be returned by by the <tt>poll</tt> method.  The two
166 <     * methods differ in that this method does not remove the element
167 <     * from the priority queue.
300 >     * Adds the specified element to this queue.
301 >     * @return <tt>true</tt> (as per the general contract of
302 >     * <tt>Collection.add</tt>).
303       *
304 <     * @return the minimal element from this priority queue if it contains
305 <     *         one or more elements, otherwise <tt>null</tt>.
304 >     * @throws NullPointerException {@inheritDoc}
305 >     * @throws ClassCastException if the specified element cannot be compared
306 >     * with elements currently in the priority queue according
307 >     * to the priority queue's ordering.
308       */
309 <    public E peek() {
310 <        return queue[1];
309 >    public boolean add(E o) {
310 >        return super.add(o);
311      }
312  
313 <    // Collection Methods
177 <
313 >  
314      /**
315 <     * Removes a single instance of the specified element from this priority
316 <     * queue, if it is present.  Returns true if this collection contained the
317 <     * specified element (or equivalently, if this collection changed as a
315 >     * Adds all of the elements in the specified collection to this queue.
316 >     * The behavior of this operation is undefined if
317 >     * the specified collection is modified while the operation is in
318 >     * progress.  (This implies that the behavior of this call is undefined if
319 >     * the specified collection is this queue, and this queue is nonempty.)
320 >     * <p>
321 >     * This implementation iterates over the specified collection, and adds
322 >     * each object returned by the iterator to this collection, in turn.
323 >     * @throws NullPointerException {@inheritDoc}
324 >     * @throws ClassCastException if any element cannot be compared
325 >     * with elements currently in the priority queue according
326 >     * to the priority queue's ordering.
327 >     */
328 >    public boolean addAll(Collection<? extends E> c) {
329 >        return super.addAll(c);
330 >    }
331 >
332 >
333 > /**
334 >     * Removes a single instance of the specified element from this
335 >     * queue, if it is present.  More formally,
336 >     * removes an element <tt>e</tt> such that <tt>(o==null ? e==null :
337 >     * o.equals(e))</tt>, if the queue contains one or more such
338 >     * elements.  Returns <tt>true</tt> if the queue contained the
339 >     * specified element (or equivalently, if the queue changed as a
340       * result of the call).
341       *
342 <     * @param element the element to be removed from this collection,
343 <     * if present.
344 <     * @return <tt>true</tt> if this collection changed as a result of the
345 <     *         call
188 <     * @throws ClassCastException if the specified element cannot be compared
189 <     *            with elements currently in the priority queue according
190 <     *            to the priority queue's ordering.
191 <     * @throws NullPointerException if the specified element is null.
342 >     * <p>This implementation iterates over the queue looking for the
343 >     * specified element.  If it finds the element, it removes the element
344 >     * from the queue using the iterator's remove method.<p>
345 >     *
346       */
347 <    public boolean remove(Object element) {
348 <        if (element == null)
349 <            throw new NullPointerException();
347 >    public boolean remove(Object o) {
348 >        if (o == null)
349 >            return false;
350  
351          if (comparator == null) {
352              for (int i = 1; i <= size; i++) {
353 <                if (((Comparable)queue[i]).compareTo(element) == 0) {
353 >                if (((Comparable<E>)queue[i]).compareTo((E)o) == 0) {
354                      remove(i);
355                      return true;
356                  }
357              }
358          } else {
359              for (int i = 1; i <= size; i++) {
360 <                if (comparator.compare(queue[i], (E) element) == 0) {
360 >                if (comparator.compare((E)queue[i], (E)o) == 0) {
361                      remove(i);
362                      return true;
363                  }
# Line 213 | Line 367 | public class PriorityQueue<E> extends Ab
367      }
368  
369      /**
370 <     * Returns an iterator over the elements in this priority queue.  The
371 <     * elements of the priority queue will be returned by this iterator in the
372 <     * order specified by the queue, which is to say the order they would be
373 <     * returned by repeated calls to <tt>poll</tt>.
220 <     *
221 <     * @return an <tt>Iterator</tt> over the elements in this priority queue.
370 >     * Returns an iterator over the elements in this queue. The iterator
371 >     * does not return the elements in any particular order.
372 >     *
373 >     * @return an iterator over the elements in this queue.
374       */
375      public Iterator<E> iterator() {
376          return new Itr();
# Line 253 | Line 405 | public class PriorityQueue<E> extends Ab
405              checkForComodification();
406              if (cursor > size)
407                  throw new NoSuchElementException();
408 <            E result = queue[cursor];
408 >            E result = (E) queue[cursor];
409              lastRet = cursor++;
410              return result;
411          }
# Line 276 | Line 428 | public class PriorityQueue<E> extends Ab
428          }
429      }
430  
279    /**
280     * Returns the number of elements in this priority queue.
281     *
282     * @return the number of elements in this priority queue.
283     */
431      public int size() {
432          return size;
433      }
434  
435      /**
289     * Add the specified element to this priority queue.
290     *
291     * @param element the element to add.
292     * @return true
293     * @throws ClassCastException if the specified element cannot be compared
294     *            with elements currently in the priority queue according
295     *            to the priority queue's ordering.
296     * @throws NullPointerException if the specified element is null.
297     */
298    public boolean offer(E element) {
299        if (element == null)
300            throw new NullPointerException();
301        modCount++;
302
303        // Grow backing store if necessary
304        if (++size == queue.length) {
305            E[] newQueue = new E[2 * queue.length];
306            System.arraycopy(queue, 0, newQueue, 0, size);
307            queue = newQueue;
308        }
309
310        queue[size] = element;
311        fixUp(size);
312        return true;
313    }
314
315    /**
436       * Remove all elements from the priority queue.
437       */
438      public void clear() {
# Line 336 | Line 456 | public class PriorityQueue<E> extends Ab
456          assert i <= size;
457          modCount++;
458  
459 <        E result = queue[i];
459 >        E result = (E) queue[i];
460          queue[i] = queue[size];
461          queue[size--] = null;  // Drop extra ref to prevent memory leak
462          if (i <= size)
# Line 357 | Line 477 | public class PriorityQueue<E> extends Ab
477          if (comparator == null) {
478              while (k > 1) {
479                  int j = k >> 1;
480 <                if (((Comparable)queue[j]).compareTo(queue[k]) <= 0)
480 >                if (((Comparable<E>)queue[j]).compareTo((E)queue[k]) <= 0)
481                      break;
482 <                E tmp = queue[j];  queue[j] = queue[k]; queue[k] = tmp;
482 >                Object tmp = queue[j];  queue[j] = queue[k]; queue[k] = tmp;
483                  k = j;
484              }
485          } else {
486              while (k > 1) {
487                  int j = k >> 1;
488 <                if (comparator.compare(queue[j], queue[k]) <= 0)
488 >                if (comparator.compare((E)queue[j], (E)queue[k]) <= 0)
489                      break;
490 <                E tmp = queue[j];  queue[j] = queue[k]; queue[k] = tmp;
490 >                Object tmp = queue[j];  queue[j] = queue[k]; queue[k] = tmp;
491                  k = j;
492              }
493          }
# Line 386 | Line 506 | public class PriorityQueue<E> extends Ab
506          int j;
507          if (comparator == null) {
508              while ((j = k << 1) <= size) {
509 <                if (j<size && ((Comparable)queue[j]).compareTo(queue[j+1]) > 0)
509 >                if (j<size && ((Comparable<E>)queue[j]).compareTo((E)queue[j+1]) > 0)
510                      j++; // j indexes smallest kid
511 <                if (((Comparable)queue[k]).compareTo(queue[j]) <= 0)
511 >                if (((Comparable<E>)queue[k]).compareTo((E)queue[j]) <= 0)
512                      break;
513 <                E tmp = queue[j];  queue[j] = queue[k]; queue[k] = tmp;
513 >                Object tmp = queue[j];  queue[j] = queue[k]; queue[k] = tmp;
514                  k = j;
515              }
516          } else {
517              while ((j = k << 1) <= size) {
518 <                if (j < size && comparator.compare(queue[j], queue[j+1]) > 0)
518 >                if (j < size && comparator.compare((E)queue[j], (E)queue[j+1]) > 0)
519                      j++; // j indexes smallest kid
520 <                if (comparator.compare(queue[k], queue[j]) <= 0)
520 >                if (comparator.compare((E)queue[k], (E)queue[j]) <= 0)
521                      break;
522 <                E tmp = queue[j];  queue[j] = queue[k]; queue[k] = tmp;
522 >                Object tmp = queue[j];  queue[j] = queue[k]; queue[k] = tmp;
523                  k = j;
524              }
525          }
526      }
527  
528 +
529      /**
530 <     * Returns the comparator associated with this priority queue, or
531 <     * <tt>null</tt> if it uses its elements' natural ordering.
530 >     * Returns the comparator used to order this collection, or <tt>null</tt>
531 >     * if this collection is sorted according to its elements natural ordering
532 >     * (using <tt>Comparable</tt>).
533       *
534 <     * @return the comparator associated with this priority queue, or
535 <     *         <tt>null</tt> if it uses its elements' natural ordering.
534 >     * @return the comparator used to order this collection, or <tt>null</tt>
535 >     * if this collection is sorted according to its elements natural ordering.
536       */
537 <    public Comparator comparator() {
537 >    public Comparator<? super E> comparator() {
538          return comparator;
539      }
540  
# Line 425 | Line 547 | public class PriorityQueue<E> extends Ab
547       * <tt>Object</tt>) in the proper order.
548       * @param s the stream
549       */
550 <    private synchronized void writeObject(java.io.ObjectOutputStream s)
550 >    private void writeObject(java.io.ObjectOutputStream s)
551          throws java.io.IOException{
552          // Write out element count, and any hidden stuff
553          s.defaultWriteObject();
# Line 443 | Line 565 | public class PriorityQueue<E> extends Ab
565       * deserialize it).
566       * @param s the stream
567       */
568 <    private synchronized void readObject(java.io.ObjectInputStream s)
568 >    private void readObject(java.io.ObjectInputStream s)
569          throws java.io.IOException, ClassNotFoundException {
570          // Read in size, and any hidden stuff
571          s.defaultReadObject();
572  
573          // Read in array length and allocate array
574          int arrayLength = s.readInt();
575 <        queue = new E[arrayLength];
575 >        queue = new Object[arrayLength];
576  
577          // Read in all elements in the proper order.
578          for (int i=0; i<size; i++)
579 <            queue[i] = (E)s.readObject();
579 >            queue[i] = s.readObject();
580      }
581  
582   }
583 +

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines