]> Git Server - utils.git/commitdiff
test
authorRobin Cheney <cheneyr@eternal.ddnss.de>
Tue, 25 Nov 2025 08:34:52 +0000 (09:34 +0100)
committerRobin Cheney <cheneyr@eternal.ddnss.de>
Tue, 25 Nov 2025 08:34:52 +0000 (09:34 +0100)
src/main/java/de/ddnss/eternal/utils/io/error/InvalidArgumentsError.java
src/main/java/de/ddnss/eternal/utils/io/input/AvailableCommands.java
src/main/java/de/ddnss/eternal/utils/io/input/Command.java
src/main/java/de/ddnss/eternal/utils/io/input/CommandOption.java
src/main/java/de/ddnss/eternal/utils/io/input/GenericCommand.java [new file with mode: 0644]
src/main/java/de/ddnss/eternal/utils/io/input/GenericCommandOption.java [new file with mode: 0644]
src/main/java/de/ddnss/eternal/utils/io/input/user/CMDCommands.java

index cb200c01994be866dfa0899050553652b67ce186..0eb07bb1488aff4c34290d3f6b8bf637bab02c85 100644 (file)
@@ -1,9 +1,10 @@
 package de.ddnss.eternal.utils.io.error;
 
-import de.ddnss.eternal.utils.io.input.CommandOption;
+import de.ddnss.eternal.utils.io.input.GenericCommandOption;
 
 /**
- * Thrown when an {@link CommandOption} object does not fit the requirements of
+ * Thrown when an {@link GenericCommandOption} object does not fit the
+ * requirements of
  * the function it was passed to
  * 
  * @author Robin Cheney
index 6dbf500d73fe27b5f73c4062c14e4ea520fb57fa..4da656e3a39b80df8e19ef4d4ddc642959a19fb9 100644 (file)
@@ -14,7 +14,7 @@ public enum AvailableCommands implements CommandEnumInterface {
         System.exit(0);
     }),
 
-    SAY((CommandOption<String> args) -> {
+    SAY((CommandOption args) -> {
         System.out.println("HI");
         System.out.println(args.get("SAY"));
         return null;
@@ -35,7 +35,8 @@ public enum AvailableCommands implements CommandEnumInterface {
      * @param command   A {@link Function} that returns null
      * @param arguments A {@link CommandOption} object
      */
