X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Ffreenet%2Ffcp%2FAbstractCommand.java;h=6e13a32e49dd411732902cb627eadc36035dc85c;hp=6018c386dfbb230ade6f9f79d28457d2d06d3f48;hb=a47643aed43d118ca68044f95451bb5374cdb332;hpb=c44520f25b0064b9ca6a00b2450445954e8d577e 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..6e13a32 100644 --- a/src/main/java/net/pterodactylus/sone/freenet/fcp/AbstractCommand.java +++ b/src/main/java/net/pterodactylus/sone/freenet/fcp/AbstractCommand.java @@ -1,5 +1,5 @@ /* - * Sone - AbstractCommand.java - Copyright © 2011 David Roden + * Sone - AbstractCommand.java - Copyright © 2011–2012 David Roden * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -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); + } + }