[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.105, Fri Feb 27 19:01:11 2015 UTC revision 1.106, Tue Jun 16 23:06:01 2015 UTC
# Line 1  Line 1 
1  /*  /*
2   * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.   * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
3   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4   *   *
5   * This code is free software; you can redistribute it and/or modify it   * This code is free software; you can redistribute it and/or modify it
# Line 111  Line 111 
111       * The number of times this priority queue has been       * The number of times this priority queue has been
112       * <i>structurally modified</i>.  See AbstractList for gory details.       * <i>structurally modified</i>.  See AbstractList for gory details.
113       */       */
114      transient int modCount;     // non-private for nested class access      transient int modCount;     // non-private to simplify nested class access
115    
116      /**      /**
117       * Creates a {@code PriorityQueue} with the default initial       * Creates a {@code PriorityQueue} with the default initial
# Line 136  Line 136 
136      }      }
137    
138      /**      /**
139         * Creates a {@code PriorityQueue} with the default initial capacity and
140         * whose elements are ordered according to the specified comparator.
141         *
142         * @param  comparator the comparator that will be used to order this
143         *         priority queue.  If {@code null}, the {@linkplain Comparable
144         *         natural ordering} of the elements will be used.
145         * @since 1.8
146         */
147        public PriorityQueue(Comparator<? super E> comparator) {
148            this(DEFAULT_INITIAL_CAPACITY, comparator);
149        }
150    
151        /**
152       * Creates a {@code PriorityQueue} with the specified initial capacity       * Creates a {@code PriorityQueue} with the specified initial capacity
153       * that orders its elements according to the specified comparator.       * that orders its elements according to the specified comparator.
154       *       *
# Line 245  Line 258 
258              a = Arrays.copyOf(a, a.length, Object[].class);              a = Arrays.copyOf(a, a.length, Object[].class);
259          int len = a.length;          int len = a.length;
260          if (len == 1 || this.comparator != null)          if (len == 1 || this.comparator != null)
261              for (int i = 0; i < len; i++)              for (Object e : a)
262                  if (a[i] == null)                  if (e == null)
263                      throw new NullPointerException();                      throw new NullPointerException();
264          this.queue = a;          this.queue = a;
265          this.size = a.length;          this.size = a.length;
# Line 786  Line 799 
799          heapify();          heapify();
800      }      }
801    
     public Spliterator<E> spliterator() {  
         return new PriorityQueueSpliterator<E>(this, 0, -1, 0);  
     }  
   
802      /**      /**
803       * This is very similar to ArrayList Spliterator, except for extra       * Creates a <em><a href="Spliterator.html#binding">late-binding</a></em>
804       * null checks.       * and <em>fail-fast</em> {@link Spliterator} over the elements in this
805         * queue.
806         *
807         * <p>The {@code Spliterator} reports {@link Spliterator#SIZED},
808         * {@link Spliterator#SUBSIZED}, and {@link Spliterator#NONNULL}.
809         * Overriding implementations should document the reporting of additional
810         * characteristic values.
811         *
812         * @return a {@code Spliterator} over the elements in this queue
813         * @since 1.8
814       */       */
815        public final Spliterator<E> spliterator() {
816            return new PriorityQueueSpliterator<>(this, 0, -1, 0);
817        }
818    
819      static final class PriorityQueueSpliterator<E> implements Spliterator<E> {      static final class PriorityQueueSpliterator<E> implements Spliterator<E> {
820            /*
821             * This is very similar to ArrayList Spliterator, except for
822             * extra null checks.
823             */
824          private final PriorityQueue<E> pq;          private final PriorityQueue<E> pq;
825          private int index;            // current index, modified on advance/split          private int index;            // current index, modified on advance/split
826          private int fence;            // -1 until first use          private int fence;            // -1 until first use
# Line 818  Line 844 
844              return hi;              return hi;
845          }          }
846    
847          public Spliterator<E> trySplit() {          public PriorityQueueSpliterator<E> trySplit() {
848              int hi = getFence(), lo = index, mid = (lo + hi) >>> 1;              int hi = getFence(), lo = index, mid = (lo + hi) >>> 1;
849              return (lo >= mid) ? null :              return (lo >= mid) ? null :
850                  new PriorityQueueSpliterator<E>(pq, lo, index = mid,                  new PriorityQueueSpliterator<>(pq, lo, index = mid,
851                                                  expectedModCount);                                                  expectedModCount);
852          }          }
853    
# Line 856  Line 882 
882          }          }
883    
884          public boolean tryAdvance(Consumer<? super E> action) {          public boolean tryAdvance(Consumer<? super E> action) {
885                if (action == null)
886                    throw new NullPointerException();
887              int hi = getFence(), lo = index;              int hi = getFence(), lo = index;
888              if (lo >= 0 && lo < hi) {              if (lo >= 0 && lo < hi) {
889                  index = lo + 1;                  index = lo + 1;

Legend:
Removed from v.1.105  
changed lines
  Added in v.1.106

Doug Lea
ViewVC Help
Powered by ViewVC 1.0.8