The following code should be simpler:
public boolean isOverlapping(IntegerInterval other) {
if (other == null) return false; // for readability's sake, this condition is pulled out
// overlap happens ONLY when this's end is on the right of other's start
// AND this's start is on the left of other's end.
return (((this.end == null) || (other.start == null) || (this.end.intValue() >= other.start.intValue())) &&
((this.start == null) || (other.end == null) || (this.start.intValue() <= other.end.intValue())));
}
UPDATE If compare by Date
as @Adam actually asked, the code would be:
private static boolean dateRangesAreOverlaping(Date start1, Date end1,
Date start2, Date end2) {
return (((end1 == null) || (start2 == null) || end1.after(start2)) &&
((start1 == null) || (end2 == null) || start1.before(end2)));
}