X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Ffcp%2FAbstractSoneCommand.java;h=8c4085cd15dcc8847407dfd5c9f662f5a53d1e4b;hb=d7f274ad71b8768637d2bd412211a5d982e6fd36;hp=6473e4da0660e5fc64b2330db22aca60e4767fea;hpb=1155e00836b6d71915c13d849cb48f264c07a9d8;p=Sone.git 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(); + } + }