aboutsummaryrefslogtreecommitdiff
path: root/src/esieequest/controller/Input.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/esieequest/controller/Input.java')
-rw-r--r--src/esieequest/controller/Input.java59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/esieequest/controller/Input.java b/src/esieequest/controller/Input.java
new file mode 100644
index 0000000..4b4ada5
--- /dev/null
+++ b/src/esieequest/controller/Input.java
@@ -0,0 +1,59 @@
1package esieequest.controller;
2
3import esieequest.controller.commands.Command;
4
5/**
6 * An user textual input.
7 *
8 * @author Pacien TRAN-GIRARD
9 */
10public class Input {
11
12 private Command command;
13 private final String argument;
14
15 /**
16 *
17 * @param command
18 * @param argument
19 */
20 public Input(final Command command, final String argument) {
21 this.command = command;
22 this.argument = argument;
23 }
24
25 /**
26 * Builds an Input from a textual input String.
27 *
28 * @param inputString
29 * the textual input String
30 */
31 public Input(final String inputString) {
32 final String[] elements = inputString.split(" ", 2);
33 try {
34 this.command = Command.valueOf(elements[0].toUpperCase());
35 } catch (final Exception exception) {
36 this.command = null;
37 }
38 if (elements.length >= 2) {
39 this.argument = elements[1];
40 } else {
41 this.argument = null;
42 }
43 }
44
45 /**
46 * @return the command
47 */
48 public Command getCommand() {
49 return this.command;
50 }
51
52 /**
53 * @return the argument
54 */
55 public String getArgument() {
56 return this.argument;
57 }
58
59}