Skip to content
This repository was archived by the owner on Jun 24, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* Event is the container class for when a specific group of people are meeting and are therefore
* busy. Events are considered read-only.
*/
public final class Event {
public final class Event implements Comparable<Event>{
private final String title;
private final TimeRange when;
private final Set<String> attendees = new HashSet<>();
Expand Down Expand Up @@ -75,6 +75,9 @@ public Set<String> getAttendees() {
// internal data.
return Collections.unmodifiableSet(attendees);
}
public int compareTo(Event eventB) {
return this.getWhen().start() - eventB.getWhen().start();
}

@Override
public int hashCode() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,54 @@

package com.google.sps;

import java.util.Collection;
import java.util.*;

public final class FindMeetingQuery {
public Collection<TimeRange> query(Collection<Event> events, MeetingRequest request) {
throw new UnsupportedOperationException("TODO: Implement this method.");
long duration = request.getDuration();
ArrayList<Event> allEvents = new ArrayList();
Set<String> attendees = new HashSet<String>(request.getAttendees());
for (Event event : events) {
Set<String> curAttendees = new HashSet<String>(attendees);
curAttendees.retainAll(event.getAttendees());
if (!(curAttendees.isEmpty())){
allEvents.add(event);
}
}
Collections.sort(allEvents);

ArrayList<TimeRange> times = new ArrayList();
int start = 0;
Boolean cont = false;
for (int i = 0; i < allEvents.size(); i++) {
TimeRange curTime = allEvents.get(i).getWhen();
if (!cont) {
TimeRange curRange = TimeRange.fromStartEnd(start, curTime.start(), false);
if ((long) curRange.duration() >= request.getDuration()) {
times.add(curRange);
}

}
if ((i != allEvents.size() - 1) && curTime.overlaps(allEvents.get(i+1).getWhen())) {
cont = true;
} else {
start = curTime.end();
cont = false;
}

if (i == allEvents.size() - 1) {
TimeRange curRange = TimeRange.fromStartEnd(start, 1440, false);
if ((long) curRange.duration() >= request.getDuration()) {
times.add(curRange);
}

}
}
if (allEvents.size() == 0) {
times.add(TimeRange.fromStartEnd(0, 1440, false));
}
return times;
}


}