Created
August 15, 2015 07:25
-
-
Save mattmess1221/9a05c08883afcfb9be00 to your computer and use it in GitHub Desktop.
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
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