I have a Meeting class that implements Comparable<Meeting>. Overridden compareTo method will compare meetingDate of two Meeting objects first and in case they are equal it will compare their meetingTime. I want to put all my Meeting objects in a ProirtiyQueue<Meeting> so I can retrieve the upcoming meetings as per their meetingDate and meetingTime. Data type used are java.time.LocalDate and java.time.LocalTime respectively. How can I compare meetingDate and meetingTime in my compareTo(Meeting o) method.
public class Meeting implements Comparable<Meeting> {
private String title;
private String desciption;
private LocalDate meetingDate;
private LocalTime meetingTime;
public Meeting(String title, String description, LocalDate meetingDate, LocalTime meetingTime) {
this.title = title;
this.desciption = description;
this.meetingDate = meetingDate;
this.meetingTime = meetingTime;
}
public String getTittle() {
return title;
}
public void setTittle(String title) {
this.title = title;
}
public String getDescription() {
return desciption;
}
public void setDescription(String description) {
this.desciption = description;
}
public LocalDate getMeetingDate() {
return meetingDate;
}
public void setMeetingDate(LocalDate meetingDate) {
this.meetingDate = meetingDate;
}
public LocalTime getMeetingTime() {
return meetingTime;
}
public void setMeetingTime(LocalTime meetingTime) {
this.meetingTime = meetingTime;
}
public int compareTo(Meeting o) {
// comparison
}
}
You can delegate the implementation of
compareToto aComparatorwhich can chain comparisons of multiple properties of the given Meeting: