-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCommand.java
90 lines (81 loc) · 2.27 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/**
* This class is part of the "Prison Break" application.
*
* This class holds information about a command that was issued by the user.
* A command currently consists of three strings: a command word, a second
* word and a third word
*
* 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 command word is <null>.
*
* If the command had only one word, then the second word is <null>.
*
* @author Michael Kölling, David J. Barnes and Michael Seiranian
* @version 2016.02.29
*/
public class Command
{
private String commandWord;
private String secondWord;
private String thirdWord;
/**
* Create a command object. First and second word must be supplied, but
* either one (or both) can be null.
* @param firstWord The first word of the command. Null if the command
* was not recognised.
* @param secondWord The second word of the command.
*/
public Command(String firstWord, String secondWord, String thirdWord)
{
commandWord = firstWord;
this.secondWord = secondWord;
this.thirdWord = thirdWord;
}
/**
* Return the command word (the first word) of this command. If the
* command was not understood, the result is null.
* @return The command word.
*/
public String getCommandWord()
{
return commandWord;
}
/**
* @return The second word of this command. Returns null if there was no
* second word.
*/
public String getSecondWord()
{
return secondWord;
}
/**
* @return the third word of the command. Returns null if there was no
* third word.
*/
public String getThirdWord()
{
return thirdWord;
}
/**
* @return true if this command was not understood.
*/
public boolean isUnknown()
{
return (commandWord == null);
}
/**
* @return true if the command has a second word.
*/
public boolean hasSecondWord()
{
return (secondWord != null);
}
/**
* @return true if the command has a third word.
*/
public boolean hasThirdWord()
{
return (thirdWord != null);
}
}