james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [08/12] james-project git commit: JAMES-2555 Do not use null to represent event absence
Date Fri, 12 Oct 2018 08:28:59 GMT
JAMES-2555 Do not use null to represent event absence


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

Branch: refs/heads/master
Commit: fbe7900db3364fb593eadadd3e49f3d97316fb81
Parents: 62e79d1
Author: Benoit Tellier <btellier@linagora.com>
Authored: Tue Oct 9 09:01:35 2018 +0700
Committer: Benoit Tellier <btellier@linagora.com>
Committed: Fri Oct 12 15:27:13 2018 +0700

----------------------------------------------------------------------
 .../mailbox/tools/indexer/ReIndexerImpl.java     | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/fbe7900d/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ReIndexerImpl.java
----------------------------------------------------------------------
diff --git a/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ReIndexerImpl.java
b/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ReIndexerImpl.java
index 413f6b7..72a6746 100644
--- a/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ReIndexerImpl.java
+++ b/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ReIndexerImpl.java
@@ -19,7 +19,6 @@
 
 package org.apache.mailbox.tools.indexer;
 
-import java.util.Collection;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Optional;
@@ -44,7 +43,7 @@ import org.apache.mailbox.tools.indexer.registrations.MailboxRegistration;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import com.google.common.collect.Iterables;
+import com.google.common.collect.Lists;
 
 /**
  * Note about live re-indexation handling :
@@ -135,23 +134,27 @@ public class ReIndexerImpl implements ReIndexer {
     private void handleMailboxIndexingIterations(MailboxSession mailboxSession, MailboxRegistration
mailboxRegistration, Mailbox mailbox, Iterator<MailboxMessage> iterator) throws MailboxException
{
         while (iterator.hasNext()) {
             MailboxMessage message = iterator.next();
-            ImpactingMessageEvent impactingMessageEvent = findMostRelevant(mailboxRegistration.getImpactingEvents(message.getUid()));
+            Optional<ImpactingMessageEvent> impactingMessageEvent = findMostRelevant(mailboxRegistration.getImpactingEvents(message.getUid()));
 
-            impactingMessageEvent.newFlags().ifPresent(message::setFlags);
+            impactingMessageEvent.flatMap(ImpactingMessageEvent::newFlags).ifPresent(message::setFlags);
 
-            if (!impactingMessageEvent.wasDeleted()) {
+            if (wasNotDeleted(impactingMessageEvent)) {
                 messageSearchIndex.add(mailboxSession, mailbox, message);
             }
         }
     }
 
-    private ImpactingMessageEvent findMostRelevant(Collection<ImpactingMessageEvent>
messageEvents) {
+    private boolean wasNotDeleted(Optional<ImpactingMessageEvent> impactingMessageEvent)
{
+        return impactingMessageEvent.map(event -> !event.wasDeleted()).orElse(true);
+    }
+
+    private Optional<ImpactingMessageEvent> findMostRelevant(List<ImpactingMessageEvent>
messageEvents) {
         for (ImpactingMessageEvent impactingMessageEvent : messageEvents) {
             if (impactingMessageEvent.getType().equals(ImpactingEventType.Deletion)) {
-                return impactingMessageEvent;
+                return Optional.of(impactingMessageEvent);
             }
         }
-        return Iterables.getLast(messageEvents, null);
+        return Lists.reverse(messageEvents).stream().findFirst();
     }
 
 }


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