-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInterface.java
More file actions
129 lines (129 loc) · 4.7 KB
/
Copy pathInterface.java
File metadata and controls
129 lines (129 loc) · 4.7 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
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package tracker;
import java.util.*;
public class Interface {
static Command.RESERVED activeCommand = null; //Last entered console command
static int commandLevel = 0;
private final Scanner scanner = new Scanner(System.in);
List<String> rawInput;
Queue<String> rawQueue = new LinkedList<>();
List<String> normalized = new ArrayList<>();
List<String> reserved = new ArrayList<>();
Interface() {}
void setUp() {
//Create list reserved from RESERVED
for (Command.RESERVED c : Command.RESERVED.values()) {
reserved.add(String.valueOf(c));
}
}
boolean isInput() {
normalized.clear();
rawInput = Arrays.asList(scanner.nextLine().split("\\s+"));
for(String in : rawInput) {
if (!in.isBlank()) rawQueue.offer(in);
}
for(int i = 0; i < rawInput.size(); i++ ) {
if (rawQueue.peek() != null) normalized.add(rawQueue.poll().toLowerCase());
}
if( normalized.size() == 0) {
Message.noInput_M();
return false;
}
return true;
}
void checkInput() {
boolean isCommand = new HashSet<>(reserved).containsAll(normalized);
if (isCommand) {
String command0 = normalized.get(0).toLowerCase();
String command1 = null;
if(normalized.size() == 2) command1 = normalized.get(1).toLowerCase();
switch (command0) {
case "students" :
case "points" :
Message.unknownCommand_M();
break;
case "list" :
if(normalized.size() > 1) {
Message.unknownCommand_M();
break;
}
commandLevel = 0;
activeCommand = Command.RESERVED.list;
new Tlist().execute();
break;
case "find" :
if(normalized.size() > 1) {
Message.unknownCommand_M();
break;
}
commandLevel = 0;
activeCommand = Command.RESERVED.find;
new Find().execute();
break;
case "statistics" :
if(normalized.size() > 1) {
Message.unknownCommand_M();
break;
}
commandLevel = 0;
activeCommand = Command.RESERVED.statistics;
new Statistics().execute();
break;
case "notify" :
if(normalized.size() > 1) {
Message.unknownCommand_M();
break;
}
commandLevel = 0;
activeCommand = Command.RESERVED.notify;
new Notify().execute();
break;
case "exit" :
if(normalized.size() > 1) {
Message.unknownCommand_M();
break;
}
commandLevel = 0;
activeCommand = Command.RESERVED.exit;
new Exit().execute();
break;
case "back" :
if(normalized.size() > 1) {
Message.unknownCommand_M();
break;
}
Interface.commandLevel = 0;
Interface.activeCommand = Command.RESERVED.back;
new Back().execute();
break;
case "add" :
if(command1 == null) {
Message.unknownCommand_M();
break;
}
switch(command1) {
case "students":
Interface.commandLevel = 1;
Interface.activeCommand = Command.RESERVED.students;
new Add().control(command1);
break;
case "points" :
Interface.commandLevel = 1;
Interface.activeCommand = Command.RESERVED.points;
new Add().control(command1);
break;
}
}
}
else Message.unknownCommand_M();
}
void verifyConsoleInput() {
if(isInput()) checkInput();
}
void Console() {
setUp();
Message.printTitle_M();
while (Main.trackerON) {
verifyConsoleInput();
}
}
}