X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Ffcp%2FAbstractSoneCommand.java;h=b183121b97a2ac458aa1bc8c719c9d06e95f2586;hb=005de67f1171d7f7608418fcd4a072ead38e7541;hp=f3e29232e4777762cf5d3e164de9429bb99a496c;hpb=45208b1b2ce354f252ef5278bf165395c806c765;p=Sone.git diff --git a/src/main/java/net/pterodactylus/sone/fcp/AbstractSoneCommand.java b/src/main/java/net/pterodactylus/sone/fcp/AbstractSoneCommand.java index f3e2923..b183121 100644 --- a/src/main/java/net/pterodactylus/sone/fcp/AbstractSoneCommand.java +++ b/src/main/java/net/pterodactylus/sone/fcp/AbstractSoneCommand.java @@ -124,6 +124,32 @@ public abstract class AbstractSoneCommand extends AbstractCommand { } /** + * Returns a reply whose ID is a parameter in the given simple field set. + * + * @param simpleFieldSet + * The simple field set containing the ID of the reply + * @param parameterName + * The name under which the reply ID is stored in the simple + * field set + * @return The reply + * @throws FcpException + * if there is no reply ID stored under the given parameter + * name, or if the reply ID is invalid + */ + protected Reply getReply(SimpleFieldSet simpleFieldSet, String parameterName) throws FcpException { + try { + String replyId = simpleFieldSet.getString(parameterName); + Reply reply = core.getReply(replyId, false); + if (reply == null) { + throw new FcpException("Could not load reply from “" + replyId + "”."); + } + return reply; + } catch (FSParseException fspe1) { + throw new FcpException("Could not reply ID from “" + parameterName + "”.", fspe1); + } + } + + /** * Creates a simple field set from the given collection of Sones. * * @param sones