Search in sources :

Example 76 with IdentityHashMap

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

the class IdentityHashMapTest method test_keyset_remove.

/**
	 * @tests java.util.IdentityHashMap#keySet()
	 * @tests java.util.IdentityHashMap#remove(java.lang.Object)
	 */
public void test_keyset_remove() {
    IdentityHashMap map = new IdentityHashMap();
    Integer key = new Integer(21);
    map.put(new Integer(1), null);
    map.put(new Integer(11), null);
    map.put(key, null);
    map.put(new Integer(31), null);
    map.put(new Integer(41), null);
    map.put(new Integer(51), null);
    map.put(new Integer(61), null);
    map.put(new Integer(71), null);
    map.put(new Integer(81), null);
    map.put(new Integer(91), null);
    Set set = map.keySet();
    Set newset = new HashSet();
    Iterator it = set.iterator();
    while (it.hasNext()) {
        Object element = it.next();
        if (element == key) {
            it.remove();
        } else
            newset.add(element);
    }
    int size = newset.size();
    assertTrue("keyset and newset don't have same size", newset.size() == size);
    assertTrue("element is in newset ", !newset.contains(key));
    assertTrue("element not removed from keyset", !set.contains(key));
    assertTrue("element not removed from map", !map.containsKey(key));
    assertTrue("newset and keyset do not have same elements 1", newset.equals(set));
    assertTrue("newset and keyset do not have same elements 2", set.equals(newset));
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) TreeSet(java.util.TreeSet) IdentityHashMap(java.util.IdentityHashMap) Iterator(java.util.Iterator) HashSet(java.util.HashSet)

Example 77 with IdentityHashMap

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

the class IdentityHashMapTest method test_clone_scenario4.

public void test_clone_scenario4() {
    IdentityHashMap hashMap = new IdentityHashMap();
    Object cloneHashMap = hashMap.clone();
    assertNull(((IdentityHashMap) cloneHashMap).get((Object) null));
    hashMap.put((Object) null, cloneHashMap);
    assertNull(((IdentityHashMap) cloneHashMap).get((Object) null));
    assertEquals(cloneHashMap, hashMap.get((Object) null));
}
Also used : IdentityHashMap(java.util.IdentityHashMap)

Example 78 with IdentityHashMap

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

the class IdentityHashMapTest method test_clone_scenario2.

public void test_clone_scenario2() {
    IdentityHashMap hashMap = new IdentityHashMap();
    assertEquals(0, hashMap.hashCode());
    Object cloneHashMap = hashMap.clone();
    hashMap.put("key", "value");
    assertEquals(1, hashMap.size());
    assertEquals(0, ((IdentityHashMap) cloneHashMap).size());
    assertEquals("value", hashMap.get("key"));
    assertNull(((IdentityHashMap) cloneHashMap).get("key"));
    assertTrue(0 != hashMap.hashCode());
    assertEquals(0, cloneHashMap.hashCode());
}
Also used : IdentityHashMap(java.util.IdentityHashMap)

Example 79 with IdentityHashMap

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

the class IdentityHashMapTest method test_clone_scenario1.

public void test_clone_scenario1() {
    IdentityHashMap hashMap = new IdentityHashMap();
    assertEquals(0, hashMap.hashCode());
    Object cloneHashMap = hashMap.clone();
    ((IdentityHashMap) cloneHashMap).put("key", "value");
    assertEquals(0, hashMap.hashCode());
    assertTrue(0 != cloneHashMap.hashCode());
}
Also used : IdentityHashMap(java.util.IdentityHashMap)

Example 80 with IdentityHashMap

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

the class IdentityHashMapTest method test_keySet_retainAll.

/**
	 * @tests java.util.IdentityHashMap#keySet()
	 */
public void test_keySet_retainAll() {
    IdentityHashMap map = new IdentityHashMap();
    for (int i = 0; i < 1000; i++) {
        map.put(new Integer(i), new Integer(i));
    }
    Set set = map.keySet();
    // retain all the elements
    boolean result = set.retainAll(set);
    assertTrue("retain all should return false", !result);
    assertEquals("did not retain all", 1000, set.size());
    // send empty set to retainAll
    result = set.retainAll(new TreeSet());
    assertTrue("retain all should return true", result);
    assertEquals("did not remove all elements in the map", 0, map.size());
    assertTrue("did not remove all elements in the keyset", set.isEmpty());
    Iterator it = set.iterator();
    assertTrue("keySet iterator still has elements", !it.hasNext());
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) TreeSet(java.util.TreeSet) TreeSet(java.util.TreeSet) IdentityHashMap(java.util.IdentityHashMap) Iterator(java.util.Iterator)

Aggregations

IdentityHashMap (java.util.IdentityHashMap)142 Map (java.util.Map)44 HashMap (java.util.HashMap)42 ArrayList (java.util.ArrayList)31 HashSet (java.util.HashSet)20 LinkedHashMap (java.util.LinkedHashMap)18 Collection (java.util.Collection)16 Set (java.util.Set)16 TreeMap (java.util.TreeMap)16 Iterator (java.util.Iterator)14 AbstractMap (java.util.AbstractMap)13 List (java.util.List)11 Test (org.junit.Test)11 DependencyNode (org.sonatype.aether.graph.DependencyNode)10 WeakHashMap (java.util.WeakHashMap)8 LinkedList (java.util.LinkedList)7 TreeSet (java.util.TreeSet)7 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)7 Tree (edu.stanford.nlp.trees.Tree)6 IOException (java.io.IOException)6