📄 taskoptimizer.java
字号:
import java.util.Date;
public class TaskOptimizer {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
}
private int max;
private int min;
private long timeout; // time to restart optimizing
private Date timer; // times sleeping
private boolean action; // true for optimizing. false for sleeping.
private boolean taskStarted; //ensure that no more than the 1st trigger affects its action
private int optValue;
public TaskOptimizer(int max, int min, long timeout, int startValue) {
this.max = max;
this.min = min;
this.timeout = timeout;
this.optValue = startValue;
//switch2Sleep();
switch2Action();
}
public void taskStart() {
this.taskStarted = true;
}
public void reportTask(boolean result) {
if (checkAction() || !result)
optimize(result);
if (checkAction() && !result) {
switch2Sleep();
}
}
private void switch2Sleep() {
action = false;
timer = new Date();
}
private void switch2Action() {
action = true;
//timer = new Date();
}
private void optimize(boolean result) {
if (taskStarted) {
taskStarted = false;
optValue = result ? optValue + 1 : optValue - 1;
optValue = (optValue < min) ? min : optValue;
optValue = (optValue > min) ? max : optValue;
}
}
private boolean checkAction() {
if (!action) // sleeping check if sleep timeout
if ((new Date().getTime() - timer.getTime()) > timeout * 1000) {
action = true;
}
return action;
}
public int getValue() {
return optValue;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -