impl: ldp find gaps fitting

This commit is contained in:
Václav Přibík
2025-10-23 21:19:32 +02:00
parent 427e963cac
commit 2df2500b77

View File

@@ -89,10 +89,32 @@ public class LocalDayPlanImpl implements LocalDayPlan {
throw new UnsupportedOperationException("Unimplemented method 'findMatchingFreeSlotsOfDuration'");
}
private CustomLinkedList<TimeSlot> traverseGapsFitting(Duration toFind, CustomLinkedList<TimeSlot> goodSlots,
Instant startOfBefore, Iterator<Appointment> iterator) {
boolean hasNext = iterator.hasNext();
Appointment nextAppointment = hasNext ? iterator.next() : null;
TimeSlot possibleFittingSlot = new TimeSlotImpl(hasNext ? nextAppointment.end() : startOfDay(),
startOfBefore == null ? endOfDay() : startOfBefore);
if (possibleFittingSlot.fits(toFind)) {
goodSlots.add(possibleFittingSlot);
}
if (!hasNext) {
return goodSlots;
}
return traverseGapsFitting(toFind, goodSlots, nextAppointment.start(), iterator);
}
@Override
public List<TimeSlot> findGapsFitting(Duration duration) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'findGapsFitting'");
return new CustomListToJavaBinding<>(
traverseGapsFitting(duration, new CustomLinkedListImpl<>(), null, timeline.iterator()));
}
@Override