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());
}
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;
}
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());
}
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;
}
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;
}
Aggregations