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