Add method to encode liking information.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 8 Apr 2011 15:25:09 +0000 (17:25 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 8 Apr 2011 15:25:09 +0000 (17:25 +0200)
src/main/java/net/pterodactylus/sone/fcp/AbstractSoneCommand.java

index 6473e4d..8c4085c 100644 (file)
@@ -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<? 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();
+       }
+
 }