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

commit 9246a5b76b9e21a6650f9a97cb4cc6f4232e9b14
Author: Gary Gregory <garydgreg...@gmail.com>
AuthorDate: Thu Sep 12 10:32:52 2024 -0400

    Convert cascading if-else to switch
---
 .../commons/net/ftp/parser/MLSxEntryParser.java    | 58 +++++++++++++---------
 1 file changed, 34 insertions(+), 24 deletions(-)

diff --git 
a/src/main/java/org/apache/commons/net/ftp/parser/MLSxEntryParser.java 
b/src/main/java/org/apache/commons/net/ftp/parser/MLSxEntryParser.java
index 3c17d2c3..69860d6d 100644
--- a/src/main/java/org/apache/commons/net/ftp/parser/MLSxEntryParser.java
+++ b/src/main/java/org/apache/commons/net/ftp/parser/MLSxEntryParser.java
@@ -225,43 +225,53 @@ public class MLSxEntryParser extends 
FTPFileEntryParserImpl {
                 continue; // nothing to see here
             }
             final String valueLowerCase = 
factvalue.toLowerCase(Locale.ENGLISH);
-            if ("size".equals(factname) || "sizd".equals(factname)) {
+            switch (factname) {
+            case "size":
+            case "sizd":
                 file.setSize(Long.parseLong(factvalue));
-            } else if ("modify".equals(factname)) {
+                break;
+            case "modify": {
                 final Calendar parsed = parseGMTdateTime(factvalue);
                 if (parsed == null) {
                     return null;
                 }
                 file.setTimestamp(parsed);
-            } else if ("type".equals(factname)) {
+                break;
+            }
+            case "type": {
                 final Integer intType = TYPE_TO_INT.get(valueLowerCase);
                 if (intType == null) {
                     file.setType(FTPFile.UNKNOWN_TYPE);
                 } else {
                     file.setType(intType.intValue());
                 }
-            } else if (factname.startsWith("unix.")) {
-                final String unixfact = 
factname.substring("unix.".length()).toLowerCase(Locale.ENGLISH);
-                if ("group".equals(unixfact)) {
-                    file.setGroup(factvalue);
-                } else if ("owner".equals(unixfact)) {
-                    file.setUser(factvalue);
-                } else if ("mode".equals(unixfact)) { // e.g. 0[1]755
-                    final int off = factvalue.length() - 3; // only parse last 
3 digits
-                    for (int i = 0; i < 3; i++) {
-                        final int ch = factvalue.charAt(off + i) - '0';
-                        if (ch >= 0 && ch <= 7) { // Check it's valid octal
-                            for (final int p : UNIX_PERMS[ch]) {
-                                file.setPermission(UNIX_GROUPS[i], p, true);
+                break;
+            }
+            default:
+                if (factname.startsWith("unix.")) {
+                    final String unixfact = 
factname.substring("unix.".length()).toLowerCase(Locale.ENGLISH);
+                    if ("group".equals(unixfact)) {
+                        file.setGroup(factvalue);
+                    } else if ("owner".equals(unixfact)) {
+                        file.setUser(factvalue);
+                    } else if ("mode".equals(unixfact)) { // e.g. 0[1]755
+                        final int off = factvalue.length() - 3; // only parse 
last 3 digits
+                        for (int i = 0; i < 3; i++) {
+                            final int ch = factvalue.charAt(off + i) - '0';
+                            if (ch >= 0 && ch <= 7) { // Check it's valid octal
+                                for (final int p : UNIX_PERMS[ch]) {
+                                    file.setPermission(UNIX_GROUPS[i], p, 
true);
+                                }
+                            } else {
+                                // TODO should this cause failure, or can it 
be reported somehow?
                             }
-                        } else {
-                            // TODO should this cause failure, or can it be 
reported somehow?
-                        }
-                    } // digits
-                } // mode
-            } // unix.
-            else if (!hasUnixMode && "perm".equals(factname)) { // skip if we 
have the UNIX.mode
-                doUnixPerms(file, valueLowerCase);
+                        } // digits
+                    } // mode
+                } // unix.
+                else if (!hasUnixMode && "perm".equals(factname)) { // skip if 
we have the UNIX.mode
+                    doUnixPerms(file, valueLowerCase);
+                }
+                break;
             } // process "perm"
         } // each fact
         return file;

Reply via email to