Skip to content

Instantly share code, notes, and snippets.

@moaikids
Created June 21, 2012 11:56
Show Gist options
  • Save moaikids/2965360 to your computer and use it in GitHub Desktop.
Save moaikids/2965360 to your computer and use it in GitHub Desktop.
Event
import lombok.Getter;
public class Event implements Comparable<Event> {
@Getter
private volatile Runnable runnable;
@Getter
private final long time;
@Getter
private boolean canceled = false;
@Getter
private boolean done = false;
public Event(Runnable runnable, long time) {
this.runnable = runnable;
this.time = time;
this.canceled = false;
this.done = false;
}
public void cancel() {
runnable = null;
canceled = true;
}
public void run() {
Runnable call = runnable;
if (call != null && !done) {
call.run();
done = true;
}
}
@Override
public int compareTo(Event o) {
long diff = time - o.time;
if (diff == 0L) {
return 0;
}
return diff > 0L ? 1 : 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment