Skip to content

Sprint 8 solution#3

Merged
zephyr0021 merged 18 commits intomainfrom
sprint_8-solution-time-and-duration
Feb 19, 2025
Merged

Sprint 8 solution#3
zephyr0021 merged 18 commits intomainfrom
sprint_8-solution-time-and-duration

Conversation

@zephyr0021
Copy link
Owner

Выполнил ТЗ 8 спринта

}
};

TreeSet<Task> prioritizedTasks = new TreeSet<>(comparator);
Copy link

Choose a reason for hiding this comment

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

TreeSet стоит вынести в поле класса,
при добавлении тасок, можно было бы записывать их в TreeSet
то есть getPrioritizedTasks возвращал бы уже готовую коллекцию

при обновлении тасок (методы update) стоит учитывать, что время старта может изменяться.
чтобы сортировка в tree set происходила, нужно удалять объект и добавлять обратно

Copy link
Owner Author

Choose a reason for hiding this comment

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

Да, согласен с вами! Поправил! Благодарю!

}

@Override
public TreeSet<Subtask> getPrioritizedSubtasks() {
Copy link

Choose a reason for hiding this comment

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

В тз явно не отметили момент про одну коллекцию,
но все таки идея была, что будет TreeSet<Task>, в котором и таски и саб-таски

Отсортируйте все задачи по приоритету — то есть по startTime. 
Напишите новый метод getPrioritizedTasks, возвращающий 
список задач и подзадач в заданном порядке. 

Copy link
Owner Author

Choose a reason for hiding this comment

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

Поправил! Спасибо :)

}

@Override
public TreeSet<Epic> getPrioritizedEpics() {
Copy link

Choose a reason for hiding this comment

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

по тз был только список из задач и подзадач

Copy link
Owner Author

Choose a reason for hiding this comment

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

Убрал не нужную реализацию!

@zephyr0021 zephyr0021 requested a review from z8q February 13, 2025 13:07
private final HashMap<Integer, Epic> epics = new HashMap<>();
private final HistoryManager historyManager = Managers.getDefaultHistory();
private int taskId = 0;
private final Comparator<Task> comparator = new Comparator<>() {
Copy link

Choose a reason for hiding this comment

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

можно немного оптимизировать до такого вида
Comparator.comparing(Task::getStartTime);

еще можно допустить сортировку, если поле startTime == null
Comparator.comparing(Task::getStartTime, Comparator.nullsLast(Comparator.naturalOrder()));

Copy link
Owner Author

Choose a reason for hiding this comment

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

Поправил

Comment on lines +249 to +250
prioritizedTasks.addAll(tasksWithoutTimeNulls);
prioritizedTasks.addAll(subtasksWithoutTimeNulls);
Copy link

Choose a reason for hiding this comment

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

в подсказке в тз есть такой блок

Если сортировать список заново каждый раз, сложность получения будет O(n∗log(n)). 
Можно хранить все задачи заранее отсортированными с помощью класса TreeSet.

тут как раз происходит сборка treeset и сортировка при каждом вызове getPrioritizedTasks

Copy link

Choose a reason for hiding this comment

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

идея в том, чтобы наполнять prioritizedTasks по мере добавления задач в менеджер, то есть на каждый add таски или саб-таски делать add в prioritizedTasks тоже

при обновлении задач, также обновлять prioritizedTasks для пересортировки, в случае изменения startTime

при удалении задач, помимо мап и истории, их также нужно будет удалять из prioritizedTasks

в методах вида clear all tasks/subtasks/epics нужно будет, помимо прочего, очищать prioritizedTasks тоже
clear all tasks - удалять из tree set только таски
clear all subtasks - удалять из tree set все саб-таски
clear all epics - удалять из tree set все саб-таски

Copy link
Owner Author

Choose a reason for hiding this comment

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

Убрал не нужный код! Оставил в выводе только фильтрацию nullовых startTime значений тасков

@zephyr0021 zephyr0021 requested a review from z8q February 14, 2025 10:55
@zephyr0021 zephyr0021 merged commit d166709 into main Feb 19, 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