forked from JavaOPs/basejava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainArray.java
More file actions
107 lines (102 loc) · 3.89 KB
/
MainArray.java
File metadata and controls
107 lines (102 loc) · 3.89 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
package ru.topjava.webapp;
import ru.topjava.webapp.model.Resume;
import ru.topjava.webapp.storage.ArrayStorage;
import ru.topjava.webapp.storage.SortedArrayStorage;
import ru.topjava.webapp.storage.Storage;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/**
* Interactive test for ArrayStorage implementation
* (just run, no need to understand)
*/
public class MainArray {
private static Storage arrayStorage;
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
Resume resume;
String[] params;
storageChoice:
while (true) {
System.out.print("Выберите тип хранилища - (sort | unsort | exit): ");
params = reader.readLine().trim().toLowerCase().split(" ");
if (params.length < 1 || params.length > 2) {
System.out.println("Неверная команда.");
continue;
}
switch (params[0]) {
case "sort":
System.out.println("Выбранный тип хранилища: отсортированный массив.");
arrayStorage = new SortedArrayStorage();
break storageChoice;
case "unsort":
System.out.println("Выбранный тип хранилища: неотсортированный массив.");
arrayStorage = new ArrayStorage();
break storageChoice;
case "exit":
return;
default:
System.out.println("Неверная команда.");
break;
}
}
while (true) {
System.out.print("Введите одну из команд - (list | save uuid | update uuid | delete uuid | get uuid | clear | exit): ");
params = reader.readLine().trim().toLowerCase().split(" ");
if (params.length < 1 || params.length > 2) {
System.out.println("Неверная команда.");
continue;
}
String uuid = null;
if (params.length == 2) {
uuid = params[1].intern();
}
switch (params[0]) {
case "list":
printAll();
break;
case "size":
System.out.println(arrayStorage.size());
break;
case "save":
resume = new Resume(uuid);
arrayStorage.save(resume);
printAll();
break;
case "update":
resume = new Resume(uuid);
arrayStorage.update(resume);
printAll();
break;
case "delete":
arrayStorage.delete(uuid);
printAll();
break;
case "get":
System.out.println(arrayStorage.get(uuid));
break;
case "clear":
arrayStorage.clear();
printAll();
break;
case "exit":
return;
default:
System.out.println("Неверная команда.");
break;
}
}
}
static void printAll() {
Resume[] all = arrayStorage.getAll();
System.out.println("----------------------------");
if (all.length == 0) {
System.out.println("Empty");
} else {
for (Resume resume : all) {
System.out.println(resume);
}
}
System.out.println("----------------------------");
}
}