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");
        }
        int[] a = new int[newCapacity];
        System.arraycopy(mElements, mHead, a, 0, r);
        System.arraycopy(mElements, 0, a, r, mHead);
        mElements = a;
        mHead = 0;
        mTail = n;
        mCapacityBitmask = newCapacity - 1;
    }
CircularIntArray is a circular integer array data structure that provides O(1) random read, O(1)
prepend and O(1) append. The CircularIntArray automatically grows its capacity when number of
added integers is over its capacity.
android/android_framework/base/src/main/java/github/tornaco/android/thanos/core/util/collection/CircularIntArray.java