}
else if (endDate.before(startDate)) {
throw new IllegalArgumentException("End date must be after start date (start date = " + startDate + ", end date = " + endDate + ")");
}
EOQualifier startKeyBeforeStartDate = ERXQ.lessThan(startDateKey, startDate);
EOQualifier startKeyBeforeEndDate = ERXQ.lessThan(startDateKey, endDate);
EOQualifier startKeyOnStartDate = ERXQ.equals(startDateKey, startDate);
EOQualifier startKeyOnEndDate = ERXQ.equals(startDateKey, endDate);
EOQualifier startKeyAfterStartDate = ERXQ.greaterThan(startDateKey, startDate);
EOQualifier startKeyAfterEndDate = ERXQ.greaterThan(startDateKey, endDate);
EOQualifier endKeyBeforeStartDate = ERXQ.lessThan(endDateKey, startDate);
EOQualifier endKeyBeforeEndDate = ERXQ.lessThan(endDateKey, endDate);
EOQualifier endKeyOnStartDate = ERXQ.equals(endDateKey, startDate);
EOQualifier endKeyOnEndDate = ERXQ.equals(endDateKey, endDate);
EOQualifier endKeyAfterStartDate = ERXQ.greaterThan(endDateKey, startDate);
EOQualifier endKeyAfterEndDate = ERXQ.greaterThan(endDateKey, endDate);
// Around Start
EOQualifier aroundStart = ERXQ.and(startKeyAfterStartDate, startKeyBeforeEndDate);
// Ends At Start
EOQualifier endsAtStart = ERXQ.and(startKeyAfterStartDate, startKeyOnEndDate);
// Surrounding
EOQualifier surrounding = ERXQ.and(startKeyBeforeStartDate, endKeyAfterEndDate);
// Directly Overlapping
EOQualifier directlyOverlapping = ERXQ.and(startKeyOnStartDate, endKeyOnEndDate);
// In Between
EOQualifier inBetween = ERXQ.and(startKeyBeforeStartDate, endKeyAfterStartDate, endKeyAfterStartDate, endKeyAfterEndDate);
// Around End
EOQualifier aroundEnd = ERXQ.and(endKeyAfterStartDate, endKeyBeforeEndDate);
// Starts At End
EOQualifier startsAtEnd = ERXQ.and(endKeyOnStartDate, endKeyBeforeEndDate);
EOQualifier qualifier;
if (exclusive) {
qualifier = ERXQ.or(aroundStart, surrounding, directlyOverlapping, inBetween, aroundEnd);
}
else {
qualifier = ERXQ.or(aroundStart, startKeyOnStartDate, endKeyOnStartDate, endsAtStart, surrounding, directlyOverlapping, inBetween, aroundEnd, endKeyOnEndDate, startsAtEnd, startKeyOnEndDate);