+ /**
+ * Returns whether the given post is known.
+ *
+ * @param post
+ * The post
+ * @return {@code true} if the post is known, {@code false} otherwise
+ */
+ @Override
+ public boolean isPostKnown(Post post) {
+ lock.readLock().lock();
+ try {
+ return knownPosts.contains(post.getId());
+ } finally {
+ lock.readLock().unlock();
+ }
+ }
+
+ /**
+ * Sets whether the given post is known.
+ *
+ * @param post
+ * The post
+ */
+ @Override
+ public void setPostKnown(Post post) {
+ lock.writeLock().lock();
+ try {
+ knownPosts.add(post.getId());
+ } finally {
+ lock.writeLock().unlock();
+ }
+ }
+
+ @Override
+ public void likePost(Post post, Sone localSone) {
+ lock.writeLock().lock();
+ try {
+ likedPostsBySone.put(localSone.getId(), post.getId());
+ postLikingSones.put(post.getId(), localSone.getId());
+ } finally {
+ lock.writeLock().unlock();
+ }
+ }
+
+ @Override
+ public void unlikePost(Post post, Sone localSone) {
+ lock.writeLock().lock();
+ try {
+ likedPostsBySone.remove(localSone.getId(), post.getId());
+ postLikingSones.remove(post.getId(), localSone.getId());
+ } finally {
+ lock.writeLock().unlock();
+ }
+ }
+
+ public boolean isLiked(Post post, Sone sone) {
+ lock.readLock().lock();
+ try {
+ return likedPostsBySone.containsEntry(sone.getId(), post.getId());
+ } finally {
+ lock.readLock().unlock();
+ }
+ }
+
+ @Override
+ public Set<Sone> getLikes(Post post) {
+ lock.readLock().lock();
+ try {
+ return from(postLikingSones.get(post.getId())).transform(getSone()).transformAndConcat(this.<Sone>unwrap()).toSet();
+ } finally {
+ lock.readLock().unlock();
+ }
+ }
+