- * Returns whether the target Sone is trusted by the origin Sone.
- *
- * @param origin
- * The origin Sone
- * @param target
- * The target Sone
- * @return {@code true} if the target Sone is trusted by the origin Sone
- */
- public boolean isSoneTrusted(Sone origin, Sone target) {
- checkNotNull(origin, "origin must not be null");
- checkNotNull(target, "target must not be null");
- checkArgument(origin.getIdentity() instanceof OwnIdentity, "origin’s identity must be an OwnIdentity");
- return trustedIdentities.containsKey(origin.getIdentity()) && trustedIdentities.get(origin.getIdentity()).contains(target.getIdentity());
- }
-
- /**
- * Returns a post builder.
- *
- * @return A new post builder
- */
- public PostBuilder postBuilder() {
- return postBuilderFactory.newPostBuilder();
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public Optional<Post> getPost(String postId) {
- synchronized (posts) {
- return Optional.fromNullable(posts.get(postId));
- }
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public Collection<Post> getDirectedPosts(final String recipientId) {
- checkNotNull(recipientId, "recipient must not be null");
- synchronized (posts) {
- return Collections2.filter(posts.values(), new Predicate<Post>() {
-
- @Override
- public boolean apply(Post post) {
- return (post.getRecipient() != null) && (post.getRecipient().getId().equals(recipientId));
- }
- });
- }
- }
-
- /**
- * Returns a post reply builder.
- *
- * @return A new post reply builder
- */
- public PostReplyBuilder postReplyBuilder() {
- return postReplyBuilderFactory.newPostReplyBuilder();
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public Optional<PostReply> getPostReply(String replyId) {
- synchronized (replies) {
- return Optional.fromNullable(replies.get(replyId));
- }
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public List<PostReply> getReplies(final Post post) {
- return Ordering.from(Reply.TIME_COMPARATOR).sortedCopy(FluentIterable.from(getSones()).transformAndConcat(new Function<Sone, Iterable<PostReply>>() {
-
- @Override
- public Iterable<PostReply> apply(Sone sone) {
- return sone.getReplies();
- }
- }).filter(new Predicate<PostReply>() {
-
- @Override
- public boolean apply(PostReply reply) {
- return post.getId().equals(reply.getPostId());
- }
- }));
- }
-
- /**
- * Returns all Sones that have liked the given post.
- *
- * @param post
- * The post to get the liking Sones for
- * @return The Sones that like the given post
- */
- public Set<Sone> getLikes(Post post) {
- Set<Sone> sones = new HashSet<Sone>();
- for (Sone sone : getSones()) {
- if (sone.getLikedPostIds().contains(post.getId())) {
- sones.add(sone);
- }
- }
- return sones;
- }
-
- /**
- * Returns all Sones that have liked the given reply.
- *
- * @param reply
- * The reply to get the liking Sones for
- * @return The Sones that like the given reply
- */
- public Set<Sone> getLikes(PostReply reply) {
- Set<Sone> sones = new HashSet<Sone>();
- for (Sone sone : getSones()) {
- if (sone.getLikedReplyIds().contains(reply.getId())) {
- sones.add(sone);
- }
- }
- return sones;
- }
-
- /**