Created
June 21, 2012 11:56
-
-
Save moaikids/2965360 to your computer and use it in GitHub Desktop.
Event
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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