-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
53 lines (40 loc) · 1.76 KB
/
Copy pathMain.java
File metadata and controls
53 lines (40 loc) · 1.76 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
import java.util.Scanner;
import core.FileSystem;
import history.AccessHistory;
public class Main {
public static void main(String[] args) {
FileSystem fileSystem = new FileSystem();
AccessHistory accessHistory = new AccessHistory();
Scanner scanner = new Scanner(System.in);
System.out.println("Smart File Simulator with History Support");
System.out.println("Type 'help' for commands, 'exit' to quit, 'access' to see visited items\n");
while (true) {
System.out.print("$ ");
if (!scanner.hasNextLine()) break;
String input = scanner.nextLine().trim();
if (input.isEmpty()) continue;
if (input.equalsIgnoreCase("exit")) break;
if (input.equalsIgnoreCase("access")) {
accessHistory.printAccessHistory();
continue;
}
if(input.equalsIgnoreCase("clear history") || input.equalsIgnoreCase("clear")) {
accessHistory.clearHistory();
fileSystem.clearCache();
System.out.println("Access history and MRU cache cleared.");
continue;
}
if(input.equalsIgnoreCase("clear history") || input.equalsIgnoreCase("clear")) {
accessHistory.clearHistory();
System.out.println("Access history cleared.");
continue;
}
if (input.startsWith("cd") || input.startsWith("open") || input.startsWith("touch") || input.startsWith("mkdir")) {
accessHistory.visit(input);
}
fileSystem.handleCommand(input);
}
System.out.println("Simulator ended. Goodbye!");
scanner.close();
}
}