-    private AvailableCommands(Function<CommandOption<String>, Void> command, CommandOption<String> arguments) {
+    private AvailableCommands(Function<CommandOption, Void> command,
+            CommandOption arguments) {
         this.command = new Command(command, arguments);
     }
 
@@ -44,7 +45,7 @@ public enum AvailableCommands implements CommandEnumInterface {
      * 
      * @param command A {@link Function} that returns null
      */
-    private AvailableCommands(Function<CommandOption<String>, Void> command) {
+    private AvailableCommands(Function<CommandOption, Void> command) {
         this.command = new Command(command);
     }
 
index fe834748424c8b9991e210c8ec9d22a2418b3995..7eef2c5ae07c93f25a6d85f9ddb0cc3c93af9f9f 100644 (file)
@@ -15,26 +15,26 @@ public class Command {
     /**
      * The command to be executed. Must be passed as a runnable to the constructor
      * or if parameters are necessary, it must be a {@link Function} that takes a
-     * {@link CommandOption} as the single parameter and always returns null
+     * {@link GenericCommandOption} as the single parameter and always returns null
      */
-    final Function<CommandOption<String>, Void> command;
-    CommandOption<String> arguments;
+    final Function<CommandOption, Void> command;
+    CommandOption arguments;
 
     /**
      * 
      * @param command
      * @param arguments
      */
-    public Command(Function<CommandOption<String>, Void> command, CommandOption<String> arguments) {
+    public Command(Function<CommandOption, Void> command, CommandOption arguments) {
         this.command = command;
         this.arguments = arguments;
     }
 
     /**
      * 
-     * @param command A {@link Function} that takes a {@link CommandOption}
+     * @param command A {@link Function} that takes a {@link GenericCommandOption}
      */
-    public Command(Function<CommandOption<String>, Void> command) {
+    public Command(Function<CommandOption, Void> command) {
         this.command = command;
     }
 
@@ -44,7 +44,7 @@ public class Command {
      * @param command A {@link Runnable} to execute
      */
     public Command(Runnable command) {
-        this.command = (CommandOption<String> undefined) -> {
+        this.command = (CommandOption undefined) -> {
             command.run();
             return null;
         };
@@ -54,9 +54,9 @@ public class Command {
      * Execute the command with the previously provided arguments
      * 
      * @apiNote This method has a shorthand property where you can provide
-     *          {@link CommandOption command options}
-     * @see #exec(CommandOption)
-     * @see #bindArguments(CommandOption)
+     *          {@link GenericCommandOption command options}
+     * @see #exec(GenericCommandOption)
+     * @see #bindArguments(GenericCommandOption)
      */
     public void exec() {
         this.command.apply(arguments);
@@ -65,22 +65,24 @@ public class Command {
     /**
      * Binds arguments to the command
      * 
-     * @param args A {@link CommandOption} object holding the command arguments and
+     * @param args A {@link GenericCommandOption} object holding the command
+     *             arguments and
      *             their values
      * @return the {@link Command} object itself
      */
-    public Command bindArguments(CommandOption<String> args) {
+    public Command bindArguments(CommandOption args) {
         this.arguments = args;
         return this;
     };
 
     /**
-     * Executes a command with a {@link CommandOption}
+     * Executes a command with a {@link GenericCommandOption}
      * 
-     * @param arguments A {@link CommandOption} object holding necessary parameters
+     * @param arguments A {@link GenericCommandOption} object holding necessary
+     *                  parameters
      * @throws InvalidArgumentsError
      */
-    public void exec(CommandOption<String> arguments) throws InvalidArgumentsError {
+    public void exec(CommandOption arguments) throws InvalidArgumentsError {
         try {
             this.command.apply(arguments);
         } catch (NullPointerException String) {
index ac55e28e9ecee5e472743862fda2191412eee746..81552642364ac71068b79fe00fc819d2610a987d 100644 (file)
@@ -11,8 +11,8 @@ import java.util.HashMap;
  * 
  * @since 1.1
  */
-public class CommandOption<E> extends HashMap<String, E> {
-    public CommandOption(String string, E e) {
+public class CommandOption extends GenericCommandOption<String> {
+    public CommandOption(String string, String e) {
         super();
         this.put(string, e);
     }
diff --git a/src/main/java/de/ddnss/eternal/utils/io/input/GenericCommand.java b/src/main/java/de/ddnss/eternal/utils/io/input/GenericCommand.java
new file mode 100644 (file)
index 0000000..f59477b
--- /dev/null
@@ -0,0 +1,92 @@
+package de.ddnss.eternal.utils.io.input;
+
+import java.util.function.Function;
+
+import de.ddnss.eternal.utils.io.error.InvalidArgumentsError;
+
+/**
+ * Class for instantiating commands with parameter type {@code String}
+ * 
+ * @author Robin Cheney
+ * 
+ * @since 1.2
+ */
+public class GenericCommand<E> {
+    /**
+     * The command to be executed. Must be passed as a runnable to the constructor
+     * or if parameters are necessary, it must be a {@link Function} that takes a
+     * {@link GenericCommandOption} as the single parameter and always returns null
+     */
+    final Function<GenericCommandOption<E>, Void> command;
+    GenericCommandOption<E> arguments;
+
+    /**
+     * 
+     * @param command
+     * @param arguments
+     */
+    public GenericCommand(Function<GenericCommandOption<E>, Void> command, GenericCommandOption<E> arguments) {
+        this.command = command;
+        this.arguments = arguments;
+    }
+
+    /**
+     * 
+     * @param command A {@link Function} that takes a {@link GenericCommandOption}
+     */
+    public GenericCommand(Function<GenericCommandOption<E>, Void> command) {
+        this.command = command;
+    }
+
+    /**
+     * Constructs a {@link GenericCommand} without any parameters
+     * 
+     * @param command A {@link Runnable} to execute
+     */
+    public GenericCommand(Runnable command) {
+        this.command = (GenericCommandOption<E> undefined) -> {
+            command.run();
+            return null;
+        };
+    }
+
+    /**
+     * Execute the command with the previously provided arguments
+     * 
+     * @apiNote This method has a shorthand property where you can provide
+     *          {@link GenericCommandOption command options}
+     * @see #exec(GenericCommandOption)
+     * @see #bindArguments(GenericCommandOption)
+     */
+    public void exec() {
+        this.command.apply(arguments);
+    };
+
+    /**
+     * Binds arguments to the command
+     * 
+     * @param args A {@link GenericCommandOption} object holding the command
+     *             arguments and
+     *             their values
+     * @return the {@link GenericCommand} object itself
+     */
+    public GenericCommand<E> bindArguments(GenericCommandOption<E> args) {
+        this.arguments = args;
+        return this;
+    };
+
+    /**
+     * Executes a command with a {@link GenericCommandOption}
+     * 
+     * @param arguments A {@link GenericCommandOption} object holding necessary
+     *                  parameters
+     * @throws InvalidArgumentsError
+     */
+    public void exec(GenericCommandOption<E> arguments) throws InvalidArgumentsError {
+        try {
+            this.command.apply(arguments);
+        } catch (NullPointerException String) {
+            throw new InvalidArgumentsError(String);
+        }
+    };
+}
\ No newline at end of file
diff --git a/src/main/java/de/ddnss/eternal/utils/io/input/GenericCommandOption.java b/src/main/java/de/ddnss/eternal/utils/io/input/GenericCommandOption.java
new file mode 100644 (file)
index 0000000..f31ca58
--- /dev/null
@@ -0,0 +1,23 @@
+package de.ddnss.eternal.utils.io.input;
+
+import java.util.HashMap;
+
+/**
+ * Command options container
+ * 
+ * @apiNote extends {@link HashMap} whose functions you can use
+ * 
+ * @author Robin Cheney
+ * 
+ * @since 1.2
+ */
+public class GenericCommandOption<E> extends HashMap<String, E> {
+    public GenericCommandOption(String string, E e) {
+        super();
+        this.put(string, e);
+    }
+
+    public GenericCommandOption() {
+        super();
+    }
+}
\ No newline at end of file
index 567c0e55fccf948dea1b5c65c67d9657b4c2513a..eda694e475fd3b5e39de59c32a9f142cca7246e4 100644 (file)
@@ -3,9 +3,9 @@ package de.ddnss.eternal.utils.io.input.user;
 import java.util.Scanner;
 
 import de.ddnss.eternal.utils.io.input.AvailableCommands;
-import de.ddnss.eternal.utils.io.input.CommandOption;
 import de.ddnss.eternal.utils.io.input.Command;
 import de.ddnss.eternal.utils.io.input.CommandEnumInterface;
+import de.ddnss.eternal.utils.io.input.CommandOption;
 
 /**
  * Should be useful for capturing console command
@@ -45,7 +45,7 @@ public class CMDCommands {
                 break;
             }
 
-            command.getCommand().bindArguments(new CommandOption<String>("SAY", parts[0])).exec();
+            command.getCommand().bindArguments(new CommandOption("SAY", parts[0])).exec();
         }
     }
 }