Package net.pterodactylus.sone.freenet

Examples of net.pterodactylus.sone.freenet.SimpleFieldSetBuilder


   *            {@code true} to include replies, {@code false} to not include
   *            replies
   * @return The simple field set containing the post
   */
  protected SimpleFieldSet encodePost(Post post, String prefix, boolean includeReplies) {
    SimpleFieldSetBuilder postBuilder = new SimpleFieldSetBuilder();

    postBuilder.put(prefix + "ID", post.getId());
    postBuilder.put(prefix + "Sone", post.getSone().getId());
    if (post.getRecipientId().isPresent()) {
      postBuilder.put(prefix + "Recipient", post.getRecipientId().get());
    }
    postBuilder.put(prefix + "Time", post.getTime());
    postBuilder.put(prefix + "Text", encodeString(post.getText()));
    postBuilder.put(encodeLikes(core.getLikes(post), prefix + "Likes."));

    if (includeReplies) {
      List<PostReply> replies = core.getReplies(post.getId());
      postBuilder.put(encodeReplies(replies, prefix));
    }

    return postBuilder.get();
  }
View Full Code Here


   *            {@code true} to include the replies, {@code false} to not
   *            include the replies
   * @return The simple field set containing the posts
   */
  protected SimpleFieldSet encodePosts(Collection<? extends Post> posts, String prefix, boolean includeReplies) {
    SimpleFieldSetBuilder postBuilder = new SimpleFieldSetBuilder();

    int postIndex = 0;
    postBuilder.put(prefix + "Count", posts.size());
    for (Post post : posts) {
      String postPrefix = prefix + postIndex++;
      postBuilder.put(encodePost(post, postPrefix + ".", includeReplies));
      if (includeReplies) {
        postBuilder.put(encodeReplies(Collections2.filter(core.getReplies(post.getId()), Reply.FUTURE_REPLY_FILTER), postPrefix + "."));
      }
    }

    return postBuilder.get();
  }
View Full Code Here

   *            The prefix for the field names (may be empty, but not
   *            {@code null})
   * @return The simple field set containing the replies
   */
  protected static SimpleFieldSet encodeReplies(Collection<? extends PostReply> replies, String prefix) {
    SimpleFieldSetBuilder replyBuilder = new SimpleFieldSetBuilder();

    int replyIndex = 0;
    replyBuilder.put(prefix + "Replies.Count", replies.size());
    for (PostReply reply : replies) {
      String replyPrefix = prefix + "Replies." + replyIndex++ + ".";
      replyBuilder.put(replyPrefix + "ID", reply.getId());
      replyBuilder.put(replyPrefix + "Sone", reply.getSone().getId());
      replyBuilder.put(replyPrefix + "Time", reply.getTime());
      replyBuilder.put(replyPrefix + "Text", encodeString(reply.getText()));
    }

    return replyBuilder.get();
  }
View Full Code Here

   *            The prefix for the field names (may be empty but not
   *            {@code null})
   * @return The simple field set containing the likes
   */
  protected static SimpleFieldSet encodeLikes(Collection<? extends Sone> likes, String prefix) {
    SimpleFieldSetBuilder likesBuilder = new SimpleFieldSetBuilder();

    int likeIndex = 0;
    likesBuilder.put(prefix + "Count", likes.size());
    for (Sone sone : likes) {
      String sonePrefix = prefix + likeIndex++ + ".";
      likesBuilder.put(sonePrefix + "ID", sone.getId());
    }

    return likesBuilder.get();
  }
View Full Code Here

TOP

Related Classes of net.pterodactylus.sone.freenet.SimpleFieldSetBuilder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.