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