-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
135 lines (126 loc) · 5.11 KB
/
Main.java
File metadata and controls
135 lines (126 loc) · 5.11 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
130
131
132
133
134
135
import java.io.IOException;
import java.util.ArrayDeque;
import java.util.LinkedHashMap;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws IOException {
LinkedHashMap<String, LabWork> collection = new LinkedHashMap<>();
Scanner in = new Scanner(System.in);
Menu menu = new Menu();
String nameOfSaveFile = "";
ArrayDeque<String> history = new ArrayDeque<>();
if (args.length == 0) {
do {
System.out.print("Введите путь к файлу для загрузки и сохранения: ");
if (in.hasNextLine())
nameOfSaveFile = in.nextLine();
else {
System.out.println("Плохой символ");
System.exit(0);
}
} while(!nameOfSaveFile.isEmpty());
} else {
nameOfSaveFile = args[0];
}
collection = IO.Read(nameOfSaveFile, ';');
if (collection == null) {
collection = new LinkedHashMap<>();
}
IO.CheckedWrite(nameOfSaveFile);
collection = Menu.lhmSort(collection);
Menu.help();
while(true) {
System.out.print("Введите команду: ");
String input = "";
if (in.hasNextLine())
input = in.nextLine();
else {
System.out.println("Плохой символ");
System.exit(0);
}
String[] current = input.split(" ");
if (current.length == 0)
current = new String[] {" "};
history.addLast(current[0]);
switch(current[0]) {
case("help"):
Menu.help();
break;
case("exit"):
System.exit(0);
break;
case("show"):
Menu.show(collection);
break;
case("info"):
Menu.info(collection);
break;
case("insert"):
if (current.length < 2)
collection.putAll(menu.insert(""));
else
collection.putAll(menu.insert(current[1]));
collection = Menu.lhmSort(collection);
break;
case("remove_key"):
if (current.length < 2)
collection = menu.removeKey(collection, "");
else
collection = menu.removeKey(collection, current[1]);
break;
case("clear"):
collection.clear();
System.out.println("Коллекция очищена");
break;
case("history"):
Menu.history(history);
break;
case("update"):
if (current.length < 2)
collection = menu.update(collection, "");
else
collection = menu.update(collection, current[1]);
break;
case("sum_of_minimal_point"):
System.out.println(Menu.sumOfMinimalPoint(collection));
break;
case("max_by_name"):
System.out.println(Menu.maxByName(collection));
break;
case("count_by_minimal_point"):
if (current.length < 2)
System.out.println(Menu.countByMinimalPoint(collection, ""));
else
System.out.println(Menu.countByMinimalPoint(collection, current[1]));
break;
case("remove_lower_key"):
if (current.length < 2)
collection = Menu.removeLowerKey(collection, "");
else
collection = Menu.removeLowerKey(collection, current[1]);
break;
case("replace_if_greater"):
if (current.length < 2)
collection = menu.replaceIfGreater(collection, "");
else
collection = menu.replaceIfGreater(collection, current[1]);
break;
case("save"):
Menu.savetoFile(collection, nameOfSaveFile, ';');
break;
case("execute_script"):
if (current.length < 2)
collection = Menu.executeScript(collection, "", nameOfSaveFile);
else
collection = Menu.executeScript(collection, current[1], nameOfSaveFile);
break;
default:
System.out.println("Неправильно введена команда");
history.pollLast();
continue;
}
if (history.size() > 12)
history.poll();
}
}
}