-
Notifications
You must be signed in to change notification settings - Fork 0
Optional attendees #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
| attendees.retainAll(event.getAttendees()); | ||
| // Attendees is only required attendees, allAttendees includes optional attendees | ||
| Set<String> requiredAttendees = new HashSet<>(request.getAttendees()); | ||
| Set<String> optionalAttendees = new HashSet<>(request.getOptionalAttendees()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You may take this out of the loop so that you don't need redundant set creations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
| Set<String> optionalAttendees = new HashSet<>(request.getOptionalAttendees()); | ||
| Set<String> allAttendees = new HashSet<>(Sets.union(requiredAttendees, optionalAttendees)); | ||
|
|
||
| // I couldn't think of a way to factor this, I'm sorry Zu :'( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looks fine with me. Please remove this comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops done!
| List<TimeRange> requiredOpenings = new ArrayList<>(findOpenings(attendedMeetings, duration)); | ||
| List<TimeRange> allOpenings = new ArrayList<>(findOpenings(allAttendedMeetings, duration)); | ||
|
|
||
| return allOpenings.size() == 0 ? requiredOpenings : allOpenings; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a good comment in the method header on what it returns ("if there is an opening for eveyone, return it, otherwise return the opening for the required").
In general, this is not the most recommended interface design, because the caller wouldn't (explicitly) know whether the returned openings are for everyone or for the required only. It is recommended to make the interface explicit about what it returns to minimize any potential error/bug. At minimum, it should be explicit in the comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made explicit in a comment. I definitely understand your concerns, and will revisit further if you'd like
| List<TimeRange> allAttendedMeetings = new ArrayList<>(); | ||
|
|
||
| // Attendees is only required attendees, allAttendees includes optional attendees | ||
| Set<String> requiredAttendees = new HashSet<>(request.getAttendees()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You cannot take out requiredAttendees because you eventually changes them bellow (retainAll). That reminds me of a lesson that you want to make objects immutable whenever possible. Can you move the requiredAttendees back in and make optionalAttendees ImmutableSet?
Also try to find out other immutable containers throughout the code and change them to immutable.
Calendar algorithm updated to consider optional attendees!