Skip to content

Commit

Permalink
MAILET-124 Simplify Not composite matcher
Browse files Browse the repository at this point in the history
  • Loading branch information
chibenwa committed Sep 15, 2016
1 parent cc718f0 commit beb9cd6
Showing 1 changed file with 7 additions and 13 deletions.
Expand Up @@ -29,6 +29,8 @@

import javax.mail.MessagingException;

import com.google.common.base.Optional;

public class Not extends GenericCompositeMatcher {

/**
Expand All @@ -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;
Expand Down

0 comments on commit beb9cd6

Please sign in to comment.