refactor: remove old Data API

This commit is contained in:
TopchetoEU 2023-12-27 14:21:52 +02:00
parent aaf9a6fa45
commit 9ea5cd9277
Signed by: topchetoeu
GPG Key ID: 6531B8583E5F6ED4
2 changed files with 0 additions and 59 deletions

View File

@ -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);
}
}

View File

@ -1,3 +0,0 @@
package me.topchetoeu.jscript.engine;
public class DataKey<T> { }