/// <summary> /// Add a TimeTableEvent to the Timetable if it doesn't collide with existing TimetableEvents /// </summary> /// <param name="timetableEvent">Event to add to Timetable</param> /// <returns>Returns true if TimetableEvent successfully added otherwise false</returns> public bool AddEvent(TimetableEvent timetableEvent) { if (EventCollides(timetableEvent)) { return(false); } _events.Add(timetableEvent); return(true); }
/// <summary> /// Check whether a Timetable event collides with this TimetableEvent /// </summary> /// <param name="timetableEvent">Timetable event to check</param> /// <returns>Whether a Timetable event collides with this TimetableEvent</returns> public bool EventCollides(TimetableEvent timetableEvent) { // Collision if start between the new events start and end or end between the new events start and end return(Start.CompareTo(timetableEvent.Start) < 0 && Start.CompareTo(timetableEvent.End) > 0 || End.CompareTo(timetableEvent.Start) > 0 && End.CompareTo(timetableEvent.End) < 0); }
/// <summary> /// Check whether a Timetable event collides with any existing TimetableEvent in the Timetable /// </summary> /// <param name="timetableEvent">Timetable event to check</param> /// <returns>Whether the event collides with any of the existing TimetableEvents in the Timetable</returns> private bool EventCollides(TimetableEvent timetableEvent) { // Checks if any of the existing timetable events collide with it (inefficient with high amounts of events due to checking all of them) return(_events.Any(exitingTimetableEvent => exitingTimetableEvent.EventCollides(timetableEvent))); }
/// <summary> /// Add a TimeTableEvent to the Timetable without checking if it collides with existing TimetableEvents /// </summary> /// <param name="timetableEvent">Event to add to Timetable</param> public void AddEventUnchecked(TimetableEvent timetableEvent) { _events.Add(timetableEvent); }