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

org.onetwo.common.reflect.ClassIntroManager Maven / Gradle / Ivy

There is a newer version: 4.7.2
Show newest version
package org.onetwo.common.reflect;

import java.util.Map;
import java.util.WeakHashMap;

import org.onetwo.common.utils.StringUtils;

public class ClassIntroManager {

	private static final ClassIntroManager introManager = new ClassIntroManager();
	
	public static ClassIntroManager getInstance() {
		return introManager;
	}
	
	private Map, Intro> introMaps = new WeakHashMap, Intro>(500);
	private Object lock = new Object();

	@SuppressWarnings("unchecked")
	public  Intro getIntro(Class clazz){
		if(clazz==null)
			return null;
		Intro intro = (Intro)introMaps.get(clazz);
		if(intro==null){
			synchronized (lock) {
				intro = (Intro)introMaps.get(clazz);
				if(intro==null){
					intro = Intro.wrap(clazz);
					introMaps.put(clazz, intro);
				}
			}
		}
		return intro;
	}

	public Intro getIntro(String className){
		if(StringUtils.isBlank(className))
			return null;
		Class clazz = ReflectUtils.loadClass(className);
		return getIntro(clazz);
	}

	
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy