Repository navigation
Expand file tree
/
Copy pathArrayStorage.java
More file actions
126 lines (83 loc) · 2.7 KB
/
Copy pathArrayStorage.java
File metadata and controls
126 lines (83 loc) · 2.7 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
import java.util.Arrays;
/**
* Array based storage for Resumes
*/
public class ArrayStorage {
private int size = 0;
private Resume[] storage = new Resume[10000];
void clear() {
Arrays.fill(storage, null);
size = 0;
}
void save(Resume r) {
// checking if after adding a new element we will not out of array capacity && checking if the value of r object isn't null
if(size+1 != storage.length && r != null){ // checking if after adding a new element we will not out of array capacity
int i = -1;
//checking if we have in our storage Resume with the uuid as received for saving object if we have such iterating i instance
for(int j = 0; j < size; j++){
if(storage[j].uuid.equals(r.uuid)){
i++;
}
}
if(i < 0){
storage[size] = r;
size++;
}
else {
System.out.println("Resume with uuid " + r.uuid +" is already presented in the base");
}
}
else {
System.out.println("Resume can't be added as storage is crowded or you passed null Resume");
}
}
Resume get(String uuid) {
//Moving through array in order to find Resume object with requested value
Resume resume = null;
for (int i = 0; i < size; i++) {
if (uuid.equals(storage[i].uuid)) {
resume = storage[i];
}
}
if(resume == null){
System.out.println("Resume isn't exist");
}
return resume;
}
void delete(String uuid) {
boolean isDeleted = false;
//Moving through array in order to find Resume object with requested uuid value
for (int i = 0; i < size; i++) {
if (storage[i].uuid.equals(uuid)) {
storage[i] = storage[size-1];
isDeleted = true;
storage[size-1] = null;
size--;
}
}
if(!isDeleted){
System.out.println("Requested resume wasn't found");
}
}
/**
* @return array, contains only Resumes in storage (without null)
*/
Resume[] getAll() {
return Arrays.copyOfRange(storage, 0, size);
}
int size() {
return size;
}
private void update (Resume resume){
boolean isFound = false;
for (int i = 0; i < size; i++) {
if (storage[i].uuid.equals(resume.uuid)) {
storage[i] = resume;
isFound = true;
}
}
if(!isFound){
System.out.println("Such resume wasn't found");
}
}
}