walkthroughs/week-5-tdd/project/src/main/java/com/google/sps/FindMeetingQuery.java
/**
   * Finds the workable time between attendees events and meeting duration.
   *
   * @param conflictTimes  collection of time range conflicting with the meeting
   *
   * @return collection of time when the meeting can be scheduled.
   */
Finds the workable time between attendees events and meeting duration.
@param conflictTimes  collection of time range conflicting with the meeting

@return collection of time when the meeting can be scheduled.
Finds the workable time between attendees events and meeting duration . @param conflictTimes collection of time range conflicting with the meeting @return collection of time when the meeting can be scheduled .
private ArrayList<TimeRange> findWorkableTimes(List<TimeRange> conflictTimes, long meetingDuration) {
    ArrayList<TimeRange> workableTimes = new ArrayList<>();    
    Collections.sort(conflictTimes, TimeRange.ORDER_BY_START);
    int workableTimeStart = TimeRange.START_OF_DAY;
    int workableTimeEnd = 0;
    int previousLargeConflictEnd = 0;
    for (TimeRange conflictTime : conflictTimes) {
      workableTimeEnd = conflictTime.start();
      if (meetingDuration <= workableTimeEnd - workableTimeStart) {
        workableTimes.add(TimeRange.fromStartEnd(workableTimeStart, workableTimeEnd, false));
      }
      if (previousLargeConflictEnd < conflictTime.end()) {
        previousLargeConflictEnd = conflictTime.end();
      }
      workableTimeStart = previousLargeConflictEnd > conflictTime.end() ? previousLargeConflictEnd : conflictTime.end();
    }
    if (TimeRange.END_OF_DAY - workableTimeStart >= meetingDuration) {
      workableTimes.add(TimeRange.fromStartEnd(workableTimeStart, TimeRange.END_OF_DAY, true));
    }
    return workableTimes;
  }
private ArrayList < TimeRange > findWorkableTimes ( List < TimeRange > conflictTimes , long meetingDuration ) { ArrayList < TimeRange > workableTimes = new ArrayList < > ( ) ; Collections . sort ( conflictTimes , TimeRange . ORDER_BY_START ) ; int workableTimeStart = TimeRange . START_OF_DAY ; int workableTimeEnd = 0 ; int previousLargeConflictEnd = 0 ; for ( TimeRange conflictTime : conflictTimes ) { workableTimeEnd = conflictTime . start ( ) ; if ( meetingDuration <= workableTimeEnd - workableTimeStart ) { workableTimes . add ( TimeRange . fromStartEnd ( workableTimeStart , workableTimeEnd , false ) ) ; } if ( previousLargeConflictEnd < conflictTime . end ( ) ) { previousLargeConflictEnd = conflictTime . end ( ) ; } workableTimeStart = previousLargeConflictEnd > conflictTime . end ( ) ? previousLargeConflictEnd : conflictTime . end ( ) ; } if ( TimeRange . END_OF_DAY - workableTimeStart >= meetingDuration ) { workableTimes . add ( TimeRange . fromStartEnd ( workableTimeStart , TimeRange . END_OF_DAY , true ) ) ; } return workableTimes ; }
Finds the workable time between attendees events and meeting duration.
Finds the workable time between attendees events and meeting duration .