CommandProcessor追加

This commit is contained in:
ろむねこ 2024-06-11 16:10:27 +09:00
parent 142f9c2c6e
commit 4990658f1a
Signed by: Fujimatsu
GPG Key ID: FA1F39A1BA37D168

View File

@ -0,0 +1,39 @@
package one.nem.kidshift.feature.debug;
public class DebugCommandProcessor {
public DebugCommandProcessor() {
}
public String execute(String command) {
try {
return processCommand(command);
} catch (InvalidCommandException e) {
return e.getMessage();
} catch (Exception e) {
return "Something went wrong!";
}
}
private String processCommand(String command) throws Exception {
// Parse to Array
String[] commandArray = command.split(" ");
// Check if command is valid
switch (commandArray[0]) {
case "ping":
return "pong";
case "echo":
return commandArray[1];
default:
throw new InvalidCommandException();
}
}
// Exceptions
private static class InvalidCommandException extends Exception {
public InvalidCommandException() {
super("Invalid Command");
}
}
}