Skip to content
This repository has been archived by the owner on Oct 23, 2023. It is now read-only.

Commit

Permalink
chore(school): remove duplication in areEventsInTimeTableOverlapping …
Browse files Browse the repository at this point in the history
…in AlterationPolicy
  • Loading branch information
AndreaBrighi committed Jul 9, 2023
1 parent 6c93d49 commit c9db27d
Showing 1 changed file with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,24 +106,28 @@ object AlterationPolicy {
}
return when (newLesson) {
is WeekLesson ->
allLesson
.filter { lesson ->
isNewLessonOverlapping(newLesson, lesson)
}.any {
isOverlappingTime(it, newLesson)
}
checkOverlapping(newLesson, allLesson) {
isNewLessonOverlapping(newLesson, it)
}

is DateLesson ->
allLesson.filter { lesson ->
isNewLessonOverlapping(newLesson, lesson)
}.any {
isOverlappingTime(it, newLesson)
checkOverlapping(newLesson, allLesson) {
isNewLessonOverlapping(newLesson, it)
}

else -> true
}
}

private fun checkOverlapping(
newLesson: CalendarEvent,
allLesson: List<CalendarEvent>,
filter: (CalendarEvent) -> Boolean,
) =
allLesson.filter(filter).any {
isOverlappingTime(it, newLesson)
}

/**
* Checks if the event in the interval is already cancelled or rescheduled.
*
Expand Down

0 comments on commit c9db27d

Please sign in to comment.