@Test public void testCompareInvolvingNullTime() { Appt a1 = new Appt(LocalDate.of(2020,11,4), null, "Vote"); Appt a2 = new Appt(2020,11,4,9,00, "Vote"); assertTrue(a1.compareTo(a2) < 0); Appt b1 = new Appt(LocalDate.of(2020,11,4), null, "Vote"); Appt b2 = new Appt(LocalDate.of(2020,11,4), null, "Go Vote"); assertTrue(b1.compareTo(b2) > 0); }
@Override public int compareTo(Appt a2) { int dateComp = date.compareTo(a2.date); if (dateComp != 0) return dateComp; if (time != null && a2.time != null) { int timeComp = time.compareTo(a2.time); if (timeComp != 0) return timeComp; } else { if (time == null && a2.time != null) { return -1; } else if (time != null && a2.time == null) return +1; } return text.compareTo(a2.text); }
Appt implements Comparable<Appt> { @Override public int compareTo(Appt a2) { int dateComp = date.compareTo(a2.date); if (dateComp != 0) return dateComp; if (time != null && a2.time != null) { int timeComp = time.compareTo(a2.time); if (timeComp != 0) return timeComp; } else { if (time == null && a2.time != null) { return -1; } else if (time != null && a2.time == null) return +1; } return text.compareTo(a2.text); } }
Appt implements Comparable<Appt> { @Override public int compareTo(Appt a2) { int dateComp = date.compareTo(a2.date); if (dateComp != 0) return dateComp; if (time != null && a2.time != null) { int timeComp = time.compareTo(a2.time); if (timeComp != 0) return timeComp; } else { if (time == null && a2.time != null) { return -1; } else if (time != null && a2.time == null) return +1; } return text.compareTo(a2.text); } Appt(int y, int mo, int d, int h, int min, String text);  Appt(LocalDateTime datetime, String text);  Appt(LocalDate date, LocalTime time, String text); }
Appt implements Comparable<Appt> { @Override public int compareTo(Appt a2) { int dateComp = date.compareTo(a2.date); if (dateComp != 0) return dateComp; if (time != null && a2.time != null) { int timeComp = time.compareTo(a2.time); if (timeComp != 0) return timeComp; } else { if (time == null && a2.time != null) { return -1; } else if (time != null && a2.time == null) return +1; } return text.compareTo(a2.text); } Appt(int y, int mo, int d, int h, int min, String text);  Appt(LocalDateTime datetime, String text);  Appt(LocalDate date, LocalTime time, String text); void setRep(int typ, int intv, int count); boolean matches(int y, int m, int d); @Override int compareTo(Appt a2); @Override int hashCode(); @Override boolean equals(Object o2); @Override String toString(); static Appt fromString(String s); int getDay(); int getHour(); int getMinute(); int getMonth(); String getText(); int getYear(); }
Appt implements Comparable<Appt> { @Override public int compareTo(Appt a2) { int dateComp = date.compareTo(a2.date); if (dateComp != 0) return dateComp; if (time != null && a2.time != null) { int timeComp = time.compareTo(a2.time); if (timeComp != 0) return timeComp; } else { if (time == null && a2.time != null) { return -1; } else if (time != null && a2.time == null) return +1; } return text.compareTo(a2.text); } Appt(int y, int mo, int d, int h, int min, String text);  Appt(LocalDateTime datetime, String text);  Appt(LocalDate date, LocalTime time, String text); void setRep(int typ, int intv, int count); boolean matches(int y, int m, int d); @Override int compareTo(Appt a2); @Override int hashCode(); @Override boolean equals(Object o2); @Override String toString(); static Appt fromString(String s); int getDay(); int getHour(); int getMinute(); int getMonth(); String getText(); int getYear(); static final int NONE; static final int HOURLY; static final int DAILY; static final int WEEKLY; static final int MONTHLY_NUMDAY_OF_M; static final int MONTHLY_WEEKDAY_OF_M; static final int YEARLY; static final int FOREVER; }