-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainArray.java
More file actions
115 lines (109 loc) · 4.59 KB
/
MainArray.java
File metadata and controls
115 lines (109 loc) · 4.59 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
package com.urise.webapp;
import com.urise.webapp.model.Resume;
import com.urise.webapp.storage.*;
import java.io.BufferedReader;
import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.List;
import java.util.Random;
import java.util.Scanner;
/**
* Interactive test for com.urise.webapp.storage.ArrayStorage implementation
* (just run, no need to understand)
*/
public class MainArray {
private static final Storage ARRAY_STORAGE;
static {
System.out.println("Type 1 - ArrayStorage" + "\n" +
"2 - SortedArrayStorage" + "\n" +
"3 - ListStorage" + "\n" +
"4 - MapStorage" + "\n" +
"5 - MapStorageResume" + "\n");
// String accessType = new Scanner(new BufferedInputStream(System.in){public void close(){}}).nextLine();
int accessType = new Scanner(new FilterInputStream(System.in){public void close(){}}).nextInt();
if (accessType == 1) {
ARRAY_STORAGE = new ArrayStorage();
System.out.println("accessType = " + accessType + " - " + ARRAY_STORAGE.getClass().getName());
} else if (accessType == 2) {
ARRAY_STORAGE = new SortedArrayStorage();
System.out.println("accessType = " + accessType + " - " + ARRAY_STORAGE.getClass().getName());
} else if (accessType == 3) {
ARRAY_STORAGE = new ListStorage();
System.out.println("accessType = " + accessType + " - " + ARRAY_STORAGE.getClass().getName());
} else if (accessType == 4) {
ARRAY_STORAGE = new MapUuidStorage();
System.out.println("accessType = " + accessType + " - " + ARRAY_STORAGE.getClass().getName());
} else if (accessType == 5) {
ARRAY_STORAGE = new MapResumeStorage();
System.out.println("accessType = " + accessType + " - " + ARRAY_STORAGE.getClass().getName());
} else {
ARRAY_STORAGE = new ArrayStorage();
System.out.println("Default accessType = " + ARRAY_STORAGE.getClass().getName());
}
}
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
Resume resume;
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":
Random random = new Random();
// ARRAY_STORAGE.save(new Resume(param, "FullName" + random.nextInt(100)));
ARRAY_STORAGE.save(new Resume(param));
printAll();
break;
case "update":
// resume = new Resume(param, "FullName" + new Random().nextInt(1000));
resume = new Resume(param, params[2]);
ARRAY_STORAGE.update(resume);
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 resume : all) {
System.out.println(resume);
}
}
System.out.println("----------------------------");
}
}