Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package org.jboss.weld.bootstrap.api.helpers;
 
 import java.util.Map;
 

Author(s):
mathieuancelin
    public static final String STATIC_INSTANCE = "STATIC_INSTANCE";
    @Override
    public <T> Singleton<T> create(Class<? extends T> type) {
        return new RegistrySingleton<T>();
    }
    private static class RegistrySingleton<T> implements Singleton<T> {
        private final Map<String, T> store = new ConcurrentHashMap<String, T>();
        public T get(String id) {
            T instance = .get(id);
            if (instance == null) {
                throw new IllegalStateException("Singleton not set for " + id + " => " + .keySet());
            }
            return instance;
        }
        public void set(String id, T object) {
            .put(idobject);
        }
        public void clear(String id) {
            .remove(id);
        }
        public boolean isSet(String id) {
            return .containsKey(id);
        }
    }
New to GrepCode? Check out our FAQ X