shz.core.compute.ComputeParam Maven / Gradle / Ivy
package shz.core.compute;
import shz.core.ToMap;
import java.util.HashMap;
import java.util.Map;
@SuppressWarnings("unchecked")
public abstract class ComputeParam> {
final int capacity;
Map, R> data;
protected ComputeParam(int capacity) {
this.capacity = capacity;
}
protected ComputeParam() {
capacity = 0;
}
public final R compute(ComputeEnum e) {
if (data == null) {
if (capacity <= 0) data = new HashMap<>();
else data = ToMap.get(capacity).build();
}
R r = data.get(e);
if (r != null || data.containsKey(e)) return r;
r = e.compute((P) this);
data.put(e, r);
return r;
}
public final void clear() {
if (data != null) data.clear();
}
}