### Question:
SimpleTimePeriod implements TimePeriod, Comparable<TimePeriod>, Serializable { @Override public int compareTo(TimePeriod that) { long t0 = getStart().getTime(); long t1 = getEnd().getTime(); long m0 = t0 + (t1 - t0) / 2L; long t2 = that.getStart().getTime(); long t3 = that.getEnd().getTime(); long m1 = t2 + (t3 - t2) / 2L; if (m0 < m1) { return -1; } else if (m0 > m1) { return 1; } else { if (t0 < t2) { return -1; } else if (t0 > t2) { return 1; } else { if (t1 < t3) { return -1; } else if (t1 > t3) { return 1; } else { return 0; } } } } SimpleTimePeriod(long start, long end);  SimpleTimePeriod(Date start, Date end); @Override Date getStart(); long getStartMillis(); @Override Date getEnd(); long getEndMillis(); @Override boolean equals(Object obj); @Override int compareTo(TimePeriod that); @Override int hashCode();  }### Answer:
@Test public void testCompareTo() { SimpleTimePeriod s1 = new SimpleTimePeriod(new Date(10L), new Date(20L)); SimpleTimePeriod s2 = new SimpleTimePeriod(new Date(10L), new Date(20L)); assertEquals(0, s1.compareTo(s2)); s1 = new SimpleTimePeriod(new Date(9L), new Date(21L)); s2 = new SimpleTimePeriod(new Date(10L), new Date(20L)); assertEquals(-1, s1.compareTo(s2)); s1 = new SimpleTimePeriod(new Date(11L), new Date(19L)); s2 = new SimpleTimePeriod(new Date(10L), new Date(20L)); assertEquals(1, s1.compareTo(s2)); s1 = new SimpleTimePeriod(new Date(9L), new Date(19L)); s2 = new SimpleTimePeriod(new Date(10L), new Date(20L)); assertEquals(-1, s1.compareTo(s2)); s1 = new SimpleTimePeriod(new Date(11L), new Date(21)); s2 = new SimpleTimePeriod(new Date(10L), new Date(20L)); assertEquals(1, s1.compareTo(s2)); s1 = new SimpleTimePeriod(new Date(10L), new Date(18)); s2 = new SimpleTimePeriod(new Date(10L), new Date(20L)); assertEquals(-1, s1.compareTo(s2)); s1 = new SimpleTimePeriod(new Date(10L), new Date(22)); s2 = new SimpleTimePeriod(new Date(10L), new Date(20L)); assertEquals(1, s1.compareTo(s2)); }