refactor: remove old Data API
This commit is contained in:
parent
aaf9a6fa45
commit
9ea5cd9277
@ -1,56 +0,0 @@
|
|||||||
package me.topchetoeu.jscript.engine;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public class Data {
|
|
||||||
private HashMap<DataKey<Object>, Object> data = new HashMap<>();
|
|
||||||
|
|
||||||
public Data copy() {
|
|
||||||
return new Data().addAll(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Data addAll(Map<DataKey<?>, ?> data) {
|
|
||||||
for (var el : data.entrySet()) {
|
|
||||||
get((DataKey<Object>)el.getKey(), (Object)el.getValue());
|
|
||||||
}
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
public Data addAll(Data data) {
|
|
||||||
for (var el : data.data.entrySet()) {
|
|
||||||
get((DataKey<Object>)el.getKey(), (Object)el.getValue());
|
|
||||||
}
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public <T> T remove(DataKey<T> key) {
|
|
||||||
return (T)data.remove(key);
|
|
||||||
}
|
|
||||||
public <T> Data set(DataKey<T> key, T val) {
|
|
||||||
data.put((DataKey<Object>)key, (Object)val);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
public <T> T get(DataKey<T> key, T val) {
|
|
||||||
if (data.containsKey(key)) return (T)data.get((DataKey<Object>)key);
|
|
||||||
set(key, val);
|
|
||||||
return val;
|
|
||||||
}
|
|
||||||
public <T> T get(DataKey<T> key) {
|
|
||||||
if (data.containsKey(key)) return (T)data.get((DataKey<Object>)key);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
public boolean has(DataKey<?> key) { return data.containsKey(key); }
|
|
||||||
|
|
||||||
public int increase(DataKey<Integer> key, int n, int start) {
|
|
||||||
int res;
|
|
||||||
set(key, res = get(key, start) + n);
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
public int increase(DataKey<Integer> key, int n) {
|
|
||||||
return increase(key, n, 0);
|
|
||||||
}
|
|
||||||
public int increase(DataKey<Integer> key) {
|
|
||||||
return increase(key, 1, 0);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,3 +0,0 @@
|
|||||||
package me.topchetoeu.jscript.engine;
|
|
||||||
|
|
||||||
public class DataKey<T> { }
|
|
Loading…
Reference in New Issue
Block a user