From: David ‘Bombe’ Roden Date: Fri, 8 Apr 2011 15:25:09 +0000 (+0200) Subject: Add method to encode liking information. X-Git-Tag: 0.6.5^2~39^2~21 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=d7f274ad71b8768637d2bd412211a5d982e6fd36;p=Sone.git Add method to encode liking information. --- diff --git a/src/main/java/net/pterodactylus/sone/fcp/AbstractSoneCommand.java b/src/main/java/net/pterodactylus/sone/fcp/AbstractSoneCommand.java index 6473e4d..8c4085c 100644 --- a/src/main/java/net/pterodactylus/sone/fcp/AbstractSoneCommand.java +++ b/src/main/java/net/pterodactylus/sone/fcp/AbstractSoneCommand.java @@ -236,4 +236,28 @@ public abstract class AbstractSoneCommand extends AbstractCommand { return replyBuilder.get(); } + /** + * Creates a simple field set from the given collection of Sones that like + * an element. + * + * @param likes + * The liking Sones + * @param prefix + * The prefix for the field names (may be empty but not + * {@code null}) + * @return The simple field set containing the likes + */ + protected SimpleFieldSet encodeLikes(Collection 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(); + } + }