You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by gg...@apache.org on 2016/03/10 19:48:01 UTC

svn commit: r1734444 - in /httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5: http/impl/ http/impl/io/ http/impl/nio/ http/protocol/ pool/io/ pool/nio/

Author: ggregory
Date: Thu Mar 10 18:47:59 2016
New Revision: 1734444

URL: http://svn.apache.org/viewvc?rev=1734444&view=rev
Log:
https://github.com/apache/httpcore/pull/25 - Code quality fix - Collapsible "if" statements should be merged.

Modified:
    httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/DefaultConnectionReuseStrategy.java
    httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/SessionInputBufferImpl.java
    httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/DefaultNHttpClientConnection.java
    httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/DefaultNHttpServerConnection.java
    httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/PipeliningClientExchangeHandler.java
    httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/SessionInputBufferImpl.java
    httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/SharedInputBuffer.java
    httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/SharedOutputBuffer.java
    httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/protocol/RequestUserAgent.java
    httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/protocol/ResponseServer.java
    httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/pool/io/RouteSpecificPool.java
    httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/pool/nio/RouteSpecificPool.java

Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/DefaultConnectionReuseStrategy.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/DefaultConnectionReuseStrategy.java?rev=1734444&r1=1734443&r2=1734444&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/DefaultConnectionReuseStrategy.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/DefaultConnectionReuseStrategy.java Thu Mar 10 18:47:59 2016
@@ -101,10 +101,8 @@ public class DefaultConnectionReuseStrat
                 return false;
             }
         } else {
-            if (canResponseHaveBody(response)) {
-                if (response.containsHeaders(HttpHeaders.CONTENT_LENGTH) != 1) {
-                    return false;
-                }
+            if (canResponseHaveBody(response) && response.containsHeaders(HttpHeaders.CONTENT_LENGTH) != 1) {
+                return false;
             }
         }
 

Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/SessionInputBufferImpl.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/SessionInputBufferImpl.java?rev=1734444&r1=1734443&r2=1734444&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/SessionInputBufferImpl.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/SessionInputBufferImpl.java Thu Mar 10 18:47:59 2016
@@ -315,10 +315,8 @@ public class SessionInputBufferImpl impl
                 len--;
             }
             // discard CR if found
-            if (len > 0) {
-                if (this.linebuffer.byteAt(len - 1) == Chars.CR) {
-                    len--;
-                }
+            if (len > 0 && this.linebuffer.byteAt(len - 1) == Chars.CR) {
+                len--;
             }
         }
         if (this.decoder == null) {

Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/DefaultNHttpClientConnection.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/DefaultNHttpClientConnection.java?rev=1734444&r1=1734443&r2=1734444&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/DefaultNHttpClientConnection.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/DefaultNHttpClientConnection.java Thu Mar 10 18:47:59 2016
@@ -239,12 +239,10 @@ public class DefaultNHttpClientConnectio
                     this.outTransportMetrics.incrementBytesTransferred(bytesWritten);
                 }
             }
-            if (!this.outbuf.hasData()) {
-                if (this.status == CLOSING) {
-                    this.session.close();
-                    this.status = CLOSED;
-                    resetOutput();
-                }
+            if (!this.outbuf.hasData() && this.status == CLOSING) {
+                this.session.close();
+                this.status = CLOSED;
+                resetOutput();
             }
         } catch (final Exception ex) {
             handler.exception(this, ex);

Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/DefaultNHttpServerConnection.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/DefaultNHttpServerConnection.java?rev=1734444&r1=1734443&r2=1734444&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/DefaultNHttpServerConnection.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/DefaultNHttpServerConnection.java Thu Mar 10 18:47:59 2016
@@ -240,12 +240,10 @@ public class DefaultNHttpServerConnectio
                     this.outTransportMetrics.incrementBytesTransferred(bytesWritten);
                 }
             }
-            if (!this.outbuf.hasData()) {
-                if (this.status == CLOSING) {
-                    this.session.close();
-                    this.status = CLOSED;
-                    resetOutput();
-                }
+            if (!this.outbuf.hasData() && this.status == CLOSING) {
+                this.session.close();
+                this.status = CLOSED;
+                resetOutput();
             }
         } catch (final Exception ex) {
             handler.exception(this, ex);

Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/PipeliningClientExchangeHandler.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/PipeliningClientExchangeHandler.java?rev=1734444&r1=1734443&r2=1734444&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/PipeliningClientExchangeHandler.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/PipeliningClientExchangeHandler.java Thu Mar 10 18:47:59 2016
@@ -243,10 +243,8 @@ public class PipeliningClientExchangeHan
                 this.future.failed(ex);
                 this.conn.shutdown();
             }
-            if (!conn.isOpen()) {
-                if (this.closed.compareAndSet(false, true)) {
-                    releaseResources();
-                }
+            if (!conn.isOpen() && this.closed.compareAndSet(false, true)) {
+                releaseResources();
             }
             if (!this.future.isDone() && this.responseConsumerQueue.isEmpty()) {
                 this.future.completed(new ArrayList<>(this.resultQueue));

Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/SessionInputBufferImpl.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/SessionInputBufferImpl.java?rev=1734444&r1=1734443&r2=1734444&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/SessionInputBufferImpl.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/SessionInputBufferImpl.java Thu Mar 10 18:47:59 2016
@@ -322,11 +322,9 @@ public class SessionInputBufferImpl exte
                 linebuffer.setLength(l);
             }
             // discard CR if found
-            if (l > 0) {
-                if (linebuffer.charAt(l - 1) == Chars.CR) {
-                    l--;
-                    linebuffer.setLength(l);
-                }
+            if (l > 0 && linebuffer.charAt(l - 1) == Chars.CR) {
+                l--;
+                linebuffer.setLength(l);
             }
         }
         return true;

Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/SharedInputBuffer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/SharedInputBuffer.java?rev=1734444&r1=1734443&r2=1734444&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/SharedInputBuffer.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/SharedInputBuffer.java Thu Mar 10 18:47:59 2016
@@ -116,10 +116,8 @@ public class SharedInputBuffer extends E
             if (bytesRead == -1 || decoder.isCompleted()) {
                 this.endOfStream = true;
             }
-            if (!buffer().hasRemaining()) {
-                if (this.ioctrl != null) {
-                    this.ioctrl.suspendInput();
-                }
+            if (!buffer().hasRemaining() && this.ioctrl != null) {
+                this.ioctrl.suspendInput();
             }
             this.condition.signalAll();
 

Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/SharedOutputBuffer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/SharedOutputBuffer.java?rev=1734444&r1=1734443&r2=1734444&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/SharedOutputBuffer.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/SharedOutputBuffer.java Thu Mar 10 18:47:59 2016
@@ -162,11 +162,9 @@ public class SharedOutputBuffer extends
                 if (this.endOfStream && !encoder.isCompleted()) {
                     encoder.complete();
                 }
-                if (!this.endOfStream) {
+                if (!this.endOfStream && this.ioctrl != null) {
                     // suspend output events
-                    if (this.ioctrl != null) {
-                        this.ioctrl.suspendOutput();
-                    }
+                    this.ioctrl.suspendOutput();
                 }
             }
             this.condition.signalAll();

Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/protocol/RequestUserAgent.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/protocol/RequestUserAgent.java?rev=1734444&r1=1734443&r2=1734444&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/protocol/RequestUserAgent.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/protocol/RequestUserAgent.java Thu Mar 10 18:47:59 2016
@@ -60,10 +60,8 @@ public class RequestUserAgent implements
     public void process(final HttpRequest request, final HttpContext context)
         throws HttpException, IOException {
         Args.notNull(request, "HTTP request");
-        if (!request.containsHeader(HttpHeaders.USER_AGENT)) {
-            if (this.userAgent != null) {
-                request.addHeader(HttpHeaders.USER_AGENT, this.userAgent);
-            }
+        if (!request.containsHeader(HttpHeaders.USER_AGENT) && this.userAgent != null) {
+            request.addHeader(HttpHeaders.USER_AGENT, this.userAgent);
         }
     }
 

Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/protocol/ResponseServer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/protocol/ResponseServer.java?rev=1734444&r1=1734443&r2=1734444&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/protocol/ResponseServer.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/protocol/ResponseServer.java Thu Mar 10 18:47:59 2016
@@ -63,10 +63,8 @@ public class ResponseServer implements H
     public void process(final HttpResponse response, final HttpContext context)
             throws HttpException, IOException {
         Args.notNull(response, "HTTP response");
-        if (!response.containsHeader(HttpHeaders.SERVER)) {
-            if (this.originServer != null) {
-                response.addHeader(HttpHeaders.SERVER, this.originServer);
-            }
+        if (!response.containsHeader(HttpHeaders.SERVER) && this.originServer != null) {
+            response.addHeader(HttpHeaders.SERVER, this.originServer);
         }
     }
 

Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/pool/io/RouteSpecificPool.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/pool/io/RouteSpecificPool.java?rev=1734444&r1=1734443&r2=1734444&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/pool/io/RouteSpecificPool.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/pool/io/RouteSpecificPool.java Thu Mar 10 18:47:59 2016
@@ -109,10 +109,8 @@ abstract class RouteSpecificPool<T, C, E
 
     public boolean remove(final E entry) {
         Args.notNull(entry, "Pool entry");
-        if (!this.available.remove(entry)) {
-            if (!this.leased.remove(entry)) {
-                return false;
-            }
+        if (!this.available.remove(entry) && !this.leased.remove(entry)) {
+            return false;
         }
         return true;
     }

Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/pool/nio/RouteSpecificPool.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/pool/nio/RouteSpecificPool.java?rev=1734444&r1=1734443&r2=1734444&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/pool/nio/RouteSpecificPool.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/pool/nio/RouteSpecificPool.java Thu Mar 10 18:47:59 2016
@@ -114,10 +114,8 @@ abstract class RouteSpecificPool<T, C, E
 
     public boolean remove(final E entry) {
         Args.notNull(entry, "Pool entry");
-        if (!this.available.remove(entry)) {
-            if (!this.leased.remove(entry)) {
-                return false;
-            }
+        if (!this.available.remove(entry) && !this.leased.remove(entry)) {
+            return false;
         }
         return true;
     }