code: protected void ensureBufferSpace(int expectedAdditions) {
      final int bufferLen = (buffer == null ? 0 : buffer.length);
      if (elementsCount + expectedAdditions > bufferLen) {
        final int newSize = resizer.grow(bufferLen, elementsCount, expectedAdditions);
        assert newSize >= elementsCount + expectedAdditions : "Resizer failed to" + " return sensible new size: "
            + newSize + " <= " + (elementsCount + expectedAdditions);
  
        this.buffer = Arrays.copyOf(buffer, newSize);
      }
    }
docs: Ensures the internal buffer has enough free slots to store
  <code>expectedAdditions</code>. Increases internal buffer size if needed.