Search in sources :

Example 51 with WeakHashMap

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);
}
Also used : Reference(org.apache.felix.scr.annotations.Reference) PhantomReference(java.lang.ref.PhantomReference) Hashtable(java.util.Hashtable) ModelClass(org.apache.sling.models.impl.model.ModelClass) WeakHashMap(java.util.WeakHashMap) BundleContext(org.osgi.framework.BundleContext) Activate(org.apache.felix.scr.annotations.Activate)

Example 52 with WeakHashMap

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;
}
Also used : ColorTransform(sun.java2d.cmm.ColorTransform) ICC_ColorSpace(java.awt.color.ICC_ColorSpace) PCMM(sun.java2d.cmm.PCMM) WeakHashMap(java.util.WeakHashMap)

Example 53 with WeakHashMap

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;
}
Also used : Or(indi.mybatis.flying.annotations.Or) FieldMapperAnnotation(indi.mybatis.flying.annotations.FieldMapperAnnotation) Annotation(java.lang.annotation.Annotation) TableMapperAnnotation(indi.mybatis.flying.annotations.TableMapperAnnotation) ConditionMapperAnnotation(indi.mybatis.flying.annotations.ConditionMapperAnnotation) Field(java.lang.reflect.Field) ConditionMapper(indi.mybatis.flying.models.ConditionMapper) ConditionMapperAnnotation(indi.mybatis.flying.annotations.ConditionMapperAnnotation) OrMapper(indi.mybatis.flying.models.OrMapper) QueryMapper(indi.mybatis.flying.models.QueryMapper) WeakHashMap(java.util.WeakHashMap)

Example 54 with WeakHashMap

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);
    }
}
Also used : Dom(org.jvnet.hk2.config.Dom) ArrayList(java.util.ArrayList) Result(com.sun.enterprise.util.Result) ConfigBeanProxy(org.jvnet.hk2.config.ConfigBeanProxy) Map(java.util.Map) WeakHashMap(java.util.WeakHashMap) WeakHashMap(java.util.WeakHashMap)

Example 55 with WeakHashMap

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));
    }
}
Also used : Submission(net.dean.jraw.models.Submission) WeakHashMap(java.util.WeakHashMap)

Aggregations

WeakHashMap (java.util.WeakHashMap)65 Map (java.util.Map)19 HashMap (java.util.HashMap)18 TreeMap (java.util.TreeMap)15 IdentityHashMap (java.util.IdentityHashMap)13 AbstractMap (java.util.AbstractMap)12 LinkedHashMap (java.util.LinkedHashMap)12 ICC_ColorSpace (java.awt.color.ICC_ColorSpace)8 ColorTransform (sun.java2d.cmm.ColorTransform)8 PCMM (sun.java2d.cmm.PCMM)8 Hashtable (java.util.Hashtable)6 AttributedString (java.text.AttributedString)5 Properties (java.util.Properties)5 ArrayList (java.util.ArrayList)4 Comparator (java.util.Comparator)4 List (java.util.List)4 TreeSet (java.util.TreeSet)4 WeakReference (java.lang.ref.WeakReference)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 AttributedCharacterIterator (java.text.AttributedCharacterIterator)3