[cvs] / jsr166 / src / main / java / util / PriorityQueue.java Repository:
ViewVC logotype

Diff of /jsr166/src/main/java/util/PriorityQueue.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.4, Mon May 19 02:45:07 2003 UTC revision 1.5, Tue May 27 18:20:06 2003 UTC
# Line 1  Line 1 
1   package java.util;   package java.util;
2    
 /*  
  * Todo  
  *  
  *   1) Make it serializable.  
  */  
   
3  /**  /**
4   * An unbounded priority queue based on a priority heap.  This queue orders   * An unbounded priority queue based on a priority heap.  This queue orders
5   * elements according to the order specified at creation time.  This order is   * elements according to the order specified at creation time.  This order is
# Line 51  Line 45 
45       *       *
46       * queue.length must be >= 2, even if size == 0.       * queue.length must be >= 2, even if size == 0.
47       */       */
48      private E[] queue;      private transient E[] queue;
49    
50      /**      /**
51       * The number of elements in the priority queue.       * The number of elements in the priority queue.
# Line 68  Line 62 
62       * The number of times this priority queue has been       * The number of times this priority queue has been
63       * <i>structurally modified</i>.  See AbstractList for gory details.       * <i>structurally modified</i>.  See AbstractList for gory details.
64       */       */
65      private int modCount = 0;      private transient int modCount = 0;
66    
67      /**      /**
68       * Create a new priority queue with the default initial capacity (11)       * Create a new priority queue with the default initial capacity (11)
# Line 129  Line 123 
123              initialCapacity = 1;              initialCapacity = 1;
124          queue = new E[initialCapacity + 1];          queue = new E[initialCapacity + 1];
125    
126            /* Commented out to compile with generics compiler
127    
128          if (initialElements instanceof Sorted) {          if (initialElements instanceof Sorted) {
129              comparator = ((Sorted)initialElements).comparator();              comparator = ((Sorted)initialElements).comparator();
130              for (Iterator<E> i = initialElements.iterator(); i.hasNext(); )              for (Iterator<E> i = initialElements.iterator(); i.hasNext(); )
131                  queue[++size] = i.next();                  queue[++size] = i.next();
132          } else {          } else {
133            */
134            {
135              comparator = null;              comparator = null;
136              for (Iterator<E> i = initialElements.iterator(); i.hasNext(); )              for (Iterator<E> i = initialElements.iterator(); i.hasNext(); )
137                  add(i.next());                  add(i.next());
# Line 408  Line 406 
406       * @return the comparator associated with this priority queue, or       * @return the comparator associated with this priority queue, or
407       *         <tt>null</tt> if it uses its elements' natural ordering.       *         <tt>null</tt> if it uses its elements' natural ordering.
408       */       */
409      Comparator<E> comparator() {      Comparator comparator() {
410          return comparator;          return comparator;
411      }      }
412    
413        /**
414         * Save the state of the instance to a stream (that
415         * is, serialize it).
416         *
417         * @serialData The length of the array backing the instance is
418         * emitted (int), followed by all of its elements (each an
419         * <tt>Object</tt>) in the proper order.
420         */
421        private synchronized void writeObject(java.io.ObjectOutputStream s)
422            throws java.io.IOException{
423            // Write out element count, and any hidden stuff
424            s.defaultWriteObject();
425    
426            // Write out array length
427            s.writeInt(queue.length);
428    
429            // Write out all elements in the proper order.
430            for (int i=0; i<size; i++)
431                s.writeObject(queue[i]);
432        }
433    
434        /**
435         * Reconstitute the <tt>ArrayList</tt> instance from a stream (that is,
436         * deserialize it).
437         */
438        private synchronized void readObject(java.io.ObjectInputStream s)
439            throws java.io.IOException, ClassNotFoundException {
440            // Read in size, and any hidden stuff
441            s.defaultReadObject();
442    
443            // Read in array length and allocate array
444            int arrayLength = s.readInt();
445            queue = new E[arrayLength];
446    
447            // Read in all elements in the proper order.
448            for (int i=0; i<size; i++)
449                queue[i] = (E)s.readObject();
450        }
451    
452  }  }

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.5

Doug Lea
ViewVC Help
Powered by ViewVC 1.0.8