james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [02/17] james-project git commit: MAILET-124 Simplify Or composite matcher
Date Thu, 15 Sep 2016 10:08:43 GMT
MAILET-124 Simplify Or 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/cc718f06
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/cc718f06
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/cc718f06

Branch: refs/heads/master
Commit: cc718f06ca094ecdb5778d261a9eff79e583209b
Parents: 185f5b0
Author: Benoit Tellier <btellier@linagora.com>
Authored: Thu Sep 1 15:19:58 2016 +0700
Committer: Benoit Tellier <btellier@linagora.com>
Committed: Thu Sep 15 11:50:49 2016 +0200

----------------------------------------------------------------------
 .../james/mailetcontainer/impl/matchers/Or.java | 70 +++-----------------
 1 file changed, 9 insertions(+), 61 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/cc718f06/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/matchers/Or.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/matchers/Or.java
b/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/matchers/Or.java
index f6d2379..cc7ab84 100644
--- a/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/matchers/Or.java
+++ b/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/matchers/Or.java
@@ -28,78 +28,26 @@ import java.util.Iterator;
 import java.util.ArrayList;
 import javax.mail.MessagingException;
 
+import com.google.common.collect.ImmutableSet;
+
 public class Or extends GenericCompositeMatcher {
 
     /**
      * This is the Or CompositeMatcher - consider it to be a union of the
-     * results. If any match results in a full set of recipients the matching is
-     * short-circuited.
+     * results.
      * 
      * @return Collection of Recipient from the Or composition results of the
      *         child matchers.
      */
     public Collection<MailAddress> match(Mail mail) throws MessagingException {
-        Collection<MailAddress> finalResult = null;
-        Matcher matcher;
-        boolean first = true;
-
-        // the size of the complete set of recipients
-        int size = mail.getRecipients().size();
-
-        // Loop through until the finalResult is full or all the child matchers
-        // have been executed
-        for (Iterator<Matcher> matcherIter = iterator(); matcherIter.hasNext();) {
-            matcher = matcherIter.next();
-            // log("Matching with "
-            // + matcher
-            // .getMatcherConfig()
-            // .getMatcherName()
-            // );
-            Collection<MailAddress> result = matcher.match(mail);
-            if (first) {
-                if (result == null) {
-                    result = new ArrayList<MailAddress>(0);
-                }
-                finalResult = result;
-                first = false;
-            } else {
-                // Check if we need to Or ...
-                // if the finalResult and the subsequent result are the same
-                // collection, then it contains the same recipients
-                // so we can short-circuit building the OR of the two
-                if (finalResult != result) {
-                    if (result != null) {
-                        if (finalResult == null) {
-                            finalResult = result;
-                        } else {
-                            // the two results are different collections, so we
-                            // must OR them
-                            // Ensure that the finalResult only contains one
-                            // copy of the recipients in the result collection
-                            MailAddress recipient;
-                            for (Object aResult : result) {
-                                recipient = (MailAddress) aResult;
-                                if (!finalResult.contains(recipient)) {
-                                    System.out.println(recipient);
-                                    finalResult.add(recipient);
-                                }
-                            }
-                            recipient = null;
-                        }
-                    }
-                }
-            }
-            if (finalResult.size() == size) {
-                // we have a complete set of recipients, no need to OR in
-                // anymore
-                // i.e. short-circuit the Or
-                break;
+        ImmutableSet.Builder<MailAddress> result = ImmutableSet.builder();
+        for (Matcher matcher : getMatchers()) {
+            Collection<MailAddress> matchResult = matcher.match(mail);
+            if (matchResult != null) {
+                result.addAll(matchResult);
             }
-            result = null;
-            matcher = null;
         }
-        // log("OrMatch: end.");
-        return finalResult;
+        return result.build();
     }
 
 }


---------------------------------------------------------------------
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