--- jsr166/src/jsr166x/LinkedBlockingDeque.java 2004/12/26 20:13:15 1.2 +++ jsr166/src/jsr166x/LinkedBlockingDeque.java 2012/12/29 23:55:19 1.13 @@ -1,7 +1,7 @@ /* * Written by Doug Lea with assistance from members of JCP JSR-166 * Expert Group and released to the public domain, as explained at - * http://creativecommons.org/licenses/publicdomain + * http://creativecommons.org/publicdomain/zero/1.0/ */ package jsr166x; @@ -14,7 +14,7 @@ import java.util.concurrent.locks.*; * An optionally-bounded {@linkplain BlockingDeque blocking deque} based on * linked nodes. * - *

The optional capacity bound constructor argument serves as a + *

The optional capacity bound constructor argument serves as a * way to prevent excessive expansion. The capacity, if unspecified, * is equal to {@link Integer#MAX_VALUE}. Linked nodes are * dynamically created upon each insertion unless this would bring the @@ -39,7 +39,7 @@ import java.util.concurrent.locks.*; */ public class LinkedBlockingDeque extends AbstractQueue - implements BlockingDeque, java.io.Serializable { + implements BlockingDeque, java.io.Serializable { /* * Implemented as a simple doubly-linked list protected by a @@ -50,7 +50,7 @@ public class LinkedBlockingDeque /** Doubly-linked list node class */ static final class Node { - E item; + E item; Node prev; Node next; Node(E x, Node p, Node n) { @@ -149,7 +149,7 @@ public class LinkedBlockingDeque } /** - * Remove and return first element, or null if empty + * Removes and returns first element, or null if empty. */ private E unlinkFirst() { Node f = first; @@ -157,9 +157,9 @@ public class LinkedBlockingDeque return null; Node n = f.next; first = n; - if (n == null) + if (n == null) last = null; - else + else n.prev = null; --count; notFull.signal(); @@ -167,7 +167,7 @@ public class LinkedBlockingDeque } /** - * Remove and return last element, or null if empty + * Removes and returns last element, or null if empty. */ private E unlinkLast() { Node l = last; @@ -175,9 +175,9 @@ public class LinkedBlockingDeque return null; Node p = l.prev; last = p; - if (p == null) + if (p == null) first = null; - else + else p.next = null; --count; notFull.signal(); @@ -191,7 +191,7 @@ public class LinkedBlockingDeque Node p = x.prev; Node n = x.next; if (p == null) { - if (n == null) + if (n == null) first = last = null; else { n.prev = null; @@ -230,12 +230,12 @@ public class LinkedBlockingDeque } } - public void addFirst(E e) { + public void addFirst(E e) { if (!offerFirst(e)) throw new IllegalStateException("Deque full"); } - public void addLast(E e) { + public void addLast(E e) { if (!offerLast(e)) throw new IllegalStateException("Deque full"); } @@ -365,7 +365,7 @@ public class LinkedBlockingDeque lock.unlock(); } } - + public boolean offerLast(E o, long timeout, TimeUnit unit) throws InterruptedException { if (o == null) throw new NullPointerException(); @@ -384,7 +384,7 @@ public class LinkedBlockingDeque } } - public E pollFirst(long timeout, TimeUnit unit) + public E pollFirst(long timeout, TimeUnit unit) throws InterruptedException { lock.lockInterruptibly(); try { @@ -402,7 +402,7 @@ public class LinkedBlockingDeque } } - public E pollLast(long timeout, TimeUnit unit) + public E pollLast(long timeout, TimeUnit unit) throws InterruptedException { lock.lockInterruptibly(); try { @@ -434,8 +434,8 @@ public class LinkedBlockingDeque // BlockingQueue methods - public void put(E o) throws InterruptedException { putLast(o); } - public E take() throws InterruptedException { return takeFirst(); } + public void put(E o) throws InterruptedException { putLast(o); } + public E take() throws InterruptedException { return takeFirst(); } public boolean offer(E o, long timeout, TimeUnit unit) throws InterruptedException { return offerLast(o, timeout, unit); } public E poll(long timeout, TimeUnit unit) @@ -444,7 +444,7 @@ public class LinkedBlockingDeque /** * Returns the number of elements in this deque. * - * @return the number of elements in this deque. + * @return the number of elements in this deque */ public int size() { lock.lock(); @@ -479,7 +479,7 @@ public class LinkedBlockingDeque if (o == null) return false; lock.lock(); try { - for (Node p = first; p != null; p = p.next) + for (Node p = first; p != null; p = p.next) if (o.equals(p.item)) return true; return false; @@ -524,7 +524,7 @@ public class LinkedBlockingDeque * Variant of removeFirstOccurrence needed by iterator.remove. * Searches for the node, not its contents. */ - boolean removeNode(Node e) { + boolean removeNode(Node e) { lock.lock(); try { for (Node p = first; p != null; p = p.next) { @@ -544,7 +544,7 @@ public class LinkedBlockingDeque try { Object[] a = new Object[count]; int k = 0; - for (Node p = first; p != null; p = p.next) + for (Node p = first; p != null; p = p.next) a[k++] = p.item; return a; } finally { @@ -562,7 +562,7 @@ public class LinkedBlockingDeque ); int k = 0; - for (Node p = first; p != null; p = p.next) + for (Node p = first; p != null; p = p.next) a[k++] = (T)p.item; if (a.length > k) a[k] = null; @@ -603,7 +603,7 @@ public class LinkedBlockingDeque throw new IllegalArgumentException(); lock.lock(); try { - for (Node p = first; p != null; p = p.next) + for (Node p = first; p != null; p = p.next) c.add(p.item); int n = count; count = 0; @@ -647,7 +647,7 @@ public class LinkedBlockingDeque * construction of the iterator, and may (but is not guaranteed to) * reflect any modifications subsequent to construction. * - * @return an iterator over the elements in this deque in proper sequence. + * @return an iterator over the elements in this deque in proper sequence */ public Iterator iterator() { return new Itr(); @@ -664,7 +664,7 @@ public class LinkedBlockingDeque * an element exists in hasNext(), we must return item read * under lock (in advance()) even if it was in the process of * being removed when hasNext() was called. - **/ + */ private E nextItem; /** @@ -680,12 +680,12 @@ public class LinkedBlockingDeque /** * Advance next, or if not yet initialized, set to first node. */ - private void advance() { + private void advance() { final ReentrantLock lock = LinkedBlockingDeque.this.lock; lock.lock(); try { - next = (next == null)? first : next.next; - nextItem = (next == null)? null : next.item; + next = (next == null) ? first : next.next; + nextItem = (next == null) ? null : next.item; } finally { lock.unlock(); } @@ -717,7 +717,7 @@ public class LinkedBlockingDeque } /** - * Save the state to a stream (that is, serialize it). + * Saves the state to a stream (that is, serializes it). * * @serialData The capacity (int), followed by elements (each an * Object) in the proper order, followed by a null @@ -740,8 +740,8 @@ public class LinkedBlockingDeque } /** - * Reconstitute this deque instance from a stream (that is, - * deserialize it). + * Reconstitutes this deque instance from a stream (that is, + * deserializes it). * @param s the stream */ private void readObject(java.io.ObjectInputStream s) @@ -758,5 +758,5 @@ public class LinkedBlockingDeque add(item); } } - + }