final Node<K,V>[] resize() { Node<K,V>[] oldTab = table; int oldCap = (oldTab == null) ? 0 : oldTab.length; int oldThr = threshold; int newCap, newThr = 0; If (oldCap >= MAXIMUM_CAPACITY) {threshold = Integer.max_value; return oldTab; Else if ((newCap = oldCap << 1) < MAXIMUM_CAPACITY && oldCap >= newCap << 1 DEFAULT_INITIAL_CAPACITY) // new threshold double newThr = oldThr << 1; } // If old TheresHold is greater than 0 else if (oldThr > 0) // Old Threshold is assigned to the new capacity newCap = oldThr; Else {newCap = DEFAULT_INITIAL_CAPACITY; newThr = (int)(DEFAULT_LOAD_FACTOR * DEFAULT_INITIAL_CAPACITY); } if (newThr == 0) {float ft = (float)newCap * loadFactor; NewThr = (newCap < MAXIMUM_CAPACITY && ft < (float)MAXIMUM_CAPACITY? (int)ft : Integer.MAX_VALUE); } // The new threshold is copied to the current HashMap instance; threshold = newThr; @SuppressWarnings({"rawtypes","unchecked"}) Node<K,V>[] newTab = (Node<K,V>[])new Node[newCap]; table = newTab; if (oldTab ! = null) {for (int j = 0; j < oldCap; ++j) { Node<K,V> e; if ((e = oldTab[j]) ! = null) { oldTab[j] = null; if (e.next == null) newTab[e.hash & (newCap - 1)] = e; else if (e instanceof TreeNode) ((TreeNode<K,V>)e).split(this, newTab, j, oldCap); else { // preserve order Node<K,V> loHead = null, loTail = null; Node<K,V> hiHead = null, hiTail = null; Node<K,V> next; do { next = e.next; /** The entire expanded array is divided into two parts: If ((e.hash & oldCap) == 0) {if (loTail == null); if (e.hash & oldCap) == 0); LoHead = E; loHead = E; loHead = E; Else // Lotail. Next = e; // Lotail = E; } else {if (hitAil == null) // The first traverse assays to the low part header node hiHead = e; Else // HitAil. next = e; hiTail = e; } } while ((e = next) ! = null); if (loTail ! = null) { loTail.next = null; NewTab [j] newTab[j] = loHead; } if (hiTail ! = null) { hiTail.next = null; NewTab [j+oldCap] = newTab[j+oldCap] = hiHead; } } } } } return newTab; }