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=c516f0fffa81fc5e0af8fb81873e07058d6d833f;hp=34759106163567db19c6159e7480a47ebf2d6aea;hb=419098bcd6215125408b29e60bd888e60979d37b;hpb=82ad9f2d7d1731ddcaef241ad94db3a38c92b718 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 3475910..c516f0f 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–2015 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 @@ -44,7 +44,7 @@ public abstract class AbstractCommand implements Command { * if there is no value for the given key in the simple field * set, or the value can not be converted to a String */ - protected String getString(SimpleFieldSet simpleFieldSet, String key) throws FcpException { + protected static String getString(SimpleFieldSet simpleFieldSet, String key) throws FcpException { try { return simpleFieldSet.getString(key); } catch (FSParseException fspe1) { @@ -64,7 +64,7 @@ public abstract class AbstractCommand implements Command { * if there is no value for the given key in the simple field * set, or the value can not be converted to an int */ - protected int getInt(SimpleFieldSet simpleFieldSet, String key) throws FcpException { + protected static int getInt(SimpleFieldSet simpleFieldSet, String key) throws FcpException { try { return simpleFieldSet.getInt(key); } catch (FSParseException fspe1) { @@ -72,4 +72,56 @@ public abstract class AbstractCommand implements Command { } } + /** + * Returns an int 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 int value + */ + protected static int getInt(SimpleFieldSet simpleFieldSet, String key, int defaultValue) { + 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 static 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 static boolean getBoolean(SimpleFieldSet simpleFieldSet, String key, boolean defaultValue) { + return simpleFieldSet.getBoolean(key, defaultValue); + } + }