Exemple #1
0
 public void testPut() {
   IntHashMap map = new IntHashMap();
   assertNull(map.put(1, "hello"));
   assertNull(map.put(2, "world"));
   assertEquals(2, map.size());
   assertEquals("hello", map.put(1, "hellooooo"));
 }
Exemple #2
0
 public void testIsEmpty() {
   IntHashMap map = new IntHashMap();
   assertTrue(map.isEmpty());
   assertNull(map.put(1, "hello"));
   assertEquals(1, map.size());
   assertFalse(map.isEmpty());
 }
Exemple #3
0
 public void testClear() {
   IntHashMap map = new IntHashMap();
   assertNull(map.put(1, "hello"));
   assertNull(map.put(2, "world"));
   assertEquals(2, map.size());
   map.clear();
   assertEquals(0, map.size());
 }
Exemple #4
0
 public void testContainsKey() {
   IntHashMap map = new IntHashMap();
   assertNull(map.put(1, "hello"));
   assertNull(map.put(2, "world"));
   assertEquals(2, map.size());
   assertTrue(map.containsKey(1));
   assertTrue(map.containsKey(2));
   assertFalse(map.containsKey(3));
 }
Exemple #5
0
 public void testRemove() {
   IntHashMap map = new IntHashMap();
   assertNull(map.put(1, "hello"));
   assertNull(map.put(2, "world"));
   assertEquals(2, map.size());
   assertEquals("hello", map.remove(1));
   assertEquals(1, map.size());
   assertNull(map.remove(3));
 }
 public static <V> IntHashMap<V> copy(Map<Integer, V> target) {
   if (target == null) {
     throw new NullPointerException("target must not be null");
   }
   final IntHashMap<V> copyMap = new IntHashMap<V>();
   for (Map.Entry<Integer, V> entry : target.entrySet()) {
     copyMap.put(entry.getKey(), entry.getValue());
   }
   return copyMap;
 }
Exemple #7
0
 public void testContainsValue() {
   IntHashMap map = new IntHashMap();
   assertNull(map.put(1, "hello"));
   assertNull(map.put(2, "world"));
   assertEquals(2, map.size());
   assertTrue(map.containsValue("hello"));
   assertTrue(map.containsValue("world"));
   assertFalse(map.containsValue("goodbye"));
   try {
     map.containsValue(null);
     fail();
   } catch (NullPointerException e) {
   }
 }
Exemple #8
0
 /** {@inheritDoc} */
 public void add(String name, int value) {
   mapNameToValue.put(name, new Integer(value));
   mapValueToName.put(value, name);
 }