From: David ‘Bombe’ Roden Date: Thu, 19 Mar 2009 21:14:17 +0000 (+0100) Subject: Expose all volatile and metadata fields. X-Git-Tag: v0.1.1~101 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=91c14e9e7fcc032dbe86073b0210eb2745e3f28a;p=jFCPlib.git Expose all volatile and metadata fields. --- diff --git a/src/net/pterodactylus/fcp/Peer.java b/src/net/pterodactylus/fcp/Peer.java index 9fd9665..68b970b 100644 --- a/src/net/pterodactylus/fcp/Peer.java +++ b/src/net/pterodactylus/fcp/Peer.java @@ -19,6 +19,11 @@ package net.pterodactylus.fcp; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; + /** * The “Peer” reply by the node contains information about a peer. * @@ -183,6 +188,21 @@ public class Peer extends BaseMessage { } /** + * Returns all volatile fields from the message. + * + * @return All volatile files + */ + public Map getVolatileFields() { + Map volatileFields = new HashMap(); + for (Entry field : getFields().entrySet()) { + if (field.getKey().startsWith("volatile.")) { + volatileFields.put(field.getKey(), field.getValue()); + } + } + return Collections.unmodifiableMap(volatileFields); + } + + /** * Returns one of the volatile fields from the message. The given field name * is prepended with “volatile.” so if you want to get the value of the * field with the name “volatile.status” you only need to specify “status”. @@ -197,6 +217,21 @@ public class Peer extends BaseMessage { } /** + * Returns all metadata fields from the message. + * + * @return All volatile files + */ + public Map getMetadataFields() { + Map metadataFields = new HashMap(); + for (Entry field : getFields().entrySet()) { + if (field.getKey().startsWith("metadata.")) { + metadataFields.put(field.getKey(), field.getValue()); + } + } + return Collections.unmodifiableMap(metadataFields); + } + + /** * Returns one of the metadata fields from the message. The given field name * is prepended with “metadata.” so if you want to get the value of the * field with the name “metadata.timeLastRoutable” you only need to specify