Search in sources :

Example 16 with WeakHashMap

use of java.util.WeakHashMap in project j2objc by google.

the class AbstractMapTest method test_values.

/**
     * java.util.AbstractMap#values()
     */
public void test_values() {
    AbstractMap map1 = new HashMap(0);
    assertSame("HashMap(0)", map1.values(), map1.values());
    AbstractMap map2 = new HashMap(10);
    assertSame("HashMap(10)", map2.values(), map2.values());
    Map map3 = Collections.EMPTY_MAP;
    assertSame("EMPTY_MAP", map3.values(), map3.values());
    AbstractMap map4 = new IdentityHashMap(1);
    assertSame("IdentityHashMap", map4.values(), map4.values());
    AbstractMap map5 = new LinkedHashMap(122);
    assertSame("IdentityHashMap", map5.values(), map5.values());
    AbstractMap map6 = new TreeMap();
    assertSame("TreeMap", map6.values(), map6.values());
    AbstractMap map7 = new WeakHashMap();
    assertSame("WeakHashMap", map7.values(), map7.values());
}
Also used : AbstractMap(java.util.AbstractMap) IdentityHashMap(java.util.IdentityHashMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) WeakHashMap(java.util.WeakHashMap) IdentityHashMap(java.util.IdentityHashMap) TreeMap(java.util.TreeMap) IdentityHashMap(java.util.IdentityHashMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) AbstractMap(java.util.AbstractMap) TreeMap(java.util.TreeMap) Map(java.util.Map) WeakHashMap(java.util.WeakHashMap) LinkedHashMap(java.util.LinkedHashMap) WeakHashMap(java.util.WeakHashMap)

Example 17 with WeakHashMap

use of java.util.WeakHashMap in project felix by apache.

the class Conditions method getConditions.

public Conditions getConditions(BundleRevisionImpl key, ConditionInfo[] conditions) {
    Conditions result = null;
    Map index = null;
    synchronized (m_cache) {
        index = (Map) m_cache.get(conditions);
        if (index == null) {
            index = new WeakHashMap();
            m_cache.put(conditions, index);
        }
    }
    synchronized (index) {
        if (key != null) {
            result = (Conditions) index.get(key);
        }
    }
    if (result == null) {
        result = new Conditions(key, conditions, m_action);
        synchronized (index) {
            index.put(key, result);
        }
    }
    return result;
}
Also used : HashMap(java.util.HashMap) Map(java.util.Map) WeakHashMap(java.util.WeakHashMap) WeakHashMap(java.util.WeakHashMap)

Example 18 with WeakHashMap

use of java.util.WeakHashMap in project jdk8u_jdk by JetBrains.

the class ColorModel method getLinearGray16ToOtherGray16LUT.

/*
     * Return a short LUT that converts 16-bit gray values in the CS_GRAY
     * linear gray ColorSpace to the appropriate 16-bit value in the
     * grayCS ColorSpace.  Cache references to any computed LUT in a Map.
     */
static short[] getLinearGray16ToOtherGray16LUT(ICC_ColorSpace grayCS) {
    if (lg16Toog16Map != null) {
        short[] lg16Toog16LUT = lg16Toog16Map.get(grayCS);
        if (lg16Toog16LUT != null) {
            return lg16Toog16LUT;
        }
    }
    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 lgCS = (ICC_ColorSpace) ColorSpace.getInstance(ColorSpace.CS_GRAY);
    transformList[0] = mdl.createTransform(lgCS.getProfile(), ColorTransform.Any, ColorTransform.In);
    transformList[1] = mdl.createTransform(grayCS.getProfile(), ColorTransform.Any, ColorTransform.Out);
    ColorTransform t = mdl.createTransform(transformList);
    short[] lg16Toog16LUT = t.colorConvert(tmp, null);
    if (lg16Toog16Map == null) {
        lg16Toog16Map = Collections.synchronizedMap(new WeakHashMap<ICC_ColorSpace, short[]>(2));
    }
    lg16Toog16Map.put(grayCS, lg16Toog16LUT);
    return lg16Toog16LUT;
}
Also used : ColorTransform(sun.java2d.cmm.ColorTransform) ICC_ColorSpace(java.awt.color.ICC_ColorSpace) PCMM(sun.java2d.cmm.PCMM) WeakHashMap(java.util.WeakHashMap)

Example 19 with WeakHashMap

use of java.util.WeakHashMap in project jdk8u_jdk by JetBrains.

the class ColorModel method getGray8TosRGB8LUT.

/*
     * Return a byte LUT that converts 8-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[] getGray8TosRGB8LUT(ICC_ColorSpace grayCS) {
    if (isLinearGRAYspace(grayCS)) {
        return getLinearRGB8TosRGB8LUT();
    }
    if (g8Tos8Map != null) {
        byte[] g8Tos8LUT = g8Tos8Map.get(grayCS);
        if (g8Tos8LUT != null) {
            return g8Tos8LUT;
        }
    }
    byte[] g8Tos8LUT = new byte[256];
    for (int i = 0; i <= 255; i++) {
        g8Tos8LUT[i] = (byte) 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);
    byte[] tmp = t.colorConvert(g8Tos8LUT, null);
    for (int i = 0, j = 2; i <= 255; 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!
        g8Tos8LUT[i] = tmp[j];
    }
    if (g8Tos8Map == null) {
        g8Tos8Map = Collections.synchronizedMap(new WeakHashMap<ICC_ColorSpace, byte[]>(2));
    }
    g8Tos8Map.put(grayCS, g8Tos8LUT);
    return g8Tos8LUT;
}
Also used : ColorTransform(sun.java2d.cmm.ColorTransform) ICC_ColorSpace(java.awt.color.ICC_ColorSpace) PCMM(sun.java2d.cmm.PCMM) WeakHashMap(java.util.WeakHashMap)

Example 20 with WeakHashMap

use of java.util.WeakHashMap in project dubbo by alibaba.

the class PojoUtils method createMap.

private static Map createMap(Map src) {
    Class<? extends Map> cl = src.getClass();
    Map result = null;
    if (HashMap.class == cl) {
        result = new HashMap();
    } else if (Hashtable.class == cl) {
        result = new Hashtable();
    } else if (IdentityHashMap.class == cl) {
        result = new IdentityHashMap();
    } else if (LinkedHashMap.class == cl) {
        result = new LinkedHashMap();
    } else if (Properties.class == cl) {
        result = new Properties();
    } else if (TreeMap.class == cl) {
        result = new TreeMap();
    } else if (WeakHashMap.class == cl) {
        return new WeakHashMap();
    } else if (ConcurrentHashMap.class == cl) {
        result = new ConcurrentHashMap();
    } else if (ConcurrentSkipListMap.class == cl) {
        result = new ConcurrentSkipListMap();
    } else {
        try {
            result = cl.newInstance();
        } catch (Exception e) {
        /* ignore */
        }
        if (result == null) {
            try {
                Constructor<?> constructor = cl.getConstructor(Map.class);
                result = (Map) constructor.newInstance(Collections.EMPTY_MAP);
            } catch (Exception e) {
            /* ignore */
            }
        }
    }
    if (result == null) {
        result = new HashMap<Object, Object>();
    }
    return result;
}
Also used : ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) WeakHashMap(java.util.WeakHashMap) IdentityHashMap(java.util.IdentityHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Hashtable(java.util.Hashtable) IdentityHashMap(java.util.IdentityHashMap) Properties(java.util.Properties) TreeMap(java.util.TreeMap) InvocationTargetException(java.lang.reflect.InvocationTargetException) LinkedHashMap(java.util.LinkedHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) WeakHashMap(java.util.WeakHashMap) IdentityHashMap(java.util.IdentityHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) TreeMap(java.util.TreeMap) 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