private void doubleCapacity() {
        int n = mElements.length;
        int r = n - mHead;
        int newCapacity = n << 1;
        if (newCapacity < 0) {
            throw new RuntimeException("Max array capacity exceeded");
        }
        Object[] a = new Object[newCapacity];
        System.arraycopy(mElements, mHead, a, 0, r);
        System.arraycopy(mElements, 0, a, r, mHead);
        mElements = (E[]) a;
        mHead = 0;
        mTail = n;
        mCapacityBitmask = newCapacity - 1;
    }
CircularArray is a generic circular array data structure that provides O(1) random read, O(1)
prepend and O(1) append. The CircularArray automatically grows its capacity when number of added
items is over its capacity.
android/android_framework/base/src/main/java/github/tornaco/android/thanos/core/util/collection/CircularArray.java