You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2024/09/12 14:36:12 UTC
(commons-net) branch master updated (3f9b234a -> c6557d39)
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/commons-net.git
from 3f9b234a Merge pull request #283 from apache/dependabot/github_actions/actions/upload-artifact-4.4.0
new 98d6395b Convert cascading if-else to switch
new 15e3f6ef Convert cascading if-else to switch
new 9246a5b7 Convert cascading if-else to switch
new c6557d39 Convert cascading if-else to switch
The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../commons/net/examples/ftp/FTPClientExample.java | 20 +++++---
.../commons/net/examples/ftp/TFTPExample.java | 22 +++++---
.../commons/net/ftp/parser/MLSxEntryParser.java | 58 +++++++++++++---------
.../org/apache/commons/net/imap/IMAPReply.java | 11 ++--
4 files changed, 69 insertions(+), 42 deletions(-)
(commons-net) 01/04: Convert cascading if-else to switch
Posted by gg...@apache.org.
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 98d6395b60d7431e496245fb718ec5ea8634cf39
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Thu Sep 12 10:32:33 2024 -0400
Convert cascading if-else to switch
---
.../commons/net/examples/ftp/FTPClientExample.java | 20 ++++++++++++++------
1 file changed, 14 insertions(+), 6 deletions(-)
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 126c9a7c..bd83852c 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
@@ -255,12 +255,20 @@ public final class FTPClientExample {
}
}
ftp = ftps;
- if ("all".equals(trustmgr)) {
- ftps.setTrustManager(TrustManagerUtils.getAcceptAllTrustManager());
- } else if ("valid".equals(trustmgr)) {
- ftps.setTrustManager(TrustManagerUtils.getValidateServerCertificateTrustManager());
- } else if ("none".equals(trustmgr)) {
- ftps.setTrustManager(null);
+ if (trustmgr != null) {
+ switch (trustmgr) {
+ case "all":
+ ftps.setTrustManager(TrustManagerUtils.getAcceptAllTrustManager());
+ break;
+ case "valid":
+ ftps.setTrustManager(TrustManagerUtils.getValidateServerCertificateTrustManager());
+ break;
+ case "none":
+ ftps.setTrustManager(null);
+ break;
+ default:
+ break;
+ }
}
}
(commons-net) 03/04: Convert cascading if-else to switch
Posted by gg...@apache.org.
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 <ga...@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;
(commons-net) 04/04: Convert cascading if-else to switch
Posted by gg...@apache.org.
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 c6557d391ab75e339c3fc11e0a90fff5007be9a3
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Thu Sep 12 10:36:05 2024 -0400
Convert cascading if-else to switch
---
.../commons/net/examples/ftp/TFTPExample.java | 22 +++++++++++++++-------
1 file changed, 15 insertions(+), 7 deletions(-)
diff --git a/src/main/java/org/apache/commons/net/examples/ftp/TFTPExample.java b/src/main/java/org/apache/commons/net/examples/ftp/TFTPExample.java
index 7c6ee9cd..76feaf9d 100644
--- a/src/main/java/org/apache/commons/net/examples/ftp/TFTPExample.java
+++ b/src/main/java/org/apache/commons/net/examples/ftp/TFTPExample.java
@@ -79,22 +79,30 @@ public final class TFTPExample {
if (!arg.startsWith("-")) {
break;
}
- if (arg.equals("-r")) {
+ switch (arg) {
+ case "-r":
receiveFile = true;
- } else if (arg.equals("-s")) {
+ break;
+ case "-s":
receiveFile = false;
- } else if (arg.equals("-a")) {
+ break;
+ case "-a":
transferMode = TFTP.ASCII_MODE;
- } else if (arg.equals("-b")) {
+ break;
+ case "-b":
transferMode = TFTP.BINARY_MODE;
- } else if (arg.equals("-t")) {
+ break;
+ case "-t":
timeout = 1000 * Integer.parseInt(args[++argc]);
- } else if (arg.equals("-v")) {
+ break;
+ case "-v":
verbose = true;
- } else {
+ break;
+ default:
System.err.println("Error: unrecognized option.");
System.err.print(USAGE);
System.exit(1);
+ break;
}
}
(commons-net) 02/04: Convert cascading if-else to switch
Posted by gg...@apache.org.
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 15e3f6ef39157a4cd1bd04630f07c1998d860465
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Thu Sep 12 10:32:44 2024 -0400
Convert cascading if-else to switch
---
src/main/java/org/apache/commons/net/imap/IMAPReply.java | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/src/main/java/org/apache/commons/net/imap/IMAPReply.java b/src/main/java/org/apache/commons/net/imap/IMAPReply.java
index 59f954f7..ea8706d8 100644
--- a/src/main/java/org/apache/commons/net/imap/IMAPReply.java
+++ b/src/main/java/org/apache/commons/net/imap/IMAPReply.java
@@ -111,14 +111,15 @@ public final class IMAPReply {
final Matcher m = pattern.matcher(line);
if (m.matches()) { // TODO would lookingAt() be more efficient? If so, then drop trailing .* from patterns
final String code = m.group(1);
- if (code.equals(IMAP_OK)) {
+ switch (code) {
+ case IMAP_OK:
return OK;
- }
- if (code.equals(IMAP_BAD)) {
+ case IMAP_BAD:
return BAD;
- }
- if (code.equals(IMAP_NO)) {
+ case IMAP_NO:
return NO;
+ default:
+ break;
}
}
throw new MalformedServerReplyException("Received unexpected IMAP protocol response from server: '" + line + "'.");