From d7f274ad71b8768637d2bd412211a5d982e6fd36 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Fri, 8 Apr 2011 17:25:09 +0200 Subject: [PATCH] Add method to encode liking information. --- .../sone/fcp/AbstractSoneCommand.java | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) 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(); + } + } -- 2.7.4