You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by rc...@apache.org on 2020/02/13 02:29:30 UTC

[james-project] 19/21: [REFACTORING] Use switch instead of chained 'if' within StoreCommandParser

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

rcordier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 4dd7fbe3c3a0d484e0428a56ecb939430f7e6755
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Tue Jan 14 09:51:09 2020 +0700

    [REFACTORING] Use switch instead of chained 'if' within StoreCommandParser
---
 .../imap/decode/parser/StoreCommandParser.java     | 33 ++++++++++++----------
 1 file changed, 18 insertions(+), 15 deletions(-)

diff --git a/protocols/imap/src/main/java/org/apache/james/imap/decode/parser/StoreCommandParser.java b/protocols/imap/src/main/java/org/apache/james/imap/decode/parser/StoreCommandParser.java
index a00df86..d161f14 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/decode/parser/StoreCommandParser.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/decode/parser/StoreCommandParser.java
@@ -18,6 +18,8 @@
  ****************************************************************/
 package org.apache.james.imap.decode.parser;
 
+import java.util.Locale;
+
 import javax.mail.Flags;
 
 import org.apache.james.imap.api.ImapConstants;
@@ -91,25 +93,26 @@ public class StoreCommandParser extends AbstractUidCommandParser {
     }
 
     private boolean parseSilent(String directive) throws DecodingException {
-        if ("FLAGS".equalsIgnoreCase(directive)) {
-            return false;
-        } else if ("FLAGS.SILENT".equalsIgnoreCase(directive)) {
-            return true;
-        } else {
-            throw new DecodingException(HumanReadableText.ILLEGAL_ARGUMENTS, "Invalid Store Directive: '" + directive + "'");
+        switch (directive.toUpperCase(Locale.US)) {
+            case "FLAGS":
+                return false;
+            case "FLAGS.SILENT":
+                return true;
+            default:
+                throw new DecodingException(HumanReadableText.ILLEGAL_ARGUMENTS, "Invalid Store Directive: '" + directive + "'");
         }
     }
 
     private MessageManager.FlagsUpdateMode parseFlagsUpdateMode(ImapRequestLineReader request, char next) throws DecodingException {
-        if (next == '+') {
-            MessageManager.FlagsUpdateMode flagsUpdateMode = MessageManager.FlagsUpdateMode.ADD;
-            request.consume();
-            return flagsUpdateMode;
-        } else if (next == '-') {
-            MessageManager.FlagsUpdateMode flagsUpdateMode = MessageManager.FlagsUpdateMode.REMOVE;
-            request.consume();
-            return flagsUpdateMode;
+        switch (next) {
+            case '+':
+                request.consume();
+                return MessageManager.FlagsUpdateMode.ADD;
+            case '-':
+                request.consume();
+                return MessageManager.FlagsUpdateMode.REMOVE;
+            default:
+                return MessageManager.FlagsUpdateMode.REPLACE;
         }
-        return MessageManager.FlagsUpdateMode.REPLACE;
     }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org