Skip to content

Implement timetable logic and add unit tests#2

Open
Aleakw wants to merge 2 commits intomainfrom
develop
Open

Implement timetable logic and add unit tests#2
Aleakw wants to merge 2 commits intomainfrom
develop

Conversation

@Aleakw
Copy link
Owner

@Aleakw Aleakw commented Feb 26, 2026

No description provided.

Copy link

@avfyodorov avfyodorov left a comment

Choose a reason for hiding this comment

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

Добрый вечер, Никита!

Очень хорошая работа, от меня всего пара уточнений.


private /* как это хранить??? */ timetable;

private Map<DayOfWeek, List<TrainingSession>> dayCache;

Choose a reason for hiding this comment

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

private Map<DayOfWeek, List<TrainingSession>> dayCache;

Честно говоря, не до конца понял выгоду от добавления и поддержания этой структуры. Лучше было бы сразу же собирать статистику в разрезе тренеров.
На ваше усмотрение.

private HashMap<Coach, Integer> coachesCounter;

Copy link
Owner Author

Choose a reason for hiding this comment

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

Согласен. Добавлю coachesCounter и упрощю реализацию.

for (DayOfWeek day : DayOfWeek.values()) {
List<TrainingSession> list = dayCache.get(day);

for (TrainingSession session : list) {

Choose a reason for hiding this comment

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

На ваше усмотрение.
В принципе, можно было бы избавиться от вложенных циклов, оставив только один:

.....
  List<CounterOfTrainings> counterOfTrainingsList = new ArrayList<CounterOfTrainings>();
        for (Coach coach: coachesCounter.keySet()) {
            CounterOfTrainings counterOfTrainings = new CounterOfTrainings(coach, coachesCounter.get(coach));
            counterOfTrainingsList.add(counterOfTrainings);
        }
............

Для этого нужно завести дополнительную переменную:

//Сразу же подсчитывать количество тренировок
    private HashMap<Coach, Integer> coachesCounter;

И при добавлении очередной тренировки сразу же прибавлять её и в мапу:

    public void addNewTrainingSession(TrainingSession trainingSession) {
................

//Сразу же подсчитывать количество тренировок
        Coach currentCoach = trainingSession.getCoach();
        coachesCounter.put(currentCoach, coachesCounter.getOrDefault(currentCoach, 0) + 1);
.........

Copy link
Owner Author

Choose a reason for hiding this comment

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

Согласен, действительно можно упростить логику и избежать вложенных циклов, если поддерживать статистику по тренерам при добавлении тренировки. Внесу изменения и добавлю coachesCounter.

Copy link

@avfyodorov avfyodorov left a comment

Choose a reason for hiding this comment

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

Добрый день, Никита!

Замечаний нет.
Работа принята.

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