From: David ‘Bombe’ Roden Date: Fri, 8 Apr 2011 12:56:26 +0000 (+0200) Subject: Add abstract basic Command implementation with helper methods. X-Git-Tag: 0.6.5^2~39^2~47 X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=commitdiff_plain;h=563f8b891e518a9b54396c8ef83aab9d51192c59 Add abstract basic Command implementation with helper methods. --- diff --git a/src/main/java/net/pterodactylus/sone/freenet/fcp/AbstractCommand.java b/src/main/java/net/pterodactylus/sone/freenet/fcp/AbstractCommand.java new file mode 100644 index 0000000..8c155e5 --- /dev/null +++ b/src/main/java/net/pterodactylus/sone/freenet/fcp/AbstractCommand.java @@ -0,0 +1,55 @@ +/* + * Sone - AbstractCommand.java - Copyright © 2011 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.pterodactylus.sone.freenet.fcp; + +import freenet.node.FSParseException; +import freenet.support.SimpleFieldSet; + +/** + * Basic implementation of a {@link Command} with various helper methods to + * simplify processing of input parameters. + * + * @author David ‘Bombe’ Roden + */ +public abstract class AbstractCommand implements Command { + + // + // PROTECTED METHODS + // + + /** + * Returns a String 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 String 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 String + */ + protected String getString(SimpleFieldSet simpleFieldSet, String key) throws FcpException { + try { + return simpleFieldSet.getString(key); + } catch (FSParseException fspe1) { + throw new FcpException("Could not get parameter “" + key + "” as String.", fspe1); + } + } + +}