@Test public void compareTo() { List<Time> times = new ArrayList<>(); times.add(new Time(12, 25)); times.add(new Time(10, 10)); times.add(new Time(11, 20)); times.add(new Time(10, 30)); Collections.sort(times); assertEquals(new Time(10, 10), times.get(0)); assertEquals(new Time(12, 25), times.get(3)); }
@Override public int compareTo(Time otherTime) { if (otherTime.getHour().equals(this.getHour())) { return this.getMinute().compareTo(otherTime.getMinute()); } return this.getHour().compareTo(otherTime.getHour()); }
Time implements Comparable<Time>, Serializable { @Override public int compareTo(Time otherTime) { if (otherTime.getHour().equals(this.getHour())) { return this.getMinute().compareTo(otherTime.getMinute()); } return this.getHour().compareTo(otherTime.getHour()); } }
Time implements Comparable<Time>, Serializable { @Override public int compareTo(Time otherTime) { if (otherTime.getHour().equals(this.getHour())) { return this.getMinute().compareTo(otherTime.getMinute()); } return this.getHour().compareTo(otherTime.getHour()); } Time();  Time(int hour, int minute);  Time(LocalTime localTime);  Time(String timeStr); }
Time implements Comparable<Time>, Serializable { @Override public int compareTo(Time otherTime) { if (otherTime.getHour().equals(this.getHour())) { return this.getMinute().compareTo(otherTime.getMinute()); } return this.getHour().compareTo(otherTime.getHour()); } Time();  Time(int hour, int minute);  Time(LocalTime localTime);  Time(String timeStr); String timeStr(); Integer getHour(); void setHour(Integer hour); Integer getMinute(); void setMinute(Integer minute); DateTime toDateTime(DateTime dateTime); DateTime toDateTime(LocalDate date); @Override int hashCode(); @Override boolean equals(Object obj); @Override String toString(); static Time parseTime(String time, String separator); @Override int compareTo(Time otherTime); boolean isBefore(Time other); boolean isAfter(Time other); boolean isBeforeOrEqual(Time other); boolean isAfterOrEqual(Time other); boolean isBetween(Time start, Time end); static Time valueOf(String str); }
Time implements Comparable<Time>, Serializable { @Override public int compareTo(Time otherTime) { if (otherTime.getHour().equals(this.getHour())) { return this.getMinute().compareTo(otherTime.getMinute()); } return this.getHour().compareTo(otherTime.getHour()); } Time();  Time(int hour, int minute);  Time(LocalTime localTime);  Time(String timeStr); String timeStr(); Integer getHour(); void setHour(Integer hour); Integer getMinute(); void setMinute(Integer minute); DateTime toDateTime(DateTime dateTime); DateTime toDateTime(LocalDate date); @Override int hashCode(); @Override boolean equals(Object obj); @Override String toString(); static Time parseTime(String time, String separator); @Override int compareTo(Time otherTime); boolean isBefore(Time other); boolean isAfter(Time other); boolean isBeforeOrEqual(Time other); boolean isAfterOrEqual(Time other); boolean isBetween(Time start, Time end); static Time valueOf(String str);  }