james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [01/17] james-project git commit: MAILET-124 Simplify Not composite matcher
Date Thu, 15 Sep 2016 10:08:42 GMT
Repository: james-project
Updated Branches:
  refs/heads/master b3fb0ef51 -> ee6589d5d


MAILET-124 Simplify Not composite matcher


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/beb9cd63
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/beb9cd63
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/beb9cd63

Branch: refs/heads/master
Commit: beb9cd637738235c794acd16f39e83952e005522
Parents: cc718f0
Author: Benoit Tellier <btellier@linagora.com>
Authored: Thu Sep 1 15:20:31 2016 +0700
Committer: Benoit Tellier <btellier@linagora.com>
Committed: Thu Sep 15 11:50:49 2016 +0200

----------------------------------------------------------------------
 .../mailetcontainer/impl/matchers/Not.java      | 20 +++++++-------------
 1 file changed, 7 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/beb9cd63/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/matchers/Not.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/matchers/Not.java
b/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/matchers/Not.java
index 7f44777..d061583 100644
--- a/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/matchers/Not.java
+++ b/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/matchers/Not.java
@@ -29,6 +29,8 @@ import org.apache.mailet.Mail;
 
 import javax.mail.MessagingException;
 
+import com.google.common.base.Optional;
+
 public class Not extends GenericCompositeMatcher {
 
     /**
@@ -41,19 +43,11 @@ public class Not extends GenericCompositeMatcher {
      *         Matcher(s).
      */
     public Collection<MailAddress> match(Mail mail) throws MessagingException {
-        Collection<MailAddress> finalResult = mail.getRecipients();
-        Matcher matcher;
-        for (Iterator<Matcher> matcherIter = iterator(); matcherIter.hasNext();) {
-            matcher = (matcherIter.next());
-            // log("Matching with " +
-            // matcher.getMatcherConfig().getMatcherName());
-            Collection<MailAddress> result = matcher.match(mail);
-            if (result == finalResult) {
-                // Not is an empty list
-                finalResult = null;
-            } else if (result != null) {
-                finalResult = new ArrayList<MailAddress>(finalResult);
-                finalResult.removeAll(result);
+        Collection<MailAddress> finalResult = Optional.fromNullable(mail.getRecipients()).or(new
ArrayList<MailAddress>());
+        for (Matcher matcher : getMatchers()) {
+            Collection<MailAddress> matcherResult = matcher.match(mail);
+            if (matcherResult != null) {
+                finalResult.removeAll(matcherResult);
             }
         }
         return finalResult;


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


Mime
View raw message