Repository navigation
Expand file tree
/
Copy pathJShellState.java
More file actions
84 lines (67 loc) · 2.05 KB
/
Copy pathJShellState.java
File metadata and controls
84 lines (67 loc) · 2.05 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
package driver;
import file_system.Directory;
import file_system.VirtualFileSystem;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Stack;
/**
* This class holds all the states of the Shell Program
*/
public class JShellState implements IShellState, Serializable {
private final VirtualFileSystem fs;
private Directory currentDir;
private boolean running;
private final Stack<Directory> directoryStack;
private final List<String> commandsHistory;
private final List<String> correctCommandsHistory;
/**
* Constructs an object that holds JShell's important states including
* the root directory, current directory, directory stack and a boolean that
* indicates JShell is running
*/
public JShellState() {
this.running = true;
this.fs = VirtualFileSystem.createFileSystemInstance();
this.currentDir = fs.getRoot();
this.commandsHistory = new ArrayList<>();
this.correctCommandsHistory = new ArrayList<>();
this.directoryStack = new Stack<>();
}
public boolean isRunning() {
return running;
}
public void stopRunning() {
running = false;
}
public VirtualFileSystem getFileSystem() {
return fs;
}
public Directory getRootDir() {
return fs.getRoot();
}
public Directory getCurrentDir() {
return currentDir;
}
public void setCurrentDir(Directory newCurrentDir) {
currentDir = newCurrentDir;
}
public void addHistory(String inputLine) {
commandsHistory.add(inputLine);
}
public void removeHistory(int index) {
commandsHistory.remove(index);
}
public List<String> getHistory() {
return commandsHistory;
}
public void addCorrectHistory(String inputLine) {
correctCommandsHistory.add(inputLine);
}
public List<String> getCorrectHistory() {
return correctCommandsHistory;
}
public Stack<Directory> getDirectoryStack(){
return directoryStack;
}
}