From 91c14e9e7fcc032dbe86073b0210eb2745e3f28a Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Thu, 19 Mar 2009 22:14:17 +0100 Subject: [PATCH] Expose all volatile and metadata fields. --- src/net/pterodactylus/fcp/Peer.java | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) 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 -- 2.7.4