use of java.util.WeakHashMap in project j2objc by google.
the class RetainedWithTest method testMapChildren.
public void testMapChildren() {
runMapTest(new MapFactory(new Object()) {
public Map newMap() {
return new IdentityHashMap();
}
});
runMapTest(new MapFactory(new Object()) {
public Map newMap() {
return new WeakHashMap();
}
});
runMapTest(new MapFactory(Color.RED) {
public Map newMap() {
return new EnumMap(Color.class);
}
});
runMapTest(new MapFactory(new Object()) {
public Map newMap() {
return new HashMap();
}
});
runMapTest(new MapFactory(5) {
public Map newMap() {
return new TreeMap();
}
});
runMapTest(new MapFactory(new Object()) {
public Map newMap() {
return new Hashtable();
}
});
runMapTest(new MapFactory(new Object()) {
public Map newMap() {
return new ConcurrentHashMap();
}
});
}
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 atlas by alibaba.
the class AndroidHack method injectResources.
// public static void injectApplication(String packageName, Application application) throws Exception {
// Object activityThread = getActivityThread();
// if (activityThread == null) {
// throw new Exception("Failed to get ActivityThread.sCurrentActivityThread");
// }
//
// Object loadedApk = getLoadedApk(application,activityThread, application.getPackageName());
// if (loadedApk == null) {
// throw new Exception("Failed to get ActivityThread.mLoadedApk");
// }
//
//// try{
//// Field field = activityThread.getClass().getDeclaredField("mAllApplications");
//// field.setAccessible(true);
//// ArrayList<Application> mAllApplications = (ArrayList<Application>)field.get(activityThread);
//// mAllApplications.add(RuntimeVariables.androidApplication);
//// }catch(Throwable e){}
// AtlasHacks.LoadedApk_mApplication.set(loadedApk,application);
// AtlasHacks.ActivityThread_mInitialApplication.set(activityThread,application);
// }
public static void injectResources(Application application, Resources resources) throws Exception {
Object activityThread = getActivityThread();
if (activityThread == null) {
throw new Exception("Failed to get ActivityThread.sCurrentActivityThread");
}
Object loadedApk = getLoadedApk(application, activityThread, application.getPackageName());
if (loadedApk == null) {
loadedApk = createNewLoadedApk(application, activityThread);
if (loadedApk == null) {
throw new RuntimeException(" Failed to get ActivityThread.mLoadedApk");
}
ClassLoader classLoader = AtlasHacks.LoadedApk_mClassLoader.get(loadedApk);
if (!(classLoader instanceof DelegateClassLoader)) {
AtlasHacks.LoadedApk_mClassLoader.set(loadedApk, RuntimeVariables.delegateClassLoader);
}
}
//AtlasHacks.LoadedApk_mResources.on(loadedApk).set(resources);
AtlasHacks.LoadedApk_mResources.set(loadedApk, resources);
//AtlasHacks.ContextImpl_mResources.on(application.getBaseContext()).set(resources);
AtlasHacks.ContextImpl_mResources.set(application.getBaseContext(), resources);
//AtlasHacks.ContextImpl_mTheme.on(application.getBaseContext()).set(null);
AtlasHacks.ContextImpl_mTheme.set(application.getBaseContext(), null);
try {
Collection<WeakReference<Resources>> references = null;
if (Build.VERSION.SDK_INT <= 18) {
HashMap<?, WeakReference<Resources>> map = (HashMap<?, WeakReference<Resources>>) sActiveResourcesField.get(activityThread);
references = map.values();
} else if (Build.VERSION.SDK_INT < 24) {
Object sResourcesManager = sgetInstanceMethod.invoke(sResourcesManagerClazz);
ArrayMap<?, WeakReference<Resources>> activeResources = (ArrayMap<?, WeakReference<Resources>>) sActiveResourcesField.get(sResourcesManager);
references = activeResources.values();
}
if (Build.VERSION.SDK_INT < 24) {
for (WeakReference<Resources> wr : references) {
Resources res = wr.get();
if (res != null) {
sAssetsField.set(res, resources.getAssets());
res.updateConfiguration(resources.getConfiguration(), resources.getDisplayMetrics());
}
}
}
// if(Build.VERSION.SDK_INT>=24){
// Object sResourcesManager = sgetInstanceMethod.invoke(sResourcesManagerClazz);
// WeakHashMap<IBinder, Object> activityResourceReferences ;
// activityResourceReferences= (WeakHashMap<IBinder, Object> )sActiveResourcesField.get(sResourcesManager);
// Collection<Object> mActivityResourcesReferences = activityResourceReferences.values();
// if(mActivityResourcesReferences!=null){
// for(Object activityResourceReference : mActivityResourcesReferences){
// ArrayList<WeakReference<Resources>> resList= (ArrayList<WeakReference<Resources>>)activityResourceReference.getClass().getDeclaredField("activityResources")
// .get(activityResourceReference);
// if(resList!=null){
// for(WeakReference<Resources> ref : resList){
//
// }
// }
// }
// }
//
//
// }
} catch (Throwable e) {
e.printStackTrace();
}
}
use of java.util.WeakHashMap in project robovm by robovm.
the class AbstractMapTest method test_removeLjava_lang_Object.
/**
* java.util.AbstractMap#remove(java.lang.Object)
*/
public void test_removeLjava_lang_Object() {
Object key = new Object();
Object value = new Object();
AbstractMap map1 = new HashMap(0);
map1.put("key", value);
assertSame("HashMap(0)", map1.remove("key"), value);
AbstractMap map4 = new IdentityHashMap(1);
map4.put(key, value);
assertSame("IdentityHashMap", map4.remove(key), value);
AbstractMap map5 = new LinkedHashMap(122);
map5.put(key, value);
assertSame("LinkedHashMap", map5.remove(key), value);
AbstractMap map6 = new TreeMap(new Comparator() {
// Bogus comparator
public int compare(Object object1, Object object2) {
return 0;
}
});
map6.put(key, value);
assertSame("TreeMap", map6.remove(key), value);
AbstractMap map7 = new WeakHashMap();
map7.put(key, value);
assertSame("WeakHashMap", map7.remove(key), value);
AbstractMap aSpecialMap = new MyMap();
aSpecialMap.put(specialKey, specialValue);
Object valueOut = aSpecialMap.remove(specialKey);
assertSame("MyMap", valueOut, specialValue);
}
use of java.util.WeakHashMap in project robovm by robovm.
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());
}
Aggregations