-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathImmutableCooldown.java
More file actions
46 lines (39 loc) · 1.39 KB
/
ImmutableCooldown.java
File metadata and controls
46 lines (39 loc) · 1.39 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
package com.cosimo.utilities.timed;
import lombok.NonNull;
import java.util.concurrent.TimeUnit;
/**
* Immutable implementation for tracking cooldown expiration only.
*/
@SuppressWarnings("unused")
public class ImmutableCooldown implements ICooldown {
/**
* Timestamp of when the {@link ImmutableCooldown} will end.
*/
private final long end;
/**
* Creates a new {@link ImmutableCooldown} from a given duration expressed in the given {@link TimeUnit}.
*
* @param duration For how long this cooldown will last
* @param unit {@link TimeUnit} of the given cooldown duration parameter
* @see ImmutableCooldown Duration unit conversion to milliseconds
*/
public ImmutableCooldown(long duration, @NonNull TimeUnit unit) {
this.end = this.getCurrentTime() + this.toThisTime(duration, unit);
}
/**
* Creates a new {@link ImmutableCooldown} from a given duration expressed in milliseconds.
*
* @param duration For how long this cooldown will last in milliseconds
*/
public ImmutableCooldown(long duration) {
this.end = this.getCurrentTime() + duration;
}
/**
* Returns the {@link #getCurrentTime()} time at which this cooldown should expire.
*
* @return {@link #getCurrentTime()} time at which this cooldown should expire
*/
public long getExpiration() {
return this.end;
}
}