final T baseAddOrReplace(T newObject) {
        if (((size + 1) * MAX_LOAD_FACTOR > elements.length) &&
                (elements.length < MAX_CAPACITY)) {
            int newSize = elements.length * 2;
            rehash(newSize);
        }
        int slot = findSlot(newObject, elements.length);
        Object cur = elements[slot];
        if (cur == null) {
            size++;
            elements[slot] = newObject;
            return null;
        } else if (cur instanceof Object[]) {
            T[] curArray = (T[]) cur;
            for (int i =  0; i < curArray.length; i++) {
                T value = curArray[i];
                if (value.equals(newObject)) {
                    curArray[i] = newObject;
                    return value;
                }
            }
            size++;
            T[] newArray = (T[]) new Object[curArray.length + 1];
            System.arraycopy(curArray, 0, newArray, 0, curArray.length);
            newArray[curArray.length] = newObject;
            elements[slot] = newArray;
            return null;
        } else if (cur.equals(newObject)) {
            elements[slot] = newObject;
            return (T) cur;
        } else {
            size++;
            elements[slot] = new Object[] {cur, newObject};
            return null;
        }
    }
Calculate the capacity we should provision, given the expected size.
<br>
Our capacity must always be a power of 2, and never less than 2 or more
than MAX_CAPACITY.  We use 64-bit numbers here to avoid overflow
concerns.
server-common/src/main/java/org/apache/kafka/timeline/BaseHashTable.java