/** * Returns <code>true</code> if {@link TimeInterval} i1 contains {@link TimeInterval} i2, <code> * false</code> otherwise (<code>null</code> border means infinity). */ public static boolean contains(TimeInterval i1, TimeInterval i2) { if (i1 == null || i2 == null) return false; i1 = arrange(i1); i2 = arrange(i2); if (i2.getStart() == null && i2.getEnd() == null) return i1.getStart() == null && i1.getEnd() == null; else if (i2.getStart() != null && i2.getEnd() == null) return i1.contains(i2.getStart()) && i1.getEnd() == null; else if (i2.getStart() == null && i2.getEnd() != null) return i1.getStart() == null && i1.contains(i2.getEnd()); else return i1.contains(i2.getStart()) && i1.contains(i2.getEnd()); }
/** * Returns <code>true</code> if {@link TimeInterval} i1 intersects {@link TimeInterval} i2, <code> * false</code> otherwise (<code>null</code> border means infinity). */ public static boolean intersects(TimeInterval i1, TimeInterval i2) { if (i1 == null || i2 == null) return false; i1 = arrange(i1); i2 = arrange(i2); if (i1.getStart() == null && i1.getEnd() == null) { return true; } else if (i1.getStart() != null && i1.getEnd() == null) { if (i2.getEnd() == null) return true; else if (i2.getStart() == null && i2.getEnd() != null) return i1.contains(i2.getEnd()); else return i1.contains(i2.getEnd()) || i1.contains(i2.getStart()); } else if (i1.getStart() == null && i1.getEnd() != null) { if (i2.getStart() == null) return true; else if (i2.getStart() != null && i2.getEnd() == null) return i1.contains(i2.getStart()); else return i1.contains(i2.getEnd()) || i1.contains(i2.getStart()); } else { if (i2.getStart() == null && i2.getEnd() == null) return true; else if (i2.getStart() == null || i2.getEnd() == null) return i2.contains(i1.getEnd()) || i2.contains(i1.getStart()); else return i1.contains(i2.getStart()) || i1.contains(i2.getEnd()) || i2.contains(i1.getStart()) || i2.contains(i1.getEnd()); } }