### Question:
HashMap extends Map<K, V> { void rehash(int capacity) { int length = calculateCapacity((capacity == 0 ? 1 : capacity << 1)); HashMapEntry<K, V>[] newData = newElementArray(length); for (int i = 0; i < elementData.length; i++) { HashMapEntry<K, V> entry = elementData[i]; elementData[i] = null; while (entry != null) { int index = entry.origKeyHash & (length - 1); HashMapEntry<K, V> next = entry.next; entry.next = newData[index]; newData[index] = entry; entry = next; } } elementData = newData; computeThreshold(); } HashMap();  HashMap(int capacity);  HashMap(int capacity, float loadFactor);  HashMap(Map<K, V> map); @Override void clear(); @Override boolean containsKey(K key); @Override boolean containsValue(V value); @Override Set<MapEntry<K, V>> entrySet(); @Override V get(K key); @Override boolean isEmpty(); @Override Set<K> keySet(); @Override V put(K key, V value); @Override void putAll(Map<? extends K, ? extends V> map); @Override V remove(K key); @Override int size(); @Override Collection<V> values();  }### Answer:
@Test public void testRehash() { HashMap<MyKey, Integer> hm = new HashMap<MyKey, Integer>(10, 0.5f); MyKey[] keyOrder = new MyKey[9]; for (int i = 0; i < keyOrder.length; i++) { keyOrder[i] = new MyKey(); } for (int i = 0; i < 8; i++) { hm.put(keyOrder[i], i); } MyKey[] returnedKeys = new MyKey[9]; hm.keySet().toArray(returnedKeys); for (int i = 0; i < 8; i++) { assertSame(null, keyOrder[i], returnedKeys[7 - i]); } hm.put(keyOrder[8], 8); hm.keySet().toArray(returnedKeys); for (int i = 0; i < 9; i++) { assertSame(null, keyOrder[i], returnedKeys[i]); } }