X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fcore%2FCore.java;h=bafe7a80406f5c730ff6876be6db07de5ec461c2;hp=862cc789778cfd6e255e44013e1a5bd602340dee;hb=d535f744751ba449e0f34fe3a42f1020988f14be;hpb=c30ad3a3fcfc66d0c1757a50afe413d9942d7793 diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index 862cc78..bafe7a8 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -357,30 +357,9 @@ public class Core extends AbstractService implements SoneProvider, PostProvider, * @return The Sone with the given ID, or {@code null} if there is no such * Sone */ - public Sone getSone(String id) { - return getSone(id, true); - } - - /** - * Returns the Sone with the given ID, regardless whether it’s local or - * remote. - * - * @param id - * The ID of the Sone to get - * @param create - * {@code true} to create a new Sone if none exists, - * {@code false} to return {@code null} if a Sone with the given - * ID does not exist - * @return The Sone with the given ID, or {@code null} if there is no such - * Sone - */ @Override - public Sone getSone(String id, boolean create) { + public Sone getSone(String id) { synchronized (sones) { - if (!sones.containsKey(id) && create) { - Sone sone = new Sone(id, false); - sones.put(id, sone); - } return sones.get(id); } } @@ -544,26 +523,21 @@ public class Core extends AbstractService implements SoneProvider, PostProvider, } /** - * Returns all posts that have the given Sone as recipient. - * - * @see Post#getRecipient() - * @param recipient - * The recipient of the posts - * @return All posts that have the given Sone as recipient + * {@inheritDoc} */ - public Set getDirectedPosts(Sone recipient) { - checkNotNull(recipient, "recipient must not be null"); - Set directedPosts = new HashSet(); + @Override + public Collection getDirectedPosts(final String recipientId) { + checkNotNull(recipientId, "recipient must not be null"); synchronized (posts) { - for (Post post : posts.values()) { - if (recipient.equals(post.getRecipient())) { - directedPosts.add(post); + return Collections2.filter(posts.values(), new Predicate() { + + @Override + public boolean apply(Post post) { + return (post.getRecipient() != null) && (post.getRecipient().getId().equals(recipientId)); } - } + }); } - return directedPosts; } - /** * Returns a post reply builder. * @@ -2359,7 +2333,7 @@ public class Core extends AbstractService implements SoneProvider, PostProvider, /* some local identity still trusts this identity, don’t remove. */ return; } - Sone sone = getSone(identity.getId(), false); + Sone sone = getSone(identity.getId()); if (sone == null) { /* TODO - we don’t have the Sone anymore. should this happen? */ return;