X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fdatabase%2Fmemory%2FMemoryBookmarkDatabase.java;h=1a4e1193327c3c660a4df5473e40ecc625b91da5;hb=23e09dfc13a0cc6dfc7d7b8cc09c78acc6984ec7;hp=38c5bd05801f4d126689a83a9f8d8d07be8a2251;hpb=04fbdc3d76e3b1140d178dc2600141ec92d22637;p=Sone.git
diff --git a/src/main/java/net/pterodactylus/sone/database/memory/MemoryBookmarkDatabase.java b/src/main/java/net/pterodactylus/sone/database/memory/MemoryBookmarkDatabase.java
index 38c5bd0..1a4e119 100644
--- a/src/main/java/net/pterodactylus/sone/database/memory/MemoryBookmarkDatabase.java
+++ b/src/main/java/net/pterodactylus/sone/database/memory/MemoryBookmarkDatabase.java
@@ -1,5 +1,6 @@
package net.pterodactylus.sone.database.memory;
+import static com.google.common.base.Optional.fromNullable;
import static com.google.common.collect.FluentIterable.from;
import java.util.HashSet;
@@ -8,21 +9,20 @@ import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import net.pterodactylus.sone.data.Post;
+import net.pterodactylus.sone.data.Post.EmptyPost;
import net.pterodactylus.sone.database.BookmarkDatabase;
import com.google.common.base.Function;
/**
* Memory-based {@link BookmarkDatabase} implementation.
- *
- * @author David âBombeâ Roden
*/
public class MemoryBookmarkDatabase implements BookmarkDatabase {
private final ReadWriteLock lock = new ReentrantReadWriteLock();
private final MemoryDatabase memoryDatabase;
private final ConfigurationLoader configurationLoader;
- private final Set bookmarkedPosts = new HashSet();
+ private final Set bookmarkedPosts = new HashSet<>();
public MemoryBookmarkDatabase(MemoryDatabase memoryDatabase,
ConfigurationLoader configurationLoader) {
@@ -94,11 +94,12 @@ public class MemoryBookmarkDatabase implements BookmarkDatabase {
public Set getBookmarkedPosts() {
lock.readLock().lock();
try {
- return from(bookmarkedPosts).transformAndConcat(
- new Function>() {
+ return from(bookmarkedPosts).transform(
+ new Function() {
@Override
- public Iterable apply(String postId) {
- return memoryDatabase.getPost(postId).asSet();
+ public Post apply(String postId) {
+ return fromNullable(memoryDatabase.getPost(postId))
+ .or(new EmptyPost(postId));
}
}).toSet();
} finally {