freemarker.cache.ConcurrentMapFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cookcc Show documentation
Show all versions of cookcc Show documentation
CookCC - a Lexer / Parser (LALR(1)) Project
package freemarker.cache;
import java.util.HashMap;
import java.util.Map;
import freemarker.template.utility.ClassUtil;
import freemarker.template.utility.UndeclaredThrowableException;
/**
* @author Attila Szegedi
* @version $Id: $
*/
class ConcurrentMapFactory
{
private static final Class mapClass = getMapClass();
private static final Class hashMapClass = getHashMapClass();
static Map createMap() {
try {
return (Map)hashMapClass.newInstance();
}
catch(Exception e) {
throw new UndeclaredThrowableException(e);
}
}
static boolean isConcurrent(Map map) {
return mapClass != null && mapClass.isInstance(map);
}
private static Class getMapClass() {
try {
return ClassUtil.forName("java.util.concurrent.ConcurrentMap");
}
catch(ClassNotFoundException e) {
return null;
}
}
private static Class getHashMapClass() {
try {
return ClassUtil.forName("java.util.concurrent.ConcurrentHashMap");
}
catch(ClassNotFoundException e) {
return HashMap.class;
}
}
}