From f7e2853aebdd167cf73fceeb7bc2e4f92dc3547e Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Fri, 8 Apr 2011 17:17:50 +0200 Subject: [PATCH] Add method to retrieve a boolean from the simple field set. --- .../sone/freenet/fcp/AbstractCommand.java | 36 ++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/main/java/net/pterodactylus/sone/freenet/fcp/AbstractCommand.java b/src/main/java/net/pterodactylus/sone/freenet/fcp/AbstractCommand.java index 6018c38..538876a 100644 --- a/src/main/java/net/pterodactylus/sone/freenet/fcp/AbstractCommand.java +++ b/src/main/java/net/pterodactylus/sone/freenet/fcp/AbstractCommand.java @@ -88,4 +88,40 @@ public abstract class AbstractCommand implements Command { return simpleFieldSet.getInt(key, defaultValue); } + /** + * Returns a boolean value from the given simple field set. + * + * @param simpleFieldSet + * The simple field set to get the value from + * @param key + * The key of the value + * @return The boolean value + * @throws FcpException + * if there is no value for the given key in the simple field + * set, or the value can not be converted to a boolean + */ + protected boolean getBoolean(SimpleFieldSet simpleFieldSet, String key) throws FcpException { + try { + return simpleFieldSet.getBoolean(key); + } catch (FSParseException fspe1) { + throw new FcpException("Could not get parameter “" + key + "” as boolean.", fspe1); + } + } + + /** + * Returns a boolean value from the given simple field set, returning a + * default value if the value can not be found or converted. + * + * @param simpleFieldSet + * The simple field set to get the value from + * @param key + * The key of the value + * @param defaultValue + * The default value + * @return The boolean value + */ + protected boolean getBoolean(SimpleFieldSet simpleFieldSet, String key, boolean defaultValue) { + return simpleFieldSet.getBoolean(key, defaultValue); + } + } -- 2.7.4