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;
private final Map<String, Post> allPosts = new HashMap<String, Post>();
/** All posts by their Sones. */
- private final Map<String, Collection<Post>> sonePosts = new HashMap<String, Collection<Post>>();
+ private final Multimap<String, Post> sonePosts = HashMultimap.create();
/** All posts by their recipient. */
private final Map<String, Collection<Post>> recipientPosts = new HashMap<String, Collection<Post>>();
* @return All posts
*/
private Collection<Post> getPostsFrom(String soneId) {
- Collection<Post> 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<Post>();
- lock.writeLock().lock();
- try {
- sonePosts.put(soneId, posts);
- } finally {
- lock.writeLock().unlock();
- }
-
- return posts;
}
/**