james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [04/24] james-project git commit: JAMES-2366 More functional style for MemoryRecipientRewriteTable
Date Tue, 03 Apr 2018 10:02:50 GMT
JAMES-2366 More functional style for MemoryRecipientRewriteTable


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

Branch: refs/heads/master
Commit: 32132801faec40ade2bf82da4256385feac447f7
Parents: 8f1689e
Author: benwa <btellier@linagora.com>
Authored: Wed Mar 28 10:10:58 2018 +0700
Committer: benwa <btellier@linagora.com>
Committed: Tue Apr 3 16:58:21 2018 +0700

----------------------------------------------------------------------
 .../rrt/memory/MemoryRecipientRewriteTable.java | 28 ++++++++++----------
 1 file changed, 14 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/32132801/server/data/data-memory/src/main/java/org/apache/james/rrt/memory/MemoryRecipientRewriteTable.java
----------------------------------------------------------------------
diff --git a/server/data/data-memory/src/main/java/org/apache/james/rrt/memory/MemoryRecipientRewriteTable.java
b/server/data/data-memory/src/main/java/org/apache/james/rrt/memory/MemoryRecipientRewriteTable.java
index 6b8e1c7..2662e13 100644
--- a/server/data/data-memory/src/main/java/org/apache/james/rrt/memory/MemoryRecipientRewriteTable.java
+++ b/server/data/data-memory/src/main/java/org/apache/james/rrt/memory/MemoryRecipientRewriteTable.java
@@ -26,6 +26,7 @@ import java.util.Map;
 import java.util.Optional;
 import java.util.stream.Stream;
 
+import org.apache.commons.lang3.tuple.Pair;
 import org.apache.james.core.Domain;
 import org.apache.james.rrt.api.RecipientRewriteTableException;
 import org.apache.james.rrt.lib.AbstractRecipientRewriteTable;
@@ -33,8 +34,8 @@ import org.apache.james.rrt.lib.Mapping;
 import org.apache.james.rrt.lib.Mappings;
 import org.apache.james.rrt.lib.MappingsImpl;
 
+import com.github.steveash.guavate.Guavate;
 import com.google.common.base.Objects;
-import com.google.common.collect.Maps;
 import com.google.common.collect.Multimaps;
 
 public class MemoryRecipientRewriteTable extends AbstractRecipientRewriteTable {
@@ -121,19 +122,18 @@ public class MemoryRecipientRewriteTable extends AbstractRecipientRewriteTable
{
         if (mappingEntries.isEmpty()) {
             return null;
         }
-        Map<String, Collection<Mappings>> userMappingsMap = Multimaps.transformEntries(
-            Multimaps.index(mappingEntries, InMemoryMappingEntry::asKey),
-            (Maps.EntryTransformer<String, InMemoryMappingEntry, Mappings>)
-                (s, mappingEntry) -> MappingsImpl.fromMappings(Stream.of(mappingEntry.getMapping())))
-            .asMap();
-        return Maps.transformEntries(userMappingsMap,
-            (s, mappingsList) -> {
-                Mappings result = MappingsImpl.empty();
-                for (Mappings mappings : mappingsList) {
-                    result = result.union(mappings);
-                }
-                return result;
-            });
+        return Multimaps.index(mappingEntries, InMemoryMappingEntry::asKey)
+            .asMap()
+            .entrySet()
+            .stream()
+            .map(entry -> Pair.of(entry.getKey(), toMappings(entry.getValue())))
+            .collect(Guavate.toImmutableMap(Pair::getKey, Pair::getValue));
+    }
+
+    private MappingsImpl toMappings(Collection<InMemoryMappingEntry> inMemoryMappingEntries)
{
+        return MappingsImpl.fromMappings(inMemoryMappingEntries
+            .stream()
+            .map(InMemoryMappingEntry::getMapping));
     }
 
     private Optional<Mappings> retrieveMappings(final String user, final Domain domain)
{


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