-
Notifications
You must be signed in to change notification settings - Fork 0
/
Command.java
70 lines (63 loc) · 1.78 KB
/
Command.java
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/**
*
* This class holds information about a command that was issued by the user.
* A command currently consists of two parts: a CommandWord and a string
* (for example, if the command was "take map", then the two parts
* are TAKE and "map").
*
* The way this is used is: Commands are already checked for being valid
* command words. If the user entered an invalid command (a word that is not
* known) then the CommandWord is UNKNOWN.
*
* If the command had only one word, then the second word is <null>.
*
* @author 162224
* @version 15/11
*/
public class Command
{
private CommandWord commandWord;
private String secondWord;
/**
* Create a command object. First and second words must be supplied, but
* the second may be null.
* @param commandWord The CommandWord. UNKNOWN if the command word
* was not recognised.
* @param secondWord The second word of the command. May be null.
*/
public Command(CommandWord commandWord, String secondWord)
{
this.commandWord = commandWord;
this.secondWord = secondWord;
}
/**
* Return the command word (the first word) of this command.
* @return The command word.
*/
public CommandWord getCommandWord()
{
return commandWord;
}
/**
* @return The second word of this command. Returns null if there was no
* second word.
*/
public String getSecondWord()
{
return secondWord;
}
/**
* @return true if this command was not understood.
*/
public boolean isUnknown()
{
return (commandWord == CommandWord.UNKNOWN);
}
/**
* @return true if the command has a second word.
*/
public boolean hasSecondWord()
{
return (secondWord != null);
}
}