From: David ‘Bombe’ Roden Date: Fri, 8 Apr 2011 13:55:25 +0000 (+0200) Subject: Add method to encode a collection of Sones into a simple field set. X-Git-Tag: 0.6.5^2~39^2~38 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=698fdb0cf7923e58d0fb5dc3695b2e1b811c0816;p=Sone.git Add method to encode a collection of Sones into a simple field set. --- diff --git a/src/main/java/net/pterodactylus/sone/fcp/AbstractSoneCommand.java b/src/main/java/net/pterodactylus/sone/fcp/AbstractSoneCommand.java index 567fe73..a8d8514 100644 --- a/src/main/java/net/pterodactylus/sone/fcp/AbstractSoneCommand.java +++ b/src/main/java/net/pterodactylus/sone/fcp/AbstractSoneCommand.java @@ -26,6 +26,7 @@ import net.pterodactylus.sone.freenet.SimpleFieldSetBuilder; import net.pterodactylus.sone.freenet.fcp.AbstractCommand; import net.pterodactylus.sone.freenet.fcp.Command; import net.pterodactylus.sone.freenet.fcp.FcpException; +import net.pterodactylus.sone.template.SoneAccessor; import freenet.node.FSParseException; import freenet.support.SimpleFieldSet; @@ -94,6 +95,29 @@ public abstract class AbstractSoneCommand extends AbstractCommand { } /** + * Creates a simple field set from the given collection of Sones. + * + * @param sones + * The Sones to encode + * @return The simple field set containing the given Sones + */ + protected SimpleFieldSet encodeSones(Collection sones) { + SimpleFieldSetBuilder soneBuilder = new SimpleFieldSetBuilder(); + + int soneIndex = 0; + soneBuilder.put("Sones.Count", sones.size()); + for (Sone sone : sones) { + String sonePrefix = "Sones." + soneIndex++; + soneBuilder.put(sonePrefix + ".ID", sone.getId()); + soneBuilder.put(sonePrefix + ".Name", sone.getName()); + soneBuilder.put(sonePrefix + ".NiceName", SoneAccessor.getNiceName(sone)); + soneBuilder.put(sonePrefix + ".Time", sone.getTime()); + } + + return soneBuilder.get(); + } + + /** * Creates a simple field set from the given collection of posts. * * @param posts