-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSortedArrayStorage.java
More file actions
43 lines (30 loc) · 1.1 KB
/
Copy pathSortedArrayStorage.java
File metadata and controls
43 lines (30 loc) · 1.1 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
package storage;
import exception.StorageException;
import model.Resume;
import java.util.Arrays;
import java.util.Comparator;
public class SortedArrayStorage extends AbstractArrayStorage {
private static final Comparator<Resume> RESUME_COMPARATOR
= Comparator.comparing(Resume::getUuid);
@Override
protected void deleteAndReplace(Object searchKey) {
System.arraycopy(storage, (Integer) searchKey +1,
storage, (Integer) searchKey, size - ((Integer) searchKey + 1));
}
@Override
protected void insertResume(Resume r, Object searchKey) {
if(size() == MAX_CAPACITY) {
throw new StorageException(r.getUuid(), "Storage is overflow");
}
Integer key = (Integer) searchKey;
key = (key * -1) -1;
System.arraycopy(storage, key, storage, key +1, size - key);
storage[key] = r;
size++;
}
@Override
protected Object getSearchKey(String uuid) {
Resume searchKey = new Resume(uuid, "dummy");
return Arrays.binarySearch(storage, 0, size, searchKey, RESUME_COMPARATOR);
}
}