private boolean resize ( int newCapacity ) { // assert (newCapacity & -newCapacity) == newCapacity; // power of 2 int newLength = newCapacity * 2 ; Object [ ] oldTable = table ; int oldLength = oldTable . length ; if ( oldLength == 2 * MAXIMUM_CAPACITY ) { // can't expand any further if ( size == MAXIMUM_CAPACITY - 1 ) throw new IllegalStateException ( "Capacity exhausted." ) ; return false ; } if ( oldLength >= newLength ) return false ; Object [ ] newTable = new Object [ newLength ] ; for ( int j = 0 ; j < oldLength ; j += 2 ) { Object key = oldTable [ j ] ; if ( key != null ) { Object value = oldTable [ j + 1 ] ; oldTable [ j ] = null ; oldTable [ j + 1 ] = null ; int i = hash ( key , newLength ) ; while ( newTable [ i ] != null ) i = nextKeyIndex ( i , newLength ) ; newTable [ i ] = key ; newTable [ i + 1 ] = value ; } } table = newTable ; return true ; }
Resizes the table if necessary to hold given capacity .