-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAbstractArrayStorage.java
More file actions
68 lines (54 loc) · 1.54 KB
/
AbstractArrayStorage.java
File metadata and controls
68 lines (54 loc) · 1.54 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
package ru.javaops.webapp.storage;
import ru.javaops.webapp.exception.StorageException;
import ru.javaops.webapp.model.Resume;
import java.util.Arrays;
import java.util.List;
/**
* Array based storage for Resumes
*/
public abstract class AbstractArrayStorage extends AbstractStorage<Integer> {
protected static final int STORAGE_LIMIT = 10000;
protected Resume[] storage = new Resume[STORAGE_LIMIT];
protected int size = 0;
@Override
public void clear() {
Arrays.fill(storage, 0, size, null);
size = 0;
}
@Override
public int size() {
return size;
}
@Override
protected void doSave(Integer searchKey, Resume r) {
if (size >= STORAGE_LIMIT) {
throw new StorageException("Storage overflow", r.getUuid());
}
storage[insertResume(searchKey)] = r;
size++;
}
@Override
protected void doDelete(Integer searchKey) {
size--;
deleteResume(searchKey);
storage[size] = null;
}
@Override
protected void doUpdate(Integer searchKey, Resume r) {
storage[searchKey] = r;
}
@Override
protected Resume doGet(Integer searchKey) {
return storage[searchKey];
}
@Override
protected List<Resume> doCopyAll() {
return Arrays.asList(Arrays.copyOf(storage, size));
}
protected abstract int insertResume(int index);
protected abstract void deleteResume(int index);
@Override
protected boolean isExist(Integer searchKey) {
return searchKey >= 0;
}
}