-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommandWord.java
More file actions
45 lines (40 loc) · 1 KB
/
CommandWord.java
File metadata and controls
45 lines (40 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import java.util.HashMap;
/**
* Write a description of class CommandWord here.
*
* @author David Panagiotopulos and Luis Hankel
* @version 2018.01.15
*/
public enum CommandWord
{
GO("go"),
HELP("help"),
QUIT("quit"),
LOOK("look"),
OPEN("open"),
SLEEP("sleep"),
UNKNOWN(null);
private final String command;
CommandWord(String command) {
this.command = command;
}
private String getCommand() {
return this.command;
}
public String getCommands(){
String cmd = "";
for(CommandWord command : CommandWord.values()){
cmd += command.getCommand() + ", ";
}
cmd = cmd.replaceAll(", $", "");
return cmd;
}
public static CommandWord getEnum(String word) {
for(CommandWord command : CommandWord.values()){
if (command.getCommand().equals(word)) {
return command;
}
}
return CommandWord.UNKNOWN;
}
}