Repository navigation
Expand file tree
/
Copy pathSortedArrayStorage.java
More file actions
53 lines (42 loc) · 1.69 KB
/
Copy pathSortedArrayStorage.java
File metadata and controls
53 lines (42 loc) · 1.69 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
package com.javaops.storage;
import com.javaops.model.Resume;
import java.util.Arrays;
import java.util.Comparator;
/**
* @author Vasichkin Pavel
* Array sorted storage for Resumes
*/
public class SortedArrayStorage extends AbstractArrayStorage {
// private static class ResumeComparator implements Comparator<Resume> {
// @Override
// public int compare(Resume o1, Resume o2) {
// int cmp = o1.getFullName().compareTo(o2.getFullName());
// return cmp != 0 ? cmp : o1.getUuid().compareTo(o2.getUuid());
// }
// }
// private static final Comparator<Resume> RESUME_COMPARATOR = new Comparator<Resume>() {
// @Override
// public int compare(Resume o1, Resume o2) {
// return o1.getUuid().compareTo(o2.getUuid());
// }
// };
// private static final Comparator<Resume> RESUME_COMPARATOR = Comparator.comparing(Resume::getFullName).thenComparing(Resume::getUuid);
// private static final Comparator<Resume> RESUME_COMPARATORR = (o1, o2) -> o1.getUuid().compareTo(o2.getUuid());
@Override
protected void insertElement(Resume resume, int index) {
System.arraycopy(storage, index, storage, index + 1, size - index);
storage[index] = resume;
}
@Override
protected void removeElement(int index) {
int numberMove = size - index - 1;
if (numberMove > 0) {
System.arraycopy(storage, index + 1, storage, index, numberMove);
}
}
@Override
protected Integer getSearchKey(String uuid) {
Resume searchKey = new Resume(uuid, "FullName");
return Arrays.binarySearch(storage, 0, size, searchKey, Comparator.comparing(Resume::getUuid));
}
}