-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathICooldown.java
More file actions
65 lines (56 loc) · 2.12 KB
/
ICooldown.java
File metadata and controls
65 lines (56 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package com.cosimo.utilities.timed;
import lombok.NonNull;
import java.util.concurrent.TimeUnit;
public interface ICooldown extends TimeStandard {
/**
* Returns whether this cooldown is expired.
*
* @return Whether this cooldown is expired
*/
default boolean isExpired() {
return this.getExpiration() <= this.getCurrentTime();
}
/**
* Returns how much time is left until the end of this cooldown, expressed in a given {@link TimeUnit}, minimally
* zero.
*
* @param unit {@link TimeUnit} in which the remaining milliseconds should be converted to
* @return The remaining cooldown time that can't be negative, expressed as a long in the given {@link TimeUnit}
*/
default long getRemaining(@NonNull TimeUnit unit) {
return Math.max(0, this.getDifference(unit));
}
/**
* Returns the timestamp difference between current one and the end of this cooldown, minimally zero, which would
* indicate it has already expired.
*
* @return Remaining time that can't be negative
*/
default long getRemaining() {
return Math.max(0, this.getDifference());
}
/**
* Returns the timestamp difference between current one and the end of this cooldown, expressed in a given
* {@link TimeUnit}.
*
* @param unit {@link TimeUnit} in which the remaining milliseconds should be converted to
* @return The remaining cooldown time, expressed as a long in the given {@link TimeUnit}
*/
default long getDifference(@NonNull TimeUnit unit) {
return this.fromThisTime(this.getDifference(), unit);
}
/**
* Returns how much time is left until the end of this cooldown, even negative if it has already expired.
*
* @return Remaining time of any mathematical sign
*/
default long getDifference() {
return this.getExpiration() - this.getCurrentTime();
}
/**
* Returns the {@link TimeStandard}-wise time at which this cooldown should expire.
*
* @return {@link #getCurrentTime()} time at which this cooldown should expire
*/
long getExpiration();
}