Return-Path: X-Original-To: apmail-commons-commits-archive@minotaur.apache.org Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 7C8081130A for ; Tue, 2 Sep 2014 15:35:07 +0000 (UTC) Received: (qmail 92408 invoked by uid 500); 2 Sep 2014 15:35:07 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 92347 invoked by uid 500); 2 Sep 2014 15:35:07 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 92338 invoked by uid 99); 2 Sep 2014 15:35:07 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 02 Sep 2014 15:35:07 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 02 Sep 2014 15:34:42 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 0DACA238883D; Tue, 2 Sep 2014 15:34:41 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1622035 - in /commons/proper/pool/trunk/src: main/java/org/apache/commons/pool2/impl/LinkedBlockingDeque.java test/java/org/apache/commons/pool2/MethodCall.java test/java/org/apache/commons/pool2/impl/TestAbandonedObjectPool.java Date: Tue, 02 Sep 2014 15:34:40 -0000 To: commits@commons.apache.org From: ggregory@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20140902153441.0DACA238883D@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: ggregory Date: Tue Sep 2 15:34:40 2014 New Revision: 1622035 URL: http://svn.apache.org/r1622035 Log: Always use blocks. Modified: commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/LinkedBlockingDeque.java commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/MethodCall.java commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestAbandonedObjectPool.java Modified: commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/LinkedBlockingDeque.java URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/LinkedBlockingDeque.java?rev=1622035&r1=1622034&r2=1622035&view=diff ============================================================================== --- commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/LinkedBlockingDeque.java (original) +++ commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/LinkedBlockingDeque.java Tue Sep 2 15:34:40 2014 @@ -193,7 +193,9 @@ class LinkedBlockingDeque extends Abs * @throws IllegalArgumentException if {@code capacity} is less than 1 */ public LinkedBlockingDeque(int capacity, boolean fairness) { - if (capacity <= 0) throw new IllegalArgumentException(); + if (capacity <= 0) { + throw new IllegalArgumentException(); + } this.capacity = capacity; lock = new InterruptibleReentrantLock(fairness); notEmpty = lock.newCondition(); @@ -215,10 +217,12 @@ class LinkedBlockingDeque extends Abs lock.lock(); // Never contended, but necessary for visibility try { for (E e : c) { - if (e == null) + if (e == null) { throw new NullPointerException(); - if (!linkLast(e)) + } + if (!linkLast(e)) { throw new IllegalStateException("Deque full"); + } } } finally { lock.unlock(); @@ -237,15 +241,17 @@ class LinkedBlockingDeque extends Abs */ private boolean linkFirst(E e) { // assert lock.isHeldByCurrentThread(); - if (count >= capacity) + if (count >= capacity) { return false; + } Node f = first; Node x = new Node(e, null, f); first = x; - if (last == null) + if (last == null) { last = x; - else + } else { f.prev = x; + } ++count; notEmpty.signal(); return true; @@ -260,15 +266,17 @@ class LinkedBlockingDeque extends Abs */ private boolean linkLast(E e) { // assert lock.isHeldByCurrentThread(); - if (count >= capacity) + if (count >= capacity) { return false; + } Node l = last; Node x = new Node(e, l, null); last = x; - if (first == null) + if (first == null) { first = x; - else + } else { l.next = x; + } ++count; notEmpty.signal(); return true; @@ -282,17 +290,19 @@ class LinkedBlockingDeque extends Abs private E unlinkFirst() { // assert lock.isHeldByCurrentThread(); Node f = first; - if (f == null) + if (f == null) { return null; + } Node n = f.next; E item = f.item; f.item = null; f.next = f; // help GC first = n; - if (n == null) + if (n == null) { last = null; - else + } else { n.prev = null; + } --count; notFull.signal(); return item; @@ -306,17 +316,19 @@ class LinkedBlockingDeque extends Abs private E unlinkLast() { // assert lock.isHeldByCurrentThread(); Node l = last; - if (l == null) + if (l == null) { return null; + } Node p = l.prev; E item = l.item; l.item = null; l.prev = l; // help GC last = p; - if (p == null) + if (p == null) { first = null; - else + } else { p.next = null; + } --count; notFull.signal(); return item; @@ -353,8 +365,9 @@ class LinkedBlockingDeque extends Abs */ @Override public void addFirst(E e) { - if (!offerFirst(e)) + if (!offerFirst(e)) { throw new IllegalStateException("Deque full"); + } } /** @@ -362,8 +375,9 @@ class LinkedBlockingDeque extends Abs */ @Override public void addLast(E e) { - if (!offerLast(e)) + if (!offerLast(e)) { throw new IllegalStateException("Deque full"); + } } /** @@ -371,7 +385,9 @@ class LinkedBlockingDeque extends Abs */ @Override public boolean offerFirst(E e) { - if (e == null) throw new NullPointerException(); + if (e == null) { + throw new NullPointerException(); + } lock.lock(); try { return linkFirst(e); @@ -385,7 +401,9 @@ class LinkedBlockingDeque extends Abs */ @Override public boolean offerLast(E e) { - if (e == null) throw new NullPointerException(); + if (e == null) { + throw new NullPointerException(); + } lock.lock(); try { return linkLast(e); @@ -404,11 +422,14 @@ class LinkedBlockingDeque extends Abs * @throws InterruptedException */ public void putFirst(E e) throws InterruptedException { - if (e == null) throw new NullPointerException(); + if (e == null) { + throw new NullPointerException(); + } lock.lock(); try { - while (!linkFirst(e)) + while (!linkFirst(e)) { notFull.await(); + } } finally { lock.unlock(); } @@ -424,11 +445,14 @@ class LinkedBlockingDeque extends Abs * @throws InterruptedException */ public void putLast(E e) throws InterruptedException { - if (e == null) throw new NullPointerException(); + if (e == null) { + throw new NullPointerException(); + } lock.lock(); try { - while (!linkLast(e)) + while (!linkLast(e)) { notFull.await(); + } } finally { lock.unlock(); } @@ -449,13 +473,16 @@ class LinkedBlockingDeque extends Abs */ public boolean offerFirst(E e, long timeout, TimeUnit unit) throws InterruptedException { - if (e == null) throw new NullPointerException(); + if (e == null) { + throw new NullPointerException(); + } long nanos = unit.toNanos(timeout); lock.lockInterruptibly(); try { while (!linkFirst(e)) { - if (nanos <= 0) + if (nanos <= 0) { return false; + } nanos = notFull.awaitNanos(nanos); } return true; @@ -479,13 +506,16 @@ class LinkedBlockingDeque extends Abs */ public boolean offerLast(E e, long timeout, TimeUnit unit) throws InterruptedException { - if (e == null) throw new NullPointerException(); + if (e == null) { + throw new NullPointerException(); + } long nanos = unit.toNanos(timeout); lock.lockInterruptibly(); try { while (!linkLast(e)) { - if (nanos <= 0) + if (nanos <= 0) { return false; + } nanos = notFull.awaitNanos(nanos); } return true; @@ -500,7 +530,9 @@ class LinkedBlockingDeque extends Abs @Override public E removeFirst() { E x = pollFirst(); - if (x == null) throw new NoSuchElementException(); + if (x == null) { + throw new NoSuchElementException(); + } return x; } @@ -510,7 +542,9 @@ class LinkedBlockingDeque extends Abs @Override public E removeLast() { E x = pollLast(); - if (x == null) throw new NoSuchElementException(); + if (x == null) { + throw new NoSuchElementException(); + } return x; } @@ -545,8 +579,9 @@ class LinkedBlockingDeque extends Abs lock.lock(); try { E x; - while ( (x = unlinkFirst()) == null) + while ( (x = unlinkFirst()) == null) { notEmpty.await(); + } return x; } finally { lock.unlock(); @@ -564,8 +599,9 @@ class LinkedBlockingDeque extends Abs lock.lock(); try { E x; - while ( (x = unlinkLast()) == null) + while ( (x = unlinkLast()) == null) { notEmpty.await(); + } return x; } finally { lock.unlock(); @@ -589,8 +625,9 @@ class LinkedBlockingDeque extends Abs try { E x; while ( (x = unlinkFirst()) == null) { - if (nanos <= 0) + if (nanos <= 0) { return null; + } nanos = notEmpty.awaitNanos(nanos); } return x; @@ -616,8 +653,9 @@ class LinkedBlockingDeque extends Abs try { E x; while ( (x = unlinkLast()) == null) { - if (nanos <= 0) + if (nanos <= 0) { return null; + } nanos = notEmpty.awaitNanos(nanos); } return x; @@ -632,7 +670,9 @@ class LinkedBlockingDeque extends Abs @Override public E getFirst() { E x = peekFirst(); - if (x == null) throw new NoSuchElementException(); + if (x == null) { + throw new NoSuchElementException(); + } return x; } @@ -642,7 +682,9 @@ class LinkedBlockingDeque extends Abs @Override public E getLast() { E x = peekLast(); - if (x == null) throw new NoSuchElementException(); + if (x == null) { + throw new NoSuchElementException(); + } return x; } @@ -668,7 +710,9 @@ class LinkedBlockingDeque extends Abs @Override public boolean removeFirstOccurrence(Object o) { - if (o == null) return false; + if (o == null) { + return false; + } lock.lock(); try { for (Node p = first; p != null; p = p.next) { @@ -685,7 +729,9 @@ class LinkedBlockingDeque extends Abs @Override public boolean removeLastOccurrence(Object o) { - if (o == null) return false; + if (o == null) { + return false; + } lock.lock(); try { for (Node p = last; p != null; p = p.prev) { @@ -875,10 +921,12 @@ class LinkedBlockingDeque extends Abs * @throws IllegalArgumentException */ public int drainTo(Collection c, int maxElements) { - if (c == null) + if (c == null) { throw new NullPointerException(); - if (c == this) + } + if (c == this) { throw new IllegalArgumentException(); + } lock.lock(); try { int n = Math.min(maxElements, count); @@ -956,12 +1004,16 @@ class LinkedBlockingDeque extends Abs */ @Override public boolean contains(Object o) { - if (o == null) return false; + if (o == null) { + return false; + } lock.lock(); try { - for (Node p = first; p != null; p = p.next) - if (o.equals(p.item)) + for (Node p = first; p != null; p = p.next) { + if (o.equals(p.item)) { return true; + } + } return false; } finally { lock.unlock(); @@ -1028,8 +1080,9 @@ class LinkedBlockingDeque extends Abs 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 { lock.unlock(); @@ -1049,8 +1102,9 @@ class LinkedBlockingDeque extends Abs (a.getClass().getComponentType(), count); } 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; } @@ -1185,8 +1239,9 @@ class LinkedBlockingDeque extends Abs } else { // Skip over removed nodes. // May be necessary if multiple interior Nodes are removed. - while (s != null && s.item == null) + while (s != null && s.item == null) { s = nextNode(s); + } next = s; } nextItem = (next == null) ? null : next.item; @@ -1202,8 +1257,9 @@ class LinkedBlockingDeque extends Abs @Override public E next() { - if (next == null) + if (next == null) { throw new NoSuchElementException(); + } lastRet = next; E x = nextItem; advance(); @@ -1213,13 +1269,15 @@ class LinkedBlockingDeque extends Abs @Override public void remove() { Node n = lastRet; - if (n == null) + if (n == null) { throw new IllegalStateException(); + } lastRet = null; lock.lock(); try { - if (n.item != null) + if (n.item != null) { unlink(n); + } } finally { lock.unlock(); } @@ -1256,8 +1314,9 @@ class LinkedBlockingDeque extends Abs // Write out capacity and any hidden stuff s.defaultWriteObject(); // Write out all elements in the proper order. - for (Node p = first; p != null; p = p.next) + for (Node p = first; p != null; p = p.next) { s.writeObject(p.item); + } // Use trailing null as sentinel s.writeObject(null); } finally { @@ -1280,8 +1339,9 @@ class LinkedBlockingDeque extends Abs for (;;) { @SuppressWarnings("unchecked") E item = (E)s.readObject(); - if (item == null) + if (item == null) { break; + } add(item); } } Modified: commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/MethodCall.java URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/MethodCall.java?rev=1622035&r1=1622034&r2=1622035&view=diff ============================================================================== --- commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/MethodCall.java (original) +++ commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/MethodCall.java Tue Sep 2 15:34:40 2014 @@ -78,14 +78,24 @@ public class MethodCall { @Override public boolean equals(final Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } final MethodCall that = (MethodCall)o; - if (name != null ? !name.equals(that.name) : that.name != null) return false; - if (params != null ? !params.equals(that.params) : that.params != null) return false; - if (returned != null ? !returned.equals(that.returned) : that.returned != null) return false; + if (name != null ? !name.equals(that.name) : that.name != null) { + return false; + } + if (params != null ? !params.equals(that.params) : that.params != null) { + return false; + } + if (returned != null ? !returned.equals(that.returned) : that.returned != null) { + return false; + } return true; } Modified: commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestAbandonedObjectPool.java URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestAbandonedObjectPool.java?rev=1622035&r1=1622034&r2=1622035&view=diff ============================================================================== --- commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestAbandonedObjectPool.java (original) +++ commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestAbandonedObjectPool.java Tue Sep 2 15:34:40 2014 @@ -399,7 +399,9 @@ class PooledTestObject implements Tracke @Override public boolean equals(Object obj) { - if (!(obj instanceof PooledTestObject)) return false; + if (!(obj instanceof PooledTestObject)) { + return false; + } return obj.hashCode() == hashCode(); } }