Follow these steps to implement the example:
- Create a class named Event and specify that it implements the Delayed interface:
public class Event implements Delayed {
- Declare a private Date attribute named startDate:
private final Date startDate;
- Implement the constructor of the class to initialize its attribute:
public Event (Date startDate) { this.startDate=startDate; }
- Implement the compareTo() method. It receives a Delayed object as its parameter. Return the difference between the delay of the current object and the one passed as a parameter:
@Override public int compareTo(Delayed o) { long result=this.getDelay(TimeUnit.NANOSECONDS)-o.getDelay (TimeUnit.NANOSECONDS); if (result<0) { return -1; } else ...