From 84c51832a2d10656e85c2d6eeb45998c34998da4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Mon, 2 Jun 2014 06:40:23 +0200 Subject: [PATCH] =?utf8?q?Use=20a=20Multimap=20to=20store=20a=20Sone?= =?utf8?q?=E2=80=99s=20posts.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../sone/database/memory/MemoryDatabase.java | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.java b/src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.java index 8b25954..61eb9be 100644 --- a/src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.java +++ b/src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.java @@ -54,6 +54,8 @@ import net.pterodactylus.util.config.Configuration; import net.pterodactylus.util.config.ConfigurationException; import com.google.common.base.Optional; +import com.google.common.collect.HashMultimap; +import com.google.common.collect.Multimap; import com.google.common.collect.SortedSetMultimap; import com.google.common.collect.TreeMultimap; import com.google.common.util.concurrent.AbstractService; @@ -79,7 +81,7 @@ public class MemoryDatabase extends AbstractService implements Database { private final Map allPosts = new HashMap(); /** All posts by their Sones. */ - private final Map> sonePosts = new HashMap>(); + private final Multimap sonePosts = HashMultimap.create(); /** All posts by their recipient. */ private final Map> recipientPosts = new HashMap>(); @@ -608,26 +610,12 @@ public class MemoryDatabase extends AbstractService implements Database { * @return All posts */ private Collection getPostsFrom(String soneId) { - Collection posts = null; lock.readLock().lock(); try { - posts = sonePosts.get(soneId); + return sonePosts.get(soneId); } finally { lock.readLock().unlock(); } - if (posts != null) { - return posts; - } - - posts = new HashSet(); - lock.writeLock().lock(); - try { - sonePosts.put(soneId, posts); - } finally { - lock.writeLock().unlock(); - } - - return posts; } /** -- 2.7.4