-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainArray.java
More file actions
83 lines (78 loc) · 2.86 KB
/
MainArray.java
File metadata and controls
83 lines (78 loc) · 2.86 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
package ru.javaops.webapp;
import ru.javaops.webapp.model.Resume;
import ru.javaops.webapp.storage.SortedArrayStorage;
import ru.javaops.webapp.storage.Storage;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.List;
/**
* Interactive test for ru.javaops.webapp.storage.ArrayStorage implementation
* (just run, no need to understand)
*/
public class MainArray {
// private final static Storage ARRAY_STORAGE = new ArrayStorage();
private final static Storage ARRAY_STORAGE = new SortedArrayStorage();
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
Resume r;
while (true) {
System.out.print("Введите одну из команд - (list | save fullName | delete uuid | get uuid | update uuid fullName | clear | exit): ");
String[] params = reader.readLine().trim().toLowerCase().split(" ");
if (params.length < 1 || params.length > 3) {
System.out.println("Неверная команда.");
continue;
}
String param = null;
if (params.length > 1) {
param = params[1].intern();
}
switch (params[0]) {
case "list":
printAll();
break;
case "size":
System.out.println(ARRAY_STORAGE.size());
break;
case "save":
r = new Resume(param);
ARRAY_STORAGE.save(r);
printAll();
break;
case "update":
r = new Resume(param, params[2]);
ARRAY_STORAGE.update(r);
printAll();
break;
case "delete":
ARRAY_STORAGE.delete(param);
printAll();
break;
case "get":
System.out.println(ARRAY_STORAGE.get(param));
break;
case "clear":
ARRAY_STORAGE.clear();
printAll();
break;
case "exit":
return;
default:
System.out.println("Неверная команда.");
break;
}
}
}
static void printAll() {
List<Resume> all = ARRAY_STORAGE.getAllSorted();
System.out.println("----------------------------");
if (all.size() == 0) {
System.out.println("Empty");
} else {
for (Resume r : all) {
System.out.println(r);
}
}
System.out.println("----------------------------");
}
}