2019-05-02 11:31:40 +00:00
|
|
|
package io.github.chronosx88.GunJava;
|
|
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Random;
|
2019-05-03 16:52:05 +00:00
|
|
|
import java.util.UUID;
|
2019-05-02 11:31:40 +00:00
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
|
|
|
|
|
public class Dup {
|
2019-05-03 16:52:05 +00:00
|
|
|
private static char[] randomSeed = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".toCharArray();
|
2019-05-02 11:31:40 +00:00
|
|
|
private static Random random = new Random(System.currentTimeMillis());
|
|
|
|
private Map<String, Long> s = new ConcurrentHashMap<>();
|
|
|
|
private DupOpt opt = new DupOpt();
|
|
|
|
private Thread to = null;
|
|
|
|
|
|
|
|
public Dup() {
|
|
|
|
opt.max = 1000;
|
|
|
|
opt.age = 1000 * 9;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String track(String id) {
|
|
|
|
s.put(id, System.currentTimeMillis());
|
|
|
|
if(to == null) {
|
|
|
|
Utils.setTimeout(() -> {
|
|
|
|
for(Map.Entry<String, Long> entry : s.entrySet()) {
|
|
|
|
if(opt.age > (System.currentTimeMillis() - entry.getValue()))
|
|
|
|
continue;
|
|
|
|
s.remove(entry.getKey());
|
|
|
|
}
|
|
|
|
to = null;
|
|
|
|
}, opt.age);
|
|
|
|
}
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean check(String id) {
|
|
|
|
if(s.containsKey(id)) {
|
|
|
|
track(id);
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-03 16:52:05 +00:00
|
|
|
public static String random() {
|
|
|
|
return UUID.randomUUID().toString();
|
2019-05-02 11:31:40 +00:00
|
|
|
}
|
|
|
|
}
|