Run the function runWithParameters() in MainTest and it will print the available Intervals for each Calendar, it will also print the available timeslots for those intervals
I had to manually set the version of the project to Java 11 several times in Intellij in order to utilize the java.nio.file.* packages
and it kept resetting. If any of those packages gives error I fixed it by manually changing the compiler here:
- Understand datatypes (30 min)
- Import files and calendars into java objects (60 min) http://www.jsonschema2pojo.org/
- Figure out how to use ISO 8601 Intervals (30 min) https://www.threeten.org/threeten-extra/
- Method for Iterating Calendars Timeslots (120 min) https://stackoverflow.com/questions/8405087/what-is-this-date-format-2011-08-12t201746-384z
- Colleting Timeslots (180 min) Spent a long time struggling with iterating over available timeslots, but took a step back and decided to make it easier by reading the array in the order they are when I understood they are already chronological
- Return available Intervals with Timeslots. (60 min)
- Some clean up and documentation (30 min)
fetchCalendars()
Function grabs calendars and parse from Json into Java classes defined in dto package. Using Java new function introduced in Java 11 (new to me at least, but worked very well). Use com.google.gson to parse Json, have had good experience with this earlier so decided to go with it again
private HashMap<Interval, List> findTimeslotsWithinIntervals(Calendar calendar, ArrayList intervalsAvailable)
Helper function, tried to naturally split this out of the receiving function to keep it a bit cleaner. This function takes in the calendar and a list of intervals available. Will return each interval again with available timeslots within that interval.
Map<String, HashMap<Interval, List>> findAvailableTime(String[] calendarIds, int durationInSeconds, Interval intervalToSearch)
Main function to solve the assignment.
- Gets Calendars relevant to CalendarId-s from parameter.
- Then iterates through each calendar's appointments to find appointments that collide with the requested interval
- No collitions? Continue
- Check gaps before the first appointment, after the last appointment and between the rest of the appointments to see if there is a room for an appointment with the requested duration
- Compile a new list of intervals from the gaps found where a potential meeting can fit.
- Utilize helper function findTimeslotsWithinIntervals to get all the timeslots available within the intervals which are not booked
- Return
- Would've like to have more tests underway but got hung up in the functionality.
- Got stuck on timeslots trying to figure out how to connect one timeslot.end to another timeslot.start and create chains/links of timeslots, spent too long on this before I realized I could easily read the timeslots in their order as they are already chronological.
- Not returning a finished functionality rather data that can be read into functionality.
- Had som issues with Intellij resetting to wrong Java version when I used Java 11 functionality. Should be good now, otherwise solution is in disclaimer. Not sure why this is happening, sorry about that if it creates an issue!