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

Comparing jsr166/src/main/java/util/concurrent/LinkedBlockingDeque.java (file contents):
Revision 1.2 by dl, Tue Mar 8 12:27:11 2005 UTC vs.
Revision 1.3 by jsr166, Tue Apr 26 01:17:18 2005 UTC

# Line 48 | Line 48 | public class LinkedBlockingDeque<E>
48  
49      /** Doubly-linked list node class */
50      static final class Node<E> {
51 <        E item;
51 >        E item;
52          Node<E> prev;
53          Node<E> next;
54          Node(E x, Node<E> p, Node<E> n) {
# Line 99 | Line 99 | public class LinkedBlockingDeque<E>
99       * added in traversal order of the collection's iterator.
100       * @param c the collection of elements to initially contain
101       * @throws NullPointerException if <tt>c</tt> or any element within it
102 <     * is <tt>null</tt>
102 >     * is <tt>null</tt>.
103       */
104      public LinkedBlockingDeque(Collection<? extends E> c) {
105          this(Integer.MAX_VALUE);
# Line 111 | Line 111 | public class LinkedBlockingDeque<E>
111      // Basic linking and unlinking operations, called only while holding lock
112  
113      /**
114 <     * Link e as first element, or return false if full
114 >     * Links e as first element, or returns false if full.
115       */
116      private boolean linkFirst(E e) {
117          if (count >= capacity)
# Line 129 | Line 129 | public class LinkedBlockingDeque<E>
129      }
130  
131      /**
132 <     * Link e as last element, or return false if full
132 >     * Links e as last element, or returns false if full.
133       */
134      private boolean linkLast(E e) {
135          if (count >= capacity)
# Line 147 | Line 147 | public class LinkedBlockingDeque<E>
147      }
148  
149      /**
150 <     * Remove and return first element, or null if empty
150 >     * Removes and returns first element, or null if empty.
151       */
152      private E unlinkFirst() {
153          Node<E> f = first;
# Line 155 | Line 155 | public class LinkedBlockingDeque<E>
155              return null;
156          Node<E> n = f.next;
157          first = n;
158 <        if (n == null)
158 >        if (n == null)
159              last = null;
160 <        else
160 >        else
161              n.prev = null;
162          --count;
163          notFull.signal();
# Line 165 | Line 165 | public class LinkedBlockingDeque<E>
165      }
166  
167      /**
168 <     * Remove and return last element, or null if empty
168 >     * Removes and returns last element, or null if empty.
169       */
170      private E unlinkLast() {
171          Node<E> l = last;
# Line 173 | Line 173 | public class LinkedBlockingDeque<E>
173              return null;
174          Node<E> p = l.prev;
175          last = p;
176 <        if (p == null)
176 >        if (p == null)
177              first = null;
178 <        else
178 >        else
179              p.next = null;
180          --count;
181          notFull.signal();
# Line 189 | Line 189 | public class LinkedBlockingDeque<E>
189          Node<E> p = x.prev;
190          Node<E> n = x.next;
191          if (p == null) {
192 <            if (n == null)
192 >            if (n == null)
193                  first = last = null;
194              else {
195                  n.prev = null;
# Line 228 | Line 228 | public class LinkedBlockingDeque<E>
228          }
229      }
230  
231 <    public void addFirst(E e) {
231 >    public void addFirst(E e) {
232          if (!offerFirst(e))
233              throw new IllegalStateException("Deque full");
234      }
235  
236 <    public void addLast(E e) {
236 >    public void addLast(E e) {
237          if (!offerLast(e))
238              throw new IllegalStateException("Deque full");
239      }
# Line 363 | Line 363 | public class LinkedBlockingDeque<E>
363              lock.unlock();
364          }
365      }
366 <        
366 >
367      public boolean offerLast(E o, long timeout, TimeUnit unit)
368          throws InterruptedException {
369          if (o == null) throw new NullPointerException();
# Line 382 | Line 382 | public class LinkedBlockingDeque<E>
382          }
383      }
384  
385 <    public E pollFirst(long timeout, TimeUnit unit)
385 >    public E pollFirst(long timeout, TimeUnit unit)
386          throws InterruptedException {
387          lock.lockInterruptibly();
388          try {
# Line 400 | Line 400 | public class LinkedBlockingDeque<E>
400          }
401      }
402  
403 <    public E pollLast(long timeout, TimeUnit unit)
403 >    public E pollLast(long timeout, TimeUnit unit)
404          throws InterruptedException {
405          lock.lockInterruptibly();
406          try {
# Line 477 | Line 477 | public class LinkedBlockingDeque<E>
477          if (o == null) return false;
478          lock.lock();
479          try {
480 <            for (Node<E> p = first; p != null; p = p.next)
480 >            for (Node<E> p = first; p != null; p = p.next)
481                  if (o.equals(p.item))
482                      return true;
483              return false;
# Line 542 | Line 542 | public class LinkedBlockingDeque<E>
542          try {
543              Object[] a = new Object[count];
544              int k = 0;
545 <            for (Node<E> p = first; p != null; p = p.next)
545 >            for (Node<E> p = first; p != null; p = p.next)
546                  a[k++] = p.item;
547              return a;
548          } finally {
# Line 560 | Line 560 | public class LinkedBlockingDeque<E>
560                      );
561  
562              int k = 0;
563 <            for (Node<E> p = first; p != null; p = p.next)
563 >            for (Node<E> p = first; p != null; p = p.next)
564                  a[k++] = (T)p.item;
565              if (a.length > k)
566                  a[k] = null;
# Line 601 | Line 601 | public class LinkedBlockingDeque<E>
601              throw new IllegalArgumentException();
602          lock.lock();
603          try {
604 <            for (Node<E> p = first; p != null; p = p.next)
604 >            for (Node<E> p = first; p != null; p = p.next)
605                  c.add(p.item);
606              int n = count;
607              count = 0;
# Line 640 | Line 640 | public class LinkedBlockingDeque<E>
640      /**
641       * Returns an iterator over the elements in this deque in proper sequence.
642       * The returned <tt>Iterator</tt> is a "weakly consistent" iterator that
643 <     * will never throw {@link java.util.ConcurrentModificationException},
643 >     * will never throw {@link ConcurrentModificationException},
644       * and guarantees to traverse elements as they existed upon
645       * construction of the iterator, and may (but is not guaranteed to)
646       * reflect any modifications subsequent to construction.
# Line 662 | Line 662 | public class LinkedBlockingDeque<E>
662           * an element exists in hasNext(), we must return item read
663           * under lock (in advance()) even if it was in the process of
664           * being removed when hasNext() was called.
665 <         **/
665 >         */
666          private E nextItem;
667  
668          /**
# Line 678 | Line 678 | public class LinkedBlockingDeque<E>
678          /**
679           * Advance next, or if not yet initialized, set to first node.
680           */
681 <        private void advance() {
681 >        private void advance() {
682              final ReentrantLock lock = LinkedBlockingDeque.this.lock;
683              lock.lock();
684              try {
# Line 715 | Line 715 | public class LinkedBlockingDeque<E>
715      }
716  
717      /**
718 <     * Save the state to a stream (that is, serialize it).
718 >     * Save the state of this deque to a stream (that is, serialize it).
719       *
720       * @serialData The capacity (int), followed by elements (each an
721       * <tt>Object</tt>) in the proper order, followed by a null
# Line 738 | Line 738 | public class LinkedBlockingDeque<E>
738      }
739  
740      /**
741 <     * Reconstitute this deque instance from a stream (that is,
741 >     * Reconstitute this deque from a stream (that is,
742       * deserialize it).
743       * @param s the stream
744       */
# Line 756 | Line 756 | public class LinkedBlockingDeque<E>
756              add(item);
757          }
758      }
759 <    
759 >
760   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines