private static AvailabilityTimeLine buildTimeline(
List<CriterionSatisfaction> satisfactions) {
if (satisfactions.isEmpty()) {
return AvailabilityTimeLine.createAllInvalid();
}
AvailabilityTimeLine result = AvailabilityTimeLine.allValid();
LocalDate previousEnd = null;
for (CriterionSatisfaction each : satisfactions) {
LocalDate startDate = each.getStartDate();
assert startDate != null : "satisfactions start date is not null";
if (previousEnd == null) {
result.invalidUntil(startDate);
} else {
result.invalidAt(previousEnd, startDate);
}
previousEnd = each.getEndDate();
if (previousEnd == null) {
break;
}
}
if (previousEnd != null) {
result.invalidFrom(previousEnd);
}
return result;
}