From: David ‘Bombe’ Roden Date: Mon, 2 Jun 2014 04:40:23 +0000 (+0200) Subject: Use a Multimap to store a Sone’s posts. X-Git-Tag: 0.9-rc1^2~3^2~258 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=84c51832a2d10656e85c2d6eeb45998c34998da4;p=Sone.git Use a Multimap to store a Sone’s posts. --- 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; } /**