lesson 6. Исправление ошибок · AlbertoJava/basejava@8df83af · GitHub
Skip to content

Commit 8df83af

Browse files
committed
lesson 6. Исправление ошибок
Resume - реализуй только эти конструкторы Resume(String fullName) Resume(String uuid, String fullName) - конструкторы записываются в порядке, зависящем от количества аргументов: от меньшего к большему - из AbstractArrayStorage строку protected abstract Integer getSearchKey(String uuid); удали, она же уже у тебя записана в предке - сортировку делай не на уровне классов, а в AbstractStorage list.stream().sorted(RESUME_COMAPATOR).collect(Collectors.toList()); mapStorage.values().stream().sorted(RESUME_COMAPATOR).collect(Collectors.toList()); так не пойдет MapStorage2Version - какое странное название класса. Придумай другое имя - new HashMap(); забыл diamond operator - поиск резюме ты уже делаешь в методе getSearchKey(String uuid). Еще раз в isExist(Object searchKey) делать не нужено. А в методе doGet делаешь это еще раз) - интерфейс к способам сортировки отношение не имеет. Сортируй на уровне AbstractStorage. И реализуй компаратор с помощью методов интерфеса Comparator. Сейчас у тебя реализовано по старинке - классы MainArray и MainTestArrayStorage можешь вообще удалить. У тебя же есть JUnit тесты - по заданию Из-за того, что количество тестовых классов растет, воспользуйтесь аннотациями JUnit, которые помогут упростить их запуск. Форматируйте класс-запуска тестов в соответствии с этой картинкой
1 parent 8291e80 commit 8df83af

16 files changed

Lines changed: 123 additions & 178 deletions

src/com/urise/webapp/MainArray.java

Lines changed: 0 additions & 89 deletions
This file was deleted.
Lines changed: 24 additions & 0 deletions

src/com/urise/webapp/MainTestArrayStorage.java

Lines changed: 0 additions & 43 deletions
This file was deleted.

src/com/urise/webapp/model/Resume.java

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,26 @@
11
package com.urise.webapp.model;
22

3+
import java.util.Comparator;
34
import java.util.UUID;
45

56
/**
67
* Initial resume class
78
*/
8-
public class Resume implements Comparable<Resume> {
9+
public class Resume implements Comparator<Resume>, Comparable<Resume> {
910

1011
// Unique identifier
1112
private final String uuid;
1213
private final String fullName;
1314

15+
public Resume(String fullName) {
16+
this(UUID.randomUUID().toString(), fullName);
17+
}
18+
1419
public Resume(String uuid, String fullName) {
1520
this.uuid = uuid;
1621
this.fullName = fullName;
1722
}
1823

19-
public Resume(String uuid) {
20-
this(uuid, "No name");
21-
}
22-
23-
public Resume() {
24-
this(UUID.randomUUID().toString());
25-
}
26-
2724
public String getUuid() {
2825
return uuid;
2926
}
@@ -38,10 +35,13 @@ public String toString() {
3835
}
3936

4037
@Override
41-
public int compareTo(Resume o) {
42-
return uuid.compareTo(o.uuid);
38+
public int compare(Resume o1, Resume o2) {
39+
return o1.getUuid().equals(o2.getUuid())?
40+
o1.getFullName().compareTo(o2.getFullName()):
41+
o1.getUuid().compareTo(o2.getUuid());
4342
}
4443

44+
4545
@Override
4646
public boolean equals(Object o) {
4747
if (this == o) return true;
@@ -56,4 +56,9 @@ public boolean equals(Object o) {
5656
public int hashCode() {
5757
return uuid.hashCode();
5858
}
59+
60+
@Override
61+
public int compareTo(Resume o) {
62+
return this.getFullName().equals(o.fullName)?this.getUuid().compareTo(o.getUuid()):this.getFullName().compareTo(o.getFullName());
63+
}
5964
}

src/com/urise/webapp/storage/AbstractArrayStorage.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,15 @@
66
import java.util.Arrays;
77
import java.util.List;
88
import java.util.stream.Collectors;
9+
import java.util.stream.Stream;
910

1011
public abstract class AbstractArrayStorage extends AbstractStorage {
1112
protected static final int MAX_SIZE = 10_0000;
13+
14+
public Resume[] getStorage() {
15+
return storage;
16+
}
17+
1218
protected Resume[] storage = new Resume[MAX_SIZE];
1319
protected int resumeCounter = 0;
1420

@@ -47,6 +53,11 @@ protected void doSave(Resume resume, Object index) {
4753
resumeCounter++;
4854
}
4955

56+
@Override
57+
protected Stream<Resume> getStream() {
58+
return Arrays.stream(storage,0,resumeCounter);
59+
}
60+
5061
public int size() {
5162
return resumeCounter;
5263
}
@@ -56,16 +67,6 @@ protected boolean isExist(Object index) {
5667
return (Integer) index >= 0;
5768
}
5869

59-
/*
60-
method returns:
61-
1. Positive Index in mapStorage, including zero, for existing element
62-
2. Negative index for absent element. Result equals |index| of element, wich is next to absent element.
63-
*/
64-
protected abstract Integer getSearchKey(String uuid);
65-
66-
/*
67-
* parametr index equals index of element in mapStorage, wich is next to inserting element
68-
* */
6970
protected abstract void insertResume(int index, Resume resume);
7071

7172
protected abstract void deleteResume(int index);

src/com/urise/webapp/storage/AbstractStorage.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
import com.urise.webapp.exception.ExistStorageException;
44
import com.urise.webapp.exception.NotExistStorageException;
55
import com.urise.webapp.model.Resume;
6+
import java.util.List;
7+
import java.util.stream.Collectors;
8+
import java.util.stream.Stream;
69

710
public abstract class AbstractStorage implements Storage {
811

@@ -18,6 +21,12 @@ public abstract class AbstractStorage implements Storage {
1821

1922
protected abstract Object getSearchKey(String uuid);
2023

24+
protected abstract Stream<Resume> getStream();
25+
26+
public List<Resume> getAllSorted(){
27+
return getStream().sorted().collect(Collectors.toList());
28+
}
29+
2130
public void save(Resume resume) {
2231
doSave(resume, getNotExistedSearchKey(resume.getUuid()));
2332
}

src/com/urise/webapp/storage/ArrayStorage.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.urise.webapp.model.Resume;
44

5+
56
/**
67
* Array based mapStorage for Resumes
78
*/
@@ -16,6 +17,7 @@ protected Integer getSearchKey(String uuid) {
1617
return -1;
1718
}
1819

20+
1921
@Override
2022
protected void insertResume(int index, Resume resume) {
2123
storage[resumeCounter] = resume;

src/com/urise/webapp/storage/ListStorage.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.util.ArrayList;
66
import java.util.List;
77
import java.util.stream.Collectors;
8+
import java.util.stream.Stream;
89

910
public class ListStorage extends AbstractStorage {
1011
private List<Resume> list = new ArrayList<>();
@@ -50,8 +51,8 @@ public void clear() {
5051
}
5152

5253
@Override
53-
public List<Resume> getAllSorted() {
54-
return list.stream().sorted(RESUME_COMAPATOR).collect(Collectors.toList());
54+
protected Stream<Resume> getStream() {
55+
return list.stream();
5556
}
5657

5758
@Override

src/com/urise/webapp/storage/MapStorage.java

Lines changed: 3 additions & 2 deletions

0 commit comments

Comments
 (0)