Skip to content

Instantly share code, notes, and snippets.

@mattmess1221
Created August 15, 2015 07:25
Show Gist options
  • Save mattmess1221/9a05c08883afcfb9be00 to your computer and use it in GitHub Desktop.
Save mattmess1221/9a05c08883afcfb9be00 to your computer and use it in GitHub Desktop.
public class BoolTimer {
private final long expire;
private boolean b;
private long time;
public BoolTimer(long expire) {
if (expire < 0) throw new IllegalArgumentException("Expiration cannot be negative");
this.expire = expire;
}
public boolean get() {
if (b && System.currentTimeMillis() - time > expire) {
b = false;
}
return b;
}
public void set() {
b = true;
time = System.currentTimeMillis();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment