/
EzyActionFrame.java
50 lines (38 loc) · 1.22 KB
/
EzyActionFrame.java
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
package com.tvd12.ezyfox.monitor.frame;
import lombok.Getter;
import java.text.SimpleDateFormat;
@Getter
public abstract class EzyActionFrame {
protected final long endTime;
protected final long startTime;
protected final long maxActions;
protected volatile long actions;
public EzyActionFrame(long maxActions) {
this(maxActions, System.currentTimeMillis());
}
public EzyActionFrame(long maxActions, long startTime) {
this.maxActions = maxActions;
this.startTime = startTime;
this.endTime = startTime + getExistsTime();
}
protected abstract int getExistsTime();
public boolean addActions(long actions) {
return (this.actions += actions) > maxActions;
}
public boolean isExpired() {
return System.currentTimeMillis() > endTime;
}
public boolean isInvalid() {
return actions > maxActions;
}
public abstract EzyActionFrame nextFrame();
@Override
public String toString() {
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss.SSS");
return getClass().getSimpleName() +
": " +
df.format(startTime) +
" -> " +
df.format(endTime);
}
}