From e641b6984bf4d67fb842d7a858e8521f2b34155f 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:43:10 +0200 Subject: [PATCH] Use a multimap to store posts with recipienets. --- .../sone/database/memory/MemoryDatabase.java | 18 ++---------------- 1 file changed, 2 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 238c533..d7e9f58 100644 --- a/src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.java +++ b/src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.java @@ -84,7 +84,7 @@ public class MemoryDatabase extends AbstractService implements Database { private final Multimap sonePosts = HashMultimap.create(); /** All posts by their recipient. */ - private final Map> recipientPosts = new HashMap>(); + private final Multimap recipientPosts = HashMultimap.create(); /** Whether posts are known. */ private final Set knownPosts = new HashSet(); @@ -627,26 +627,12 @@ public class MemoryDatabase extends AbstractService implements Database { * @return All posts */ private Collection getPostsTo(String recipientId) { - Collection posts = null; lock.readLock().lock(); try { - posts = recipientPosts.get(recipientId); + return recipientPosts.get(recipientId); } finally { lock.readLock().unlock(); } - if (posts != null) { - return posts; - } - - posts = new HashSet(); - lock.writeLock().lock(); - try { - recipientPosts.put(recipientId, posts); - } finally { - lock.writeLock().unlock(); - } - - return posts; } /** Loads the known posts. */ -- 2.7.4