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 aaf61a9f0c328e74715844b14be183335f06bfd0
Author: Benoit Tellier <btell...@linagora.com>
AuthorDate: Thu Jan 16 14:19:25 2020 +0700

    [REFACTORING] s/StringValidator/StringMatcherCharacterValidator/
---
 .../james/imap/decode/ImapRequestLineReader.java    | 21 +++++++++++----------
 .../parser/AbstractSelectionCommandParser.java      |  6 +++---
 .../imap/decode/parser/FetchCommandParser.java      |  6 +++---
 .../imap/decode/parser/StoreCommandParser.java      |  4 ++--
 ...ava => StringMatcherCharacterValidatorTest.java} | 16 ++++++++--------
 5 files changed, 27 insertions(+), 26 deletions(-)

diff --git 
a/protocols/imap/src/main/java/org/apache/james/imap/decode/ImapRequestLineReader.java
 
b/protocols/imap/src/main/java/org/apache/james/imap/decode/ImapRequestLineReader.java
index 79f5a1b..ac0e7d9 100644
--- 
a/protocols/imap/src/main/java/org/apache/james/imap/decode/ImapRequestLineReader.java
+++ 
b/protocols/imap/src/main/java/org/apache/james/imap/decode/ImapRequestLineReader.java
@@ -31,7 +31,6 @@ import java.nio.charset.CodingErrorAction;
 import java.time.LocalDateTime;
 import java.util.ArrayList;
 import java.util.List;
-import java.util.function.BiPredicate;
 
 import javax.mail.Flags;
 
@@ -818,31 +817,33 @@ public abstract class ImapRequestLineReader {
     /**
      * Verifies subsequent characters match a specified string
      */
-    public static class StringValidator implements CharacterValidator {
-        public static StringValidator caseIncentive(String expectedString) {
-            return new StringValidator(expectedString,
-                (c1, c2) -> isaBoolean(c1, c2));
+    public static class StringMatcherCharacterValidator implements 
CharacterValidator {
+        public static StringMatcherCharacterValidator ignoreCase(String 
expectedString) {
+            return new StringMatcherCharacterValidator(expectedString);
         }
 
-        public static boolean isaBoolean(Character c1, Character c2) {
+        static boolean asciiEqualsIgnoringCase(Character c1, Character c2) {
             return Character.toUpperCase(c1) == Character.toUpperCase(c2);
         }
 
         private final String expectedString;
-        private final BiPredicate<Character, Character> equalityTester;
         private int position = 0;
 
-        private StringValidator(String expectedString, BiPredicate<Character, 
Character> equalityTester) {
+        private StringMatcherCharacterValidator(String expectedString) {
             this.expectedString = expectedString;
-            this.equalityTester = equalityTester;
         }
 
+        /**
+         * Verifies whether the next character is valid or not.
+         *
+         * This call will mutate StringValidator internal state, making it 
progress to following character validation.
+         */
         @Override
         public boolean isValid(char chr) {
             if (position >= expectedString.length()) {
                 return false;
             } else {
-                return equalityTester.test(chr, 
expectedString.charAt(position++));
+                return asciiEqualsIgnoringCase(chr, 
expectedString.charAt(position++));
             }
         }
     }
diff --git 
a/protocols/imap/src/main/java/org/apache/james/imap/decode/parser/AbstractSelectionCommandParser.java
 
b/protocols/imap/src/main/java/org/apache/james/imap/decode/parser/AbstractSelectionCommandParser.java
index 758cb8b..3933c5e 100644
--- 
a/protocols/imap/src/main/java/org/apache/james/imap/decode/parser/AbstractSelectionCommandParser.java
+++ 
b/protocols/imap/src/main/java/org/apache/james/imap/decode/parser/AbstractSelectionCommandParser.java
@@ -29,7 +29,7 @@ import 
org.apache.james.imap.api.message.response.StatusResponseFactory;
 import org.apache.james.imap.api.process.ImapSession;
 import org.apache.james.imap.decode.DecodingException;
 import org.apache.james.imap.decode.ImapRequestLineReader;
-import org.apache.james.imap.decode.ImapRequestLineReader.StringValidator;
+import 
org.apache.james.imap.decode.ImapRequestLineReader.StringMatcherCharacterValidator;
 import org.apache.james.imap.decode.base.AbstractImapCommandParser;
 import org.apache.james.imap.message.request.AbstractMailboxSelectionRequest;
 import org.apache.james.mailbox.MessageUid;
@@ -67,12 +67,12 @@ public abstract class AbstractSelectionCommandParser 
extends AbstractImapCommand
             switch (n) {
             case 'C':
                 // It starts with C so it should be CONDSTORE
-                request.consumeWord(StringValidator.caseIncentive(CONDSTORE));
+                
request.consumeWord(StringMatcherCharacterValidator.ignoreCase(CONDSTORE));
                 condstore = true;
                 break;
             case 'Q':
                 // It starts with Q so it should be QRESYNC
-                request.consumeWord(StringValidator.caseIncentive(QRESYNC));
+                
request.consumeWord(StringMatcherCharacterValidator.ignoreCase(QRESYNC));
                 
                 // Consume the SP
                 request.consumeChar(' ');
diff --git 
a/protocols/imap/src/main/java/org/apache/james/imap/decode/parser/FetchCommandParser.java
 
b/protocols/imap/src/main/java/org/apache/james/imap/decode/parser/FetchCommandParser.java
index caf93cc..d9b2fc2 100644
--- 
a/protocols/imap/src/main/java/org/apache/james/imap/decode/parser/FetchCommandParser.java
+++ 
b/protocols/imap/src/main/java/org/apache/james/imap/decode/parser/FetchCommandParser.java
@@ -43,7 +43,7 @@ import org.apache.james.imap.api.process.ImapSession;
 import org.apache.james.imap.decode.DecodingException;
 import org.apache.james.imap.decode.FetchPartPathDecoder;
 import org.apache.james.imap.decode.ImapRequestLineReader;
-import org.apache.james.imap.decode.ImapRequestLineReader.StringValidator;
+import 
org.apache.james.imap.decode.ImapRequestLineReader.StringMatcherCharacterValidator;
 import org.apache.james.imap.message.request.FetchRequest;
 
 /**
@@ -90,12 +90,12 @@ public class FetchCommandParser extends 
AbstractUidCommandParser {
                 switch (next) {
                 case 'C':
                     // Now check for the CHANGEDSINCE option which is part of 
CONDSTORE
-                    
request.consumeWord(StringValidator.caseIncentive(CHANGEDSINCE));
+                    
request.consumeWord(StringMatcherCharacterValidator.ignoreCase(CHANGEDSINCE));
                     fetch.changedSince(request.number(true));
                     break;
                 case 'V':
                     // Check for the VANISHED option which is part of QRESYNC
-                    
request.consumeWord(StringValidator.caseIncentive(VANISHED));
+                    
request.consumeWord(StringMatcherCharacterValidator.ignoreCase(VANISHED));
                     fetch.vanished(true);
                     break;
                 default:
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 d161f14..4ae9d6b 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
@@ -31,7 +31,7 @@ import 
org.apache.james.imap.api.message.response.StatusResponseFactory;
 import org.apache.james.imap.api.process.ImapSession;
 import org.apache.james.imap.decode.DecodingException;
 import org.apache.james.imap.decode.ImapRequestLineReader;
-import org.apache.james.imap.decode.ImapRequestLineReader.StringValidator;
+import 
org.apache.james.imap.decode.ImapRequestLineReader.StringMatcherCharacterValidator;
 import org.apache.james.imap.message.request.StoreRequest;
 import org.apache.james.mailbox.MessageManager;
 
@@ -55,7 +55,7 @@ public class StoreCommandParser extends 
AbstractUidCommandParser {
             // Seems like we have a CONDSTORE parameter
             request.consume();
 
-            request.consumeWord(StringValidator.caseIncentive(UNCHANGEDSINCE));
+            
request.consumeWord(StringMatcherCharacterValidator.ignoreCase(UNCHANGEDSINCE));
             request.consumeChar(' ');
             unchangedSince = request.number(true);
             request.consumeChar(')');
diff --git 
a/protocols/imap/src/test/java/org/apache/james/imap/decode/StringValidatorTest.java
 
b/protocols/imap/src/test/java/org/apache/james/imap/decode/StringMatcherCharacterValidatorTest.java
similarity index 73%
rename from 
protocols/imap/src/test/java/org/apache/james/imap/decode/StringValidatorTest.java
rename to 
protocols/imap/src/test/java/org/apache/james/imap/decode/StringMatcherCharacterValidatorTest.java
index e1220ca..83271a3 100644
--- 
a/protocols/imap/src/test/java/org/apache/james/imap/decode/StringValidatorTest.java
+++ 
b/protocols/imap/src/test/java/org/apache/james/imap/decode/StringMatcherCharacterValidatorTest.java
@@ -19,36 +19,36 @@
 
 package org.apache.james.imap.decode;
 
-import static 
org.apache.james.imap.decode.ImapRequestLineReader.StringValidator;
+import static 
org.apache.james.imap.decode.ImapRequestLineReader.StringMatcherCharacterValidator;
 import static org.assertj.core.api.Assertions.assertThat;
 
 import org.junit.jupiter.api.Test;
 
-class StringValidatorTest {
+class StringMatcherCharacterValidatorTest {
     @Test
     void isValidShouldReturnFalseWhenDifferent() {
-        StringValidator stringValidator = 
StringValidator.caseIncentive("expected");
+        StringMatcherCharacterValidator stringMatcherCharacterValidator = 
StringMatcherCharacterValidator.ignoreCase("expected");
         assertThat(
             "different".chars().mapToObj(i -> (char) i)
-                .allMatch(stringValidator::isValid))
+                .allMatch(stringMatcherCharacterValidator::isValid))
             .isFalse();
     }
 
     @Test
     void isValidShouldReturnTrueWhenSame() {
-        StringValidator stringValidator = 
StringValidator.caseIncentive("expected");
+        StringMatcherCharacterValidator stringMatcherCharacterValidator = 
StringMatcherCharacterValidator.ignoreCase("expected");
         assertThat(
             "expected".chars().mapToObj(i -> (char) i)
-                .allMatch(stringValidator::isValid))
+                .allMatch(stringMatcherCharacterValidator::isValid))
             .isTrue();
     }
 
     @Test
     void isValidShouldShouldReturnTrueOnCaseDifference() {
-        StringValidator stringValidator = 
StringValidator.caseIncentive("expected");
+        StringMatcherCharacterValidator stringMatcherCharacterValidator = 
StringMatcherCharacterValidator.ignoreCase("expected");
         assertThat(
             "eXpeCTed".chars().mapToObj(i -> (char) i)
-                .allMatch(stringValidator::isValid))
+                .allMatch(stringMatcherCharacterValidator::isValid))
             .isTrue();
     }
 }
\ No newline at end of file


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

Reply via email to