Search in sources :

Example 31 with WeakHashMap

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

the class AbstractMapTest method test_keySet.

/**
 * java.util.AbstractMap#keySet()
 */
public void test_keySet() {
    AbstractMap map1 = new HashMap(0);
    assertSame("HashMap(0)", map1.keySet(), map1.keySet());
    AbstractMap map2 = new HashMap(10);
    assertSame("HashMap(10)", map2.keySet(), map2.keySet());
    Map map3 = Collections.EMPTY_MAP;
    assertSame("EMPTY_MAP", map3.keySet(), map3.keySet());
    AbstractMap map4 = new IdentityHashMap(1);
    assertSame("IdentityHashMap", map4.keySet(), map4.keySet());
    AbstractMap map5 = new LinkedHashMap(122);
    assertSame("LinkedHashMap", map5.keySet(), map5.keySet());
    AbstractMap map6 = new TreeMap();
    assertSame("TreeMap", map6.keySet(), map6.keySet());
    AbstractMap map7 = new WeakHashMap();
    assertSame("WeakHashMap", map7.keySet(), map7.keySet());
}
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 32 with WeakHashMap

use of java.util.WeakHashMap in project hudson-2.x by hudson.

the class InstallerTranslator method getToolHome.

public String getToolHome(Node node, ToolInstallation tool, TaskListener log) throws IOException, InterruptedException {
    InstallSourceProperty isp = tool.getProperties().get(InstallSourceProperty.class);
    if (isp == null) {
        return null;
    }
    for (ToolInstaller installer : isp.installers) {
        if (installer.appliesTo(node)) {
            Map<ToolInstallation, Semaphore> mutexByTool = mutexByNode.get(node);
            if (mutexByTool == null) {
                mutexByNode.put(node, mutexByTool = new WeakHashMap<ToolInstallation, Semaphore>());
            }
            Semaphore semaphore = mutexByTool.get(tool);
            if (semaphore == null) {
                mutexByTool.put(tool, semaphore = new Semaphore(1));
            }
            semaphore.acquire();
            try {
                return installer.performInstallation(tool, node, log).getRemote();
            } finally {
                semaphore.release();
            }
        }
    }
    return null;
}
Also used : Semaphore(java.util.concurrent.Semaphore) WeakHashMap(java.util.WeakHashMap)

Example 33 with WeakHashMap

use of java.util.WeakHashMap in project guava by hceylan.

the class GcFinalizationTest method testAwaitDone_FinalizationPredicate.

public void testAwaitDone_FinalizationPredicate() {
    final WeakHashMap<Object, Object> map = new WeakHashMap<Object, Object>();
    map.put(new Object(), Boolean.TRUE);
    GcFinalization.awaitDone(new FinalizationPredicate() {

        public boolean isDone() {
            return map.isEmpty();
        }
    });
    assertTrue(map.isEmpty());
}
Also used : FinalizationPredicate(com.google.common.testing.GcFinalization.FinalizationPredicate) WeakHashMap(java.util.WeakHashMap)

Example 34 with WeakHashMap

use of java.util.WeakHashMap in project new-cloud by xie-summer.

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 = Maps.newHashMap();
    } else if (Hashtable.class == cl) {
        result = new Hashtable();
    } else if (IdentityHashMap.class == cl) {
        result = new IdentityHashMap();
    } else if (LinkedHashMap.class == cl) {
        result = Maps.newLinkedHashMap();
    } 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 = Maps.newConcurrentMap();
    } 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 = Maps.newHashMap();
    }
    return result;
}
Also used : ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) Hashtable(java.util.Hashtable) IdentityHashMap(java.util.IdentityHashMap) Properties(java.util.Properties) TreeMap(java.util.TreeMap) 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) InvocationTargetException(java.lang.reflect.InvocationTargetException) LinkedHashMap(java.util.LinkedHashMap) WeakHashMap(java.util.WeakHashMap)

Example 35 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();
    int size = src.size();
    Map result = null;
    if (HashMap.class == cl) {
        result = new HashMap(Math.max((int) (size / .75f) + 1, 16));
    } else if (Hashtable.class == cl) {
        result = new Hashtable(Math.max((int) (size / .75f) + 1, 16));
    } else if (IdentityHashMap.class == cl) {
        result = new IdentityHashMap((int) (1 + size * 1.1));
    } 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(Math.max((int) (size / .75f) + 1, 16));
    } else if (ConcurrentHashMap.class == cl) {
        result = new ConcurrentHashMap(Math.max((int) (size / .75f) + 1, 16));
    } 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>(Math.max((int) (size / .75f) + 1, 16));
    }
    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