I have an app to write in Java to find the available booking slot in a day. what I have a is a json file which contain the list of already booked slot and the open/close time of the booking.
For example (just assume the numbers below are given as exampe),
{
    "bookingopen" : 112,
    "bookingclose" : 213,
    "list_of_booking" : {
          "start" : "114",
          "end" : "119"
        },
        {
          "start" : "136",
          "end" : "180",
        },
        {
          "start" : "140",
          "end" : "156"
        }
    }
}
what I want to get is the remaining spot:
(112..114), (119..136) and (180..213)
I have tried using
IntStream but it's not working.
I have also wrote a set of if condition:
for(int i = 1; i < mListOfBooking.size()-1; i++){
            if(mListOfBooking.get(i-1).getArriveTime() > venue.getOpenTime() && (i-1 == 0)) {
                mNewList.add(new Person(0, "No visitors", venue.getOpenTime(), mListOfBooking.get(i - 1).getArriveTime()));
            } else if (mListOfBooking.get(i-1).getLeaveTime() < mListOfBooking.get(i).getArriveTime()){
                mNewList.add(new Person(0, "No visitors", mListOfBooking.get(i-1).getLeaveTime(), mListOfBooking.get(i).getArriveTime()));
            } else if((i == mListOfBooking.size()-1) && (mListOfBooking.get(i).getLeaveTime() < venue.getCloseTime())){
                mNewList.add(new Person(0, "No visitors", mListOfBooking.get(i).getLeaveTime(), venue.getCloseTime()));
            }
                mNewList.add(new Person(mListOfBooking.get(i - 1).getId(),
                        mListOfBooking.get(i - 1).getArriveTime(),
                        mListOfBooking.get(i - 1).getLeaveTime()));
}
method getclose, getopen, getLeaveTime, getArrive a just method to extarct information from the JSON
this logic is not good and probably not "smart" enough because it misses some cases and I can't have an if in any edge case.
Any idea on a good algorithm to extract the available slot