All Downloads are FREE. Search and download functionalities are using the official Maven repository.

shz.core.compute.ComputeParam Maven / Gradle / Ivy

There is a newer version: 2024.0.2
Show newest version
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();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy