walkthroughs/week-5-tdd/project/src/main/java/com/google/sps/FindMeetingQuery.java
public Collection<TimeRange> checkBookedOptionalAttendees(List<Event> newEvents, ArrayList<TimeRange> availableTimeRanges, MeetingRequest request, Integer eventEndTime) {
    Collection<TimeRange> availableTimeRangesWithOptional = new ArrayList<>();
    Set<String> optionalAttendees = new HashSet<>(request.getOptionalAttendees());
    Integer endOfTheDay = 24 * 60;

    Integer optionalStartTime = 0;
    for (int eventIndex = 0; eventIndex < newEvents.size() ; eventIndex++)  {
        Set<String> eventAttendees = newEvents.get(eventIndex).getAttendees();
        if (optionalAttendees.containsAll(eventAttendees)) {
            TimeRange eventTime = newEvents.get(eventIndex).getWhen();
            for (int timeRangeIndex = 0 ; timeRangeIndex < availableTimeRanges.size(); timeRangeIndex++) {
                if (availableTimeRanges.get(timeRangeIndex).contains(eventTime)) {
                    if (optionalStartTime < eventTime.start()) {
                        TimeRange newAvailableTime = TimeRange.fromStartEnd(optionalStartTime, eventTime.start(), false);
                        availableTimeRangesWithOptional.add(newAvailableTime);
                    }
                    optionalStartTime = eventTime.end();
                }
            }
        }
    }
    if (optionalStartTime < endOfTheDay & optionalStartTime != 0) {
        TimeRange availableTimeToBook = TimeRange.fromStartEnd(eventEndTime, endOfTheDay, false);
        availableTimeRangesWithOptional.add(availableTimeToBook);
    }
    return availableTimeRangesWithOptional;
  }
/**
   * This method uses the above helper functions to decide the available time 
   * based on the booked events and requested duration and attendees.
   * @param newEvents It contains a collection of event objects
   * @param availableTimeRanges It contains the available time slots, considering just mandatory attendees.
   * @param request It contains a MeetingRequest object.
   * @param eventEndTime saves the end time of the last event.
   * @return Collection<TimeRange> contains all the time slot available.
   */
This method uses the above helper functions to decide the available time
based on the booked events and requested duration and attendees.
@param newEvents It contains a collection of event objects
@param availableTimeRanges It contains the available time slots, considering just mandatory attendees.
@param request It contains a MeetingRequest object.
@param eventEndTime saves the end time of the last event.
@return Collection contains all the time slot available.
This method uses the above helper functions to decide the available time based on the booked events and requested duration and attendees . @param newEvents It contains a collection of event objects @param availableTimeRanges It contains the available time slots considering just mandatory attendees . @param request It contains a MeetingRequest object . @param eventEndTime saves the end time of the last event . @return Collection contains all the time slot available .
public Collection<TimeRange> checkBookedOptionalAttendees(List<Event> newEvents, ArrayList<TimeRange> availableTimeRanges, MeetingRequest request, Integer eventEndTime) {
    Collection<TimeRange> availableTimeRangesWithOptional = new ArrayList<>();
    Set<String> optionalAttendees = new HashSet<>(request.getOptionalAttendees());
    Integer endOfTheDay = 24 * 60;
    Integer optionalStartTime = 0;
    for (int eventIndex = 0; eventIndex < newEvents.size() ; eventIndex++)  {
        Set<String> eventAttendees = newEvents.get(eventIndex).getAttendees();
        if (optionalAttendees.containsAll(eventAttendees)) {
            TimeRange eventTime = newEvents.get(eventIndex).getWhen();
            for (int timeRangeIndex = 0 ; timeRangeIndex < availableTimeRanges.size(); timeRangeIndex++) {
                if (availableTimeRanges.get(timeRangeIndex).contains(eventTime)) {
                    if (optionalStartTime < eventTime.start()) {
                        TimeRange newAvailableTime = TimeRange.fromStartEnd(optionalStartTime, eventTime.start(), false);
                        availableTimeRangesWithOptional.add(newAvailableTime);
                    }
                    optionalStartTime = eventTime.end();
                }
            }
        }
    }
    if (optionalStartTime < endOfTheDay & optionalStartTime != 0) {
        TimeRange availableTimeToBook = TimeRange.fromStartEnd(eventEndTime, endOfTheDay, false);
        availableTimeRangesWithOptional.add(availableTimeToBook);
    }
    return availableTimeRangesWithOptional;
  }
public Collection < TimeRange > checkBookedOptionalAttendees ( List < Event > newEvents , ArrayList < TimeRange > availableTimeRanges , MeetingRequest request , Integer eventEndTime ) { Collection < TimeRange > availableTimeRangesWithOptional = new ArrayList < > ( ) ; Set < String > optionalAttendees = new HashSet < > ( request . getOptionalAttendees ( ) ) ; Integer endOfTheDay = 24 * 60 ; Integer optionalStartTime = 0 ; for ( int eventIndex = 0 ; eventIndex < newEvents . size ( ) ; eventIndex ++ ) { Set < String > eventAttendees = newEvents . get ( eventIndex ) . getAttendees ( ) ; if ( optionalAttendees . containsAll ( eventAttendees ) ) { TimeRange eventTime = newEvents . get ( eventIndex ) . getWhen ( ) ; for ( int timeRangeIndex = 0 ; timeRangeIndex < availableTimeRanges . size ( ) ; timeRangeIndex ++ ) { if ( availableTimeRanges . get ( timeRangeIndex ) . contains ( eventTime ) ) { if ( optionalStartTime < eventTime . start ( ) ) { TimeRange newAvailableTime = TimeRange . fromStartEnd ( optionalStartTime , eventTime . start ( ) , false ) ; availableTimeRangesWithOptional . add ( newAvailableTime ) ; } optionalStartTime = eventTime . end ( ) ; } } } } if ( optionalStartTime < endOfTheDay & optionalStartTime != 0 ) { TimeRange availableTimeToBook = TimeRange . fromStartEnd ( eventEndTime , endOfTheDay , false ) ; availableTimeRangesWithOptional . add ( availableTimeToBook ) ; } return availableTimeRangesWithOptional ; }
This method uses the above helper functions to decide the available time
 based on the booked events and requested duration and attendees.
This method uses the above helper functions to decide the available time based on the booked events and requested duration and attendees .