This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-net.git


The following commit(s) were added to refs/heads/master by this push:
     new 243449b  Combine nested 'if' statement in 'else' block to 'else if'.
243449b is described below

commit 243449bd6998f84cf3169954c3a9d3b41888f9ac
Author: Gary Gregory <garydgreg...@gmail.com>
AuthorDate: Mon Feb 22 11:43:51 2021 -0500

    Combine nested 'if' statement in 'else' block to 'else if'.
---
 .../java/org/apache/commons/net/examples/Main.java | 12 ++---
 .../commons/net/examples/ftp/FTPClientExample.java | 24 ++++------
 .../java/org/apache/commons/net/ftp/FTPClient.java | 56 ++++++++++------------
 .../org/apache/commons/net/nntp/NNTPClient.java    | 14 ++----
 .../java/org/apache/commons/net/ntp/TimeInfo.java  | 25 +++++-----
 .../java/org/apache/commons/net/telnet/Telnet.java | 43 +++++++----------
 6 files changed, 72 insertions(+), 102 deletions(-)

diff --git a/src/main/java/org/apache/commons/net/examples/Main.java 
b/src/main/java/org/apache/commons/net/examples/Main.java
index 442316d..a278b5b 100644
--- a/src/main/java/org/apache/commons/net/examples/Main.java
+++ b/src/main/java/org/apache/commons/net/examples/Main.java
@@ -63,14 +63,12 @@ public class Main {
                                     " exampleClass>,<exampleClass parameters> 
(comma-separated, no spaces)");
                 System.out.println("Or   : mvn -q exec:java  
-Dexec.args=\"<alias" +
                                     " or exampleClass> <exampleClass 
parameters>\" (space separated)");
+            } else if (fromJar()) {
+                System.out.println(
+                    "Usage: java -jar commons-net-examples-m.n.jar <alias or 
exampleClass> <exampleClass parameters>");
             } else {
-                if (fromJar()) {
-                    System.out.println(
-                        "Usage: java -jar commons-net-examples-m.n.jar <alias 
or exampleClass> <exampleClass parameters>");
-                } else {
-                    System.out.println(
-                        "Usage: java -cp target/classes examples/Main <alias 
or exampleClass> <exampleClass parameters>");
-                }
+                System.out.println(
+                    "Usage: java -cp target/classes examples/Main <alias or 
exampleClass> <exampleClass parameters>");
             }
             @SuppressWarnings("unchecked") // property names are Strings
             final
diff --git 
a/src/main/java/org/apache/commons/net/examples/ftp/FTPClientExample.java 
b/src/main/java/org/apache/commons/net/examples/ftp/FTPClientExample.java
index c721089..aaf5029 100644
--- a/src/main/java/org/apache/commons/net/examples/ftp/FTPClientExample.java
+++ b/src/main/java/org/apache/commons/net/examples/ftp/FTPClientExample.java
@@ -481,12 +481,10 @@ __main:
                 if (remote != null) { // See if the command is present
                     if (ftp.hasFeature(remote)) {
                         System.out.println("Has feature: "+remote);
+                    } else if 
(FTPReply.isPositiveCompletion(ftp.getReplyCode())) {
+                        System.out.println("FEAT "+remote+" was not detected");
                     } else {
-                        if (FTPReply.isPositiveCompletion(ftp.getReplyCode())) 
{
-                            System.out.println("FEAT "+remote+" was not 
detected");
-                        } else {
-                            System.out.println("Command failed: 
"+ftp.getReplyString());
-                        }
+                        System.out.println("Command failed: 
"+ftp.getReplyString());
                     }
 
                     // Strings feature check
@@ -495,19 +493,15 @@ __main:
                         for(final String f : features) {
                             System.out.println("FEAT "+remote+"="+f+".");
                         }
+                    } else if 
(FTPReply.isPositiveCompletion(ftp.getReplyCode())) {
+                        System.out.println("FEAT "+remote+" is not present");
                     } else {
-                        if (FTPReply.isPositiveCompletion(ftp.getReplyCode())) 
{
-                            System.out.println("FEAT "+remote+" is not 
present");
-                        } else {
-                            System.out.println("Command failed: 
"+ftp.getReplyString());
-                        }
+                        System.out.println("Command failed: 
"+ftp.getReplyString());
                     }
-                } else {
-                    if (ftp.features()) {
+                } else if (ftp.features()) {
 //                        Command listener has already printed the output
-                    } else {
-                        System.out.println("Failed: "+ftp.getReplyString());
-                    }
+                } else {
+                    System.out.println("Failed: "+ftp.getReplyString());
                 }
             }
             else if (doCommand != null)
diff --git a/src/main/java/org/apache/commons/net/ftp/FTPClient.java 
b/src/main/java/org/apache/commons/net/ftp/FTPClient.java
index e30766e..389b47a 100644
--- a/src/main/java/org/apache/commons/net/ftp/FTPClient.java
+++ b/src/main/java/org/apache/commons/net/ftp/FTPClient.java
@@ -786,10 +786,8 @@ public class FTPClient extends FTP implements Configurable 
{
                     if 
(!FTPReply.isPositiveCompletion(eprt(getReportHostAddress(), 
server.getLocalPort()))) {
                         return null;
                     }
-                } else {
-                    if 
(!FTPReply.isPositiveCompletion(port(getReportHostAddress(), 
server.getLocalPort()))) {
-                        return null;
-                    }
+                } else if 
(!FTPReply.isPositiveCompletion(port(getReportHostAddress(), 
server.getLocalPort()))) {
+                    return null;
                 }
 
                 if ((restartOffset > 0) && !restart(restartOffset)) {
@@ -1396,36 +1394,34 @@ public class FTPClient extends FTP implements 
Configurable {
                     parserFactory.createFileEntryParser(parserKey);
                 entryParserKey = parserKey;
 
+            } else // if no parserKey was supplied, check for a configuration
+            // in the params, and if it has a non-empty system type, use that.
+            if (null != configuration && 
configuration.getServerSystemKey().length() > 0) {
+                entryParser =
+                    parserFactory.createFileEntryParser(configuration);
+                entryParserKey = configuration.getServerSystemKey();
             } else {
-                // if no parserKey was supplied, check for a configuration
-                // in the params, and if it has a non-empty system type, use 
that.
-                if (null != configuration && 
configuration.getServerSystemKey().length() > 0) {
-                    entryParser =
-                        parserFactory.createFileEntryParser(configuration);
-                    entryParserKey = configuration.getServerSystemKey();
-                } else {
-                    // if a parserKey hasn't been supplied, and a configuration
-                    // hasn't been supplied, and the override property is not 
set
-                    // then autodetect by calling
-                    // the SYST command and use that to choose the parser.
-                    String systemType = System.getProperty(FTP_SYSTEM_TYPE);
-                    if (systemType == null) {
-                        systemType = getSystemType(); // cannot be null
-                        final Properties override = getOverrideProperties();
-                        if (override != null) {
-                            final String newType = 
override.getProperty(systemType);
-                            if (newType != null) {
-                                systemType = newType;
-                            }
+                // if a parserKey hasn't been supplied, and a configuration
+                // hasn't been supplied, and the override property is not set
+                // then autodetect by calling
+                // the SYST command and use that to choose the parser.
+                String systemType = System.getProperty(FTP_SYSTEM_TYPE);
+                if (systemType == null) {
+                    systemType = getSystemType(); // cannot be null
+                    final Properties override = getOverrideProperties();
+                    if (override != null) {
+                        final String newType = 
override.getProperty(systemType);
+                        if (newType != null) {
+                            systemType = newType;
                         }
                     }
-                    if (null != configuration) { // system type must have been 
empty above
-                        entryParser = parserFactory.createFileEntryParser(new 
FTPClientConfig(systemType, configuration));
-                    } else {
-                        entryParser = 
parserFactory.createFileEntryParser(systemType);
-                    }
-                    entryParserKey = systemType;
                 }
+                if (null != configuration) { // system type must have been 
empty above
+                    entryParser = parserFactory.createFileEntryParser(new 
FTPClientConfig(systemType, configuration));
+                } else {
+                    entryParser = 
parserFactory.createFileEntryParser(systemType);
+                }
+                entryParserKey = systemType;
             }
         }
     }
diff --git a/src/main/java/org/apache/commons/net/nntp/NNTPClient.java 
b/src/main/java/org/apache/commons/net/nntp/NNTPClient.java
index 59a4d5f..c812c43 100644
--- a/src/main/java/org/apache/commons/net/nntp/NNTPClient.java
+++ b/src/main/java/org/apache/commons/net/nntp/NNTPClient.java
@@ -831,12 +831,8 @@ public class NNTPClient extends NNTP
             if (!NNTPReply.isPositiveCompletion(sendCommand(command, 
articleId))) {
                 return null;
             }
-        }
-        else
-        {
-            if (!NNTPReply.isPositiveCompletion(sendCommand(command))) {
-                return null;
-            }
+        } else if (!NNTPReply.isPositiveCompletion(sendCommand(command))) {
+            return null;
         }
 
 
@@ -1675,10 +1671,8 @@ public class NNTPClient extends NNTP
             if (!NNTPReply.isPositiveCompletion(stat(articleId))) {
                 return false;
             }
-        } else {
-            if (!NNTPReply.isPositiveCompletion(stat())) {
-                return false;
-            }
+        } else if (!NNTPReply.isPositiveCompletion(stat())) {
+            return false;
         }
 
         if (pointer != null) {
diff --git a/src/main/java/org/apache/commons/net/ntp/TimeInfo.java 
b/src/main/java/org/apache/commons/net/ntp/TimeInfo.java
index ff6ed8c..c123465 100644
--- a/src/main/java/org/apache/commons/net/ntp/TimeInfo.java
+++ b/src/main/java/org/apache/commons/net/ntp/TimeInfo.java
@@ -216,22 +216,19 @@ public class TimeInfo {
                  if (deltaMillis <= delayValueMillis)
                  {
                      delayValueMillis -= deltaMillis; // delay = (t4 - t1) - 
(t3 - t2)
-                 } else
+                 } else // if delta - delayValue == 1 ms then it's a round-off 
error
+                 // e.g. delay=3ms, processing=4ms
+                 if (deltaMillis - delayValueMillis == 1)
                  {
-                     // if delta - delayValue == 1 ms then it's a round-off 
error
-                     // e.g. delay=3ms, processing=4ms
-                     if (deltaMillis - delayValueMillis == 1)
+                     // delayValue == 0 -> local clock saw no tick change but 
destination clock did
+                     if (delayValueMillis != 0)
                      {
-                         // delayValue == 0 -> local clock saw no tick change 
but destination clock did
-                         if (delayValueMillis != 0)
-                         {
-                             comments.add("Info: processing time > total 
network time by 1 ms -> assume zero delay");
-                             delayValueMillis = 0;
-                         }
-                     } else {
-                        comments.add("Warning: processing time > total network 
time");
-                    }
-                 }
+                         comments.add("Info: processing time > total network 
time by 1 ms -> assume zero delay");
+                         delayValueMillis = 0;
+                     }
+                 } else {
+                    comments.add("Warning: processing time > total network 
time");
+                }
              }
              delayMillis = Long.valueOf(delayValueMillis);
             if (origTimeMillis > returnTimeMillis) {
diff --git a/src/main/java/org/apache/commons/net/telnet/Telnet.java 
b/src/main/java/org/apache/commons/net/telnet/Telnet.java
index d1c0d4f..66468b2 100644
--- a/src/main/java/org/apache/commons/net/telnet/Telnet.java
+++ b/src/main/java/org/apache/commons/net/telnet/Telnet.java
@@ -465,22 +465,17 @@ class Telnet extends SocketClient
         if (optionHandlers[option] != null)
         {
             acceptNewState = optionHandlers[option].getAcceptLocal();
-        }
-        else
+        } else /* open TelnetOptionHandler functionality (end)*/
+        /* TERMINAL-TYPE option (start)*/
+        if (option == TERMINAL_TYPE)
         {
-        /* open TelnetOptionHandler functionality (end)*/
-            /* TERMINAL-TYPE option (start)*/
-            if (option == TERMINAL_TYPE)
+            if (terminalType != null && !terminalType.isEmpty())
             {
-                if (terminalType != null && !terminalType.isEmpty())
-                {
-                    acceptNewState = true;
-                }
+                acceptNewState = true;
             }
-            /* TERMINAL-TYPE option (end)*/
-        /* open TelnetOptionHandler functionality (start)*/
         }
-        /* open TelnetOptionHandler functionality (end)*/
+        /* TERMINAL-TYPE option (end)*/
+      /* open TelnetOptionHandler functionality (start)*/
 
         if (willResponse[option] > 0)
         {
@@ -611,25 +606,21 @@ class Telnet extends SocketClient
                   optionHandlers[suboption[0]].answerSubnegotiation(suboption,
                   suboptionLength);
                 _sendSubnegotiation(responseSuboption);
-            }
-            else
+            } else if (suboptionLength > 1)
             {
-                if (suboptionLength > 1)
+                if (debug)
                 {
-                    if (debug)
-                    {
-                        for (int ii = 0; ii < suboptionLength; ii++)
-                        {
-                            System.err.println("SUB[" + ii + "]: "
-                                + suboption[ii]);
-                        }
-                    }
-                    if (suboption[0] == TERMINAL_TYPE
-                        && suboption[1] == TERMINAL_TYPE_SEND)
+                    for (int ii = 0; ii < suboptionLength; ii++)
                     {
-                        sendTerminalType();
+                        System.err.println("SUB[" + ii + "]: "
+                            + suboption[ii]);
                     }
                 }
+                if (suboption[0] == TERMINAL_TYPE
+                    && suboption[1] == TERMINAL_TYPE_SEND)
+                {
+                    sendTerminalType();
+                }
             }
         }
         /* open TelnetOptionHandler functionality (end)*/

Reply via email to