forked from JavaOPs/basejava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayStorage.java
More file actions
63 lines (55 loc) · 1.36 KB
/
ArrayStorage.java
File metadata and controls
63 lines (55 loc) · 1.36 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
import java.util.Arrays;
/**
* Array based storage for Resumes
*/
public class ArrayStorage {
Resume[] storage = new Resume[10000];
private int size = 0;
void clear() {
for (int i = 0; i < size; i++) {
storage[i] = null;
}
size--;
}
void save(Resume r) {
if (r == null) throw new
IllegalArgumentException("resume is null");
size++;
storage[0] = r;
storage[size] = r;
}
String get(String uuid) {
for (int i = 0; i < size; i++) {
if (storage[i].uuid.equals(uuid)) {
return storage[i].toString();
}
}
return null;
}
void delete(String uuid) {
for (int i = 0; i < size; i++) {
if (storage[i].uuid.equals(uuid)) {
storage[i] = storage[size - 1];
storage[size - 1] = storage[size - 2];
size--;
}
}
}
/**
* @return array, contains only Resumes in storage (without null)
*/
Resume[] getAll() {
Resume[] resumes = new Resume[size];
for (int i = 0; i < size; i++) {
resumes[i] = storage[i];
}
return resumes;
}
int size() {
return size;
}
@Override
public String toString() {
return Arrays.toString(storage);
}
}