Search in sources :

Example 11 with WeakHashMap

use of java.util.WeakHashMap in project robovm by robovm.

the class WeakHashMapTest method test_putLjava_lang_ObjectLjava_lang_Object.

/**
     * java.util.WeakHashMap#put(java.lang.Object, java.lang.Object)
     */
public void test_putLjava_lang_ObjectLjava_lang_Object() {
    // Test for method java.lang.Object
    // java.util.WeakHashMap.put(java.lang.Object, java.lang.Object)
    WeakHashMap map = new WeakHashMap();
    // add null key
    map.put(null, "value");
    System.gc();
    System.gc();
    FinalizationTester.induceFinalization();
    // Cause objects in queue to be removed
    map.remove("nothing");
    assertEquals("null key was removed", 1, map.size());
}
Also used : WeakHashMap(java.util.WeakHashMap)

Example 12 with WeakHashMap

use of java.util.WeakHashMap in project robovm by robovm.

the class WeakHashMapTest method test_values.

/**
     * java.util.WeakHashMap#values()
     */
public void test_values() {
    // Test for method java.util.Set java.util.WeakHashMap.values()
    whm = new WeakHashMap();
    for (int i = 0; i < 100; i++) whm.put(keyArray[i], valueArray[i]);
    List keys = Arrays.asList(keyArray);
    List values = Arrays.asList(valueArray);
    Collection valuesCollection = whm.values();
    assertEquals("Incorrect number of keys returned,", 100, valuesCollection.size());
    Iterator it = valuesCollection.iterator();
    while (it.hasNext()) {
        Object value = it.next();
        assertTrue("Invalid map entry returned--bad value", values.contains(value));
    }
    keys = null;
    values = null;
    keyArray[50] = null;
    int count = 0;
    do {
        System.gc();
        System.gc();
        FinalizationTester.induceFinalization();
        count++;
    } while (count <= 5 && valuesCollection.size() == 100);
    assertEquals("Incorrect number of keys returned after gc,", 99, valuesCollection.size());
}
Also used : Iterator(java.util.Iterator) Collection(java.util.Collection) List(java.util.List) WeakHashMap(java.util.WeakHashMap)

Example 13 with WeakHashMap

use of java.util.WeakHashMap in project robovm by robovm.

the class WeakHashMapTest method test_keySet.

/**
     * java.util.WeakHashMap#keySet()
     */
public void test_keySet() {
    // Test for method java.util.Set java.util.WeakHashMap.keySet()
    whm = new WeakHashMap();
    for (int i = 0; i < 100; i++) whm.put(keyArray[i], valueArray[i]);
    List keys = Arrays.asList(keyArray);
    List values = Arrays.asList(valueArray);
    Set keySet = whm.keySet();
    assertEquals("Incorrect number of keys returned,", 100, keySet.size());
    Iterator it = keySet.iterator();
    while (it.hasNext()) {
        Object key = it.next();
        assertTrue("Invalid map entry returned--bad key", keys.contains(key));
    }
    keys = null;
    values = null;
    keyArray[50] = null;
    int count = 0;
    do {
        System.gc();
        System.gc();
        FinalizationTester.induceFinalization();
        count++;
    } while (count <= 5 && keySet.size() == 100);
    assertEquals("Incorrect number of keys returned after gc,", 99, keySet.size());
}
Also used : Set(java.util.Set) Iterator(java.util.Iterator) List(java.util.List) WeakHashMap(java.util.WeakHashMap)

Example 14 with WeakHashMap

use of java.util.WeakHashMap in project robovm by robovm.

the class WeakHashMapTest method test_entrySet.

/**
     * java.util.WeakHashMap#entrySet()
     */
public void test_entrySet() {
    // Test for method java.util.Set java.util.WeakHashMap.entrySet()
    whm = new WeakHashMap();
    for (int i = 0; i < 100; i++) whm.put(keyArray[i], valueArray[i]);
    List keys = Arrays.asList(keyArray);
    List values = Arrays.asList(valueArray);
    Set entrySet = whm.entrySet();
    assertTrue("Incorrect number of entries returned--wanted 100, got: " + entrySet.size(), entrySet.size() == 100);
    Iterator it = entrySet.iterator();
    while (it.hasNext()) {
        Map.Entry entry = (Map.Entry) it.next();
        assertTrue("Invalid map entry returned--bad key", keys.contains(entry.getKey()));
        assertTrue("Invalid map entry returned--bad key", values.contains(entry.getValue()));
    }
    keys = null;
    values = null;
    keyArray[50] = null;
    int count = 0;
    do {
        System.gc();
        System.gc();
        FinalizationTester.induceFinalization();
        count++;
    } while (count <= 5 && entrySet.size() == 100);
    assertTrue("Incorrect number of entries returned after gc--wanted 99, got: " + entrySet.size(), entrySet.size() == 99);
}
Also used : Set(java.util.Set) Iterator(java.util.Iterator) List(java.util.List) AbstractMap(java.util.AbstractMap) Map(java.util.Map) WeakHashMap(java.util.WeakHashMap) WeakHashMap(java.util.WeakHashMap)

Example 15 with WeakHashMap

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

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)

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