-
Notifications
You must be signed in to change notification settings - Fork 1
/
CmmdEnvironment.java
78 lines (66 loc) · 1.99 KB
/
CmmdEnvironment.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
package ccg.cmmdLine;
import java.util.ArrayList;
import java.util.List;
import ccg.cmmdLine.Cmmd;
import ccg.cmmdLine.Flag;
public final class CmmdEnvironment
{
private final List<Cmmd> cmds;
public static final int MAX_CMMDS = 12;
private boolean echoState;
private boolean confirmState;
/**
* default constructor important for initializing echo and confirm statements
* */
public CmmdEnvironment()
{
cmds = new ArrayList<>();
echoState = false;
confirmState = false;
createCmmds();
}
/**worker methods*/
private void createCmmds()
{
/*overlapping flags*/
Flag clss = new Flag("cl", "various manipulations can be performed for any generic class");
/*build the 'add' cmmd*/
Cmmd addCmd = new Cmmd("add");
addCmd.addFlag(clss);
this.cmds.add(addCmd);
Cmmd remvCmd = new Cmmd("remv");
Cmmd modfCmd = new Cmmd("modf");
Cmmd useCmd = new Cmmd("use");
Cmmd buildCmd = new Cmmd("build");
}
/**
* Using the confirm feature of the env., the user can find out every time
* post-execution if their input was valid and successfully executed or not
* */
public boolean confirm()
{
/*alternate the confirm state depending on current state*/
if(this.confirmState){this.confirmState = false;return true;}
else if(this.confirmState == false){this.confirmState = true;return true;}
else{return false;}
}
/**
* The echo feature of the env. enables the user to see exactly
* what they input "to the T".
* <p>
* Combined with the confirmation feature, these two features of the
* command line environment will inform the user each time for statement evaluation.
* */
public boolean echo()
{
/*alternate the echo state depending on current state*/
if(this.echoState){this.echoState = false;return true;}
else if(this.echoState == false){this.echoState = true;return true;}
else{return false;}
}
public String help()
{
String output = " Valid Commands\t\tDescription\n---------------------------------------------";
return output;
}
}