Skip to content

Подготовить проект к ревью шестого спринта - #2

Merged
AleksOBM merged 2 commits into
mainfrom
sprint_6-solution
Oct 10, 2025
Merged

Подготовить проект к ревью шестого спринта#2
AleksOBM merged 2 commits into
mainfrom
sprint_6-solution

Conversation

@AleksOBM

@AleksOBM AleksOBM commented Oct 8, 2025

Copy link
Copy Markdown
Owner

Сделать историю посещений неограниченной по размеру.
Избавиться от повторных просмотров в истории.

Comment thread src/manager/InMemoryHistoryManager.java Outdated
public List<T> getHistory() {
return new ArrayList<>((ArrayList<? extends T>) history);
public List<Task> getHistory() {
List<Task> history = List.copyOf(getTasks());

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

метод getTasks() сам при каждом вызове создает новую коллекцию, создавать еще одну не нужно

Comment thread src/manager/InMemoryHistoryManager.java Outdated
public List<Task> getHistory() {
List<Task> history = List.copyOf(getTasks());
if (history.isEmpty()) {
return null;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

лучше пустой список, чем null

Comment thread src/manager/InMemoryHistoryManager.java Outdated
public void add(Task task) {
int taskId = task.getId();

if (idToNode.isEmpty()) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

перенеси добавление первой ноды в метод linkLast()

Comment thread src/manager/InMemoryHistoryManager.java Outdated
Node newNode = new Node(null, task, null);
idToNode.put(task.getId(), newNode);
first = newNode;
} else if (idToNode.containsKey(taskId)) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

действие linkLast(task) присутствует как в блоке if(), так и else(), значит оно никак не зависит от условия оператора if/else и его можно сделать одним действием уже после оператора

private void linkLast(Task task) {
Node oldLastNode;
Node newLastNode;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

если в очереди только одна нода, то на нее должны указывать как first, так и last. По аналогии с очередью например к врачу: единственный пациент, он же ответит я, на вопрос врача кто первый, и так же ответит я, на вопрос нового пациента кто последний.

Comment thread src/manager/InMemoryHistoryManager.java Outdated

Node node = first;
while (node.next != null) {
tasks.add(node.next.data);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. добавляй задачу из текущей ноды, а не следующей
  2. в while() так же с null проверяй текущую ноду
  3. действие tasks.add(first.data) убери

Comment thread src/manager/InMemoryHistoryManager.java Outdated
int taskId = node.data.getId();

if (node.prev == null & node.next == null) {
idToNode.remove(taskId);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

убери из всех if/else удаление из idToNode и сделай его одной строкой после


if (node.prev == null & node.next == null) {
idToNode.remove(taskId);
first = null;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

еще нужно обнуллить и last

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

метод removeAllSubtasksByEpic(int epicId) - еще нужно все подзадачи удалить из истории

метод removeAllTasks() - аналогично

метод removeAllEpics() - тут и эпики, и подзадачи долой из истории

метод removeAllSubTasks() - тут только подзадачи

Comment thread src/manager/InMemoryTaskManager.java Outdated
public ArrayList<? extends Task> getHistory() {
return (ArrayList<? extends Task>) historyManager.getHistory();
public ArrayList<Task> getHistory() {
return new ArrayList<>(historyManager.getHistory());

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

это уже третье оборачивание в новый список истории, не нужно))

@AleksOBM AleksOBM changed the title Подготовить проект к первому ревью шестого спринта Подготовить проект к ревью шестого спринта Oct 9, 2025
@AleksOBM
AleksOBM merged commit a95d028 into main Oct 10, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants