use of java.util.WeakHashMap in project sling by apache.
the class ModelAdapterFactory method activate.
@Activate
protected void activate(final ComponentContext ctx) {
Dictionary<?, ?> props = ctx.getProperties();
final int maxRecursionDepth = PropertiesUtil.toInteger(props.get(PROP_MAX_RECURSION_DEPTH), DEFAULT_MAX_RECURSION_DEPTH);
this.invocationCountThreadLocal = new ThreadLocal<ThreadInvocationCounter>() {
@Override
protected ThreadInvocationCounter initialValue() {
return new ThreadInvocationCounter(maxRecursionDepth);
}
};
this.adapterCache = Collections.synchronizedMap(new WeakHashMap<Object, Map<Class, Object>>());
BundleContext bundleContext = ctx.getBundleContext();
this.queue = new ReferenceQueue<Object>();
this.disposalCallbacks = new ConcurrentHashMap<java.lang.ref.Reference<Object>, DisposalCallbackRegistryImpl>();
Hashtable<Object, Object> properties = new Hashtable<Object, Object>();
properties.put(Constants.SERVICE_VENDOR, "Apache Software Foundation");
properties.put(Constants.SERVICE_DESCRIPTION, "Sling Models OSGi Service Disposal Job");
properties.put("scheduler.name", "Sling Models OSGi Service Disposal Job");
properties.put("scheduler.concurrent", false);
properties.put("scheduler.period", PropertiesUtil.toLong(props.get(PROP_CLEANUP_JOB_PERIOD), DEFAULT_CLEANUP_JOB_PERIOD));
this.jobRegistration = bundleContext.registerService(Runnable.class.getName(), this, properties);
this.listener = new ModelPackageBundleListener(ctx.getBundleContext(), this, this.adapterImplementations, bindingsValuesProvidersByContext);
Hashtable<Object, Object> printerProps = new Hashtable<Object, Object>();
printerProps.put(Constants.SERVICE_VENDOR, "Apache Software Foundation");
printerProps.put(Constants.SERVICE_DESCRIPTION, "Sling Models Configuration Printer");
printerProps.put("felix.webconsole.label", "slingmodels");
printerProps.put("felix.webconsole.title", "Sling Models");
printerProps.put("felix.webconsole.configprinter.modes", "always");
this.configPrinterRegistration = bundleContext.registerService(Object.class.getName(), new ModelConfigurationPrinter(this, bundleContext, adapterImplementations), printerProps);
}
use of java.util.WeakHashMap in project checker-framework by typetools.
the class ColorModel method getGray16TosRGB8LUT.
/*
* Return a byte LUT that converts 16-bit gray values in the grayCS
* ColorSpace to the appropriate 8-bit sRGB value. I.e., if lut
* is the byte array returned by this method and sval = lut[gval],
* then the sRGB triple (sval,sval,sval) is the best match to gval.
* Cache references to any computed LUT in a Map.
*/
static byte[] getGray16TosRGB8LUT(ICC_ColorSpace grayCS) {
if (isLinearGRAYspace(grayCS)) {
return getLinearRGB16TosRGB8LUT();
}
if (g16Tos8Map != null) {
byte[] g16Tos8LUT = g16Tos8Map.get(grayCS);
if (g16Tos8LUT != null) {
return g16Tos8LUT;
}
}
short[] tmp = new short[65536];
for (int i = 0; i <= 65535; i++) {
tmp[i] = (short) i;
}
ColorTransform[] transformList = new ColorTransform[2];
PCMM mdl = CMSManager.getModule();
ICC_ColorSpace srgbCS = (ICC_ColorSpace) ColorSpace.getInstance(ColorSpace.CS_sRGB);
transformList[0] = mdl.createTransform(grayCS.getProfile(), ColorTransform.Any, ColorTransform.In);
transformList[1] = mdl.createTransform(srgbCS.getProfile(), ColorTransform.Any, ColorTransform.Out);
ColorTransform t = mdl.createTransform(transformList);
tmp = t.colorConvert(tmp, null);
byte[] g16Tos8LUT = new byte[65536];
for (int i = 0, j = 2; i <= 65535; i++, j += 3) {
// All three components of tmp should be equal, since
// the input color space to colorConvert is a gray scale
// space. However, there are slight anomalies in the results.
// Copy tmp starting at index 2, since colorConvert seems
// to be slightly more accurate for the third component!
// scale unsigned short (0 - 65535) to unsigned byte (0 - 255)
g16Tos8LUT[i] = (byte) (((float) (tmp[j] & 0xffff)) * (1.0f / 257.0f) + 0.5f);
}
if (g16Tos8Map == null) {
g16Tos8Map = Collections.synchronizedMap(new WeakHashMap<ICC_ColorSpace, byte[]>(2));
}
g16Tos8Map.put(grayCS, g16Tos8LUT);
return g16Tos8LUT;
}
use of java.util.WeakHashMap in project mybatis.flying by limeng32.
the class SqlBuilder method buildQueryMapper.
/**
* 由传入的dto对象的class构建TableMapper对象,构建好的对象存入缓存中,以后使用时直接从缓存中获取
*
* @param dtoClass
* @param pojoClass
* @return QueryMapper
*/
private static QueryMapper buildQueryMapper(Class<?> dtoClass, Class<?> pojoClass) {
QueryMapper queryMapper = queryMapperCache.get(dtoClass);
if (queryMapper != null) {
return queryMapper;
}
Map<String, ConditionMapper> conditionMapperCache = new WeakHashMap<>(16);
Map<String, OrMapper> orMapperCache = new WeakHashMap<>(4);
Field[] fields = null;
ConditionMapperAnnotation conditionMapperAnnotation = null;
ConditionMapper conditionMapper = null;
Or or = null;
OrMapper orMapper = null;
queryMapper = new QueryMapper();
fields = dtoClass.getDeclaredFields();
Annotation[] conditionAnnotations = null;
for (Field field : fields) {
conditionAnnotations = field.getDeclaredAnnotations();
if (conditionAnnotations.length == 0) {
continue;
}
for (Annotation an : conditionAnnotations) {
if (an instanceof ConditionMapperAnnotation) {
conditionMapperAnnotation = (ConditionMapperAnnotation) an;
conditionMapper = new ConditionMapper();
buildConditionMapper(conditionMapper, conditionMapperAnnotation, pojoClass, field);
conditionMapperCache.put(field.getName(), conditionMapper);
} else if (an instanceof Or) {
or = (Or) an;
orMapper = new OrMapper();
orMapper.setFieldName(field.getName());
ConditionMapper[] conditionMappers = new ConditionMapper[or.value().length];
int i = 0;
for (ConditionMapperAnnotation cma : or.value()) {
conditionMappers[i] = new ConditionMapper();
buildConditionMapper(conditionMappers[i], cma, pojoClass, field);
i++;
}
orMapper.setConditionMappers(conditionMappers);
orMapperCache.put(field.getName(), orMapper);
}
}
}
queryMapper.setConditionMapperCache(conditionMapperCache);
queryMapper.setOrMapperCache(orMapperCache);
queryMapperCache.put(dtoClass, queryMapper);
return queryMapper;
}
use of java.util.WeakHashMap in project Payara by payara.
the class DomainXmlVerifier method checkDuplicate.
private void checkDuplicate(Collection<? extends Dom> beans) {
if (beans == null || beans.size() <= 1) {
return;
}
WeakHashMap keyBeanMap = new WeakHashMap();
ArrayList<String> keys = new ArrayList<String>(beans.size());
for (Dom b : beans) {
String key = b.getKey();
keyBeanMap.put(key, b);
keys.add(key);
}
WeakHashMap<String, Class<ConfigBeanProxy>> errorKeyBeanMap = new WeakHashMap<String, Class<ConfigBeanProxy>>();
String[] strKeys = keys.toArray(new String[beans.size()]);
for (int i = 0; i < strKeys.length; i++) {
boolean foundDuplicate = false;
for (int j = i + 1; j < strKeys.length; j++) {
// we have a duplicate. So output that error
if ((strKeys[i].equals(strKeys[j]))) {
foundDuplicate = true;
errorKeyBeanMap.put(strKeys[i], ((Dom) keyBeanMap.get(strKeys[i])).getProxyType());
error = true;
break;
}
}
}
for (Map.Entry e : errorKeyBeanMap.entrySet()) {
Result result = new Result(strings.get("VerifyDupKey", e.getKey(), e.getValue()));
output(result);
}
}
use of java.util.WeakHashMap in project Slide by ccrama.
the class SubmissionCache method cacheInfo.
private static void cacheInfo(List<Submission> submissions, Context mContext, String baseSub) {
if (titles == null)
titles = new WeakHashMap<>();
if (info == null)
info = new WeakHashMap<>();
if (crosspost == null)
crosspost = new WeakHashMap<>();
for (Submission submission : submissions) {
titles.put(submission.getFullName(), getTitleSpannable(submission, mContext));
info.put(submission.getFullName(), getInfoSpannable(submission, mContext, baseSub));
crosspost.put(submission.getFullName(), getCrosspostLine(submission, mContext));
}
}
Aggregations