Search in sources :

Example 36 with WeakHashMap

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();
        }
    });
}
Also used : IdentityHashMap(java.util.IdentityHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) WeakHashMap(java.util.WeakHashMap) Hashtable(java.util.Hashtable) IdentityHashMap(java.util.IdentityHashMap) TreeMap(java.util.TreeMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) IdentityHashMap(java.util.IdentityHashMap) EnumMap(java.util.EnumMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) Map(java.util.Map) WeakHashMap(java.util.WeakHashMap) EnumMap(java.util.EnumMap) WeakHashMap(java.util.WeakHashMap)

Example 37 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 38 with WeakHashMap

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();
    }
}
Also used : HashMap(java.util.HashMap) WeakHashMap(java.util.WeakHashMap) ArrayMap(android.util.ArrayMap) WeakReference(java.lang.ref.WeakReference) DelegateClassLoader(android.taobao.atlas.runtime.DelegateClassLoader) DelegateClassLoader(android.taobao.atlas.runtime.DelegateClassLoader) DelegateResources(android.taobao.atlas.runtime.DelegateResources) Resources(android.content.res.Resources)

Example 39 with WeakHashMap

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);
}
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) LinkedHashMap(java.util.LinkedHashMap) Comparator(java.util.Comparator) WeakHashMap(java.util.WeakHashMap)

Example 40 with WeakHashMap

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

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