X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fdatabase%2Fmemory%2FMemoryBookmarkDatabase.java;h=4c4bc3fd0e3b9ce35a92963a406cafaa0dac7776;hp=aae93dd3cde38c6530768327487227a547b6afba;hb=cbd6de75a2a96966a2381100c5b643feea702458;hpb=308b94c1c75e55637644142e2553aec8d7ce01ad 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 aae93dd..4c4bc3f 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,6 +9,7 @@ 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; @@ -74,6 +76,7 @@ public class MemoryBookmarkDatabase implements BookmarkDatabase { lock.writeLock().lock(); try { bookmarkedPosts.remove(post.getId()); + saveBookmarkedPosts(); } finally { lock.writeLock().unlock(); } @@ -93,11 +96,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 {