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

io.descoped.dc.api.services.InstanceCache Maven / Gradle / Ivy

The newest version!
package io.descoped.dc.api.services;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class InstanceCache {

    private final Map, Object> cache = new ConcurrentHashMap();

    public  R add(Class clazz, R instance) {
        cache.put(clazz, instance);
        return instance;
    }

    public boolean has(Class clazz) {
        return cache.containsKey(clazz);
    }

    public  R get(Class clazz) {
        return (R) cache.get(clazz);
    }

    private static class InstanceCacheHolder {
        private static final InstanceCache INSTANCE = new InstanceCache();
    }

    public static InstanceCache instance() {
        return InstanceCacheHolder.INSTANCE;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy