Ensures the internal buffer has enough free slots to store
<code>expectedAdditions</code>. Increases internal buffer size if needed.
349433
protected void ensureBufferSpace(int expectedAdditions) {
    final int bufferLen = buffer.length;
    final int elementsCount = size();

    if (elementsCount + expectedAdditions >= bufferLen) {
      final int emptySlot = 1; // deque invariant: always an empty slot.
      final int newSize = resizer.grow(bufferLen, elementsCount + emptySlot, expectedAdditions);
      assert newSize >= (elementsCount + expectedAdditions + emptySlot) : "Resizer failed to"
          + " return sensible new size: " + newSize + " <= " + (elementsCount + expectedAdditions);

      try {
        final KType[] newBuffer = Intrinsics.<KType> newArray(newSize);
        if (bufferLen > 0) {
          toArray(newBuffer);
          tail = elementsCount;
          head = 0;
        }
        this.buffer = newBuffer;
      } catch (OutOfMemoryError e) {
        throw new BufferAllocationException(
            "Not enough memory to allocate new buffers: %,d -> %,d", 
            e, bufferLen, newSize);
      }
    }
  }
834208
public void ensureCapacity(int capacity) {
        if (capacity > data.length) {
            int newCap = Math.max(data.length << 1, capacity);
            int[] tmp = new int[newCap];
            System.arraycopy(data, 0, tmp, 0, data.length);
            data = tmp;
        }
    }
13868
public void ensureHasSpace(int numBytesToAdd) {
    if (numBytesToAdd < 0) {
      throw new IllegalArgumentException("Number of bytes can't be negative");
    }
    int capacityLeft = getCapacityLeft();
    if (capacityLeft < numBytesToAdd) {
      grow(numBytesToAdd - capacityLeft, true);
    }
  }
1088000
private void boundSize(HashSetModifiableDBIDs set, int items) {
    if(set.size() > items) {
      DBIDs sample = DBIDUtil.randomSample(set, items, rnd);
      set.clear();
      set.addDBIDs(sample);
    }
  }
928602
public final void ensureCapacity(int minCapacity) {
    if (minCapacity < 0) {
      throw new IndexOutOfBoundsException();
    }
    Object[] data = this.data;
    int minDataCapacity = minCapacity << 1;
    int oldDataCapacity = data == null ? 0 : data.length;
    if (minDataCapacity > oldDataCapacity) {
      int newDataCapacity = oldDataCapacity / 2 * 3 + 1;
      if (newDataCapacity % 2 != 0) {
        newDataCapacity++;
      }
      if (newDataCapacity < minDataCapacity) {
        newDataCapacity = minDataCapacity;
      }
      setDataCapacity(newDataCapacity);
    }
  }
50862
public void add(Bounds bounds) {
        if (bounds.minX < minX) minX = bounds.minX;
        if (bounds.minY < minY) minY = bounds.minY;
        if (bounds.maxX > maxX) maxX = bounds.maxX;
        if (bounds.maxY > maxY) maxY = bounds.maxY;
    }
1205672
public void ensureSize(int maxPartitionOrder) {
        if (capacityByOrder >= maxPartitionOrder) return;
        parameters = new int[(1 << maxPartitionOrder)];
        rawBits = new int[(1 << maxPartitionOrder)]; 
        capacityByOrder = maxPartitionOrder;
    }
429318
@Override
    @SuppressWarnings("unchecked")
    protected void ensureCapacity(int capacity) {
        checkCapacity(capacity);
        K[] newArray = (K[]) new Object[capacity];
        System.arraycopy(array, 0, newArray, 0, size);
        array = newArray;
        BitSet newBitSet = new BitSet(capacity);
        newBitSet.or(reverse);
        reverse = newBitSet;
    }
198526
@SuppressWarnings("unchecked")
    private void ensureCapacity(int capacity) {
        checkCapacity(capacity);
        Elem<V>[] newArray = (Elem<V>[]) Array.newInstance(Elem.class, capacity + 2);
        if (newArray.length >= array.length) {
            System.arraycopy(array, 0, newArray, 0, array.length);
            for (int i = array.length; i < newArray.length; i++) {
                newArray[i] = new Elem<V>(SUP_KEY, null);
            }
        } else {
            System.arraycopy(array, 0, newArray, 0, newArray.length);
        }
        array = newArray;
    }
397930
private void ensureAvail(int n) {
    if (pos + n >= buf.length) {
      int newSize = Math.max(pos + n, buf.length * 2);
      buf = Arrays.copyOf(buf, newSize);
    }
  }
1358508
private void increaseSizeTo(int newSize) {
    assert (newSize > pointers.length);
    double[][] pointersBuf = new double[newSize][];
    boolean[] sparseBuf = new boolean[newSize];
    boolean[] copyOnWriteBuf = new boolean[newSize];
    System.arraycopy(pointers, 0, pointersBuf, 0, pointers.length);
    System.arraycopy(sparse, 0, sparseBuf, 0, pointers.length);
    System.arraycopy(copyOnWrite, 0, copyOnWriteBuf, 0, pointers.length);
    pointers = pointersBuf;
    sparse = sparseBuf;
    copyOnWrite = copyOnWriteBuf;
  }
1052564
public void reserve (@Nonnegative final int nExpectedLength)
  {
    ValueEnforcer.isGE0 (nExpectedLength, "ExpectedLength");
    if (m_aBuffer.position () != 0)
      throw new IllegalStateException ("cannot be called except after finish()");

    if (nExpectedLength > m_aBuffer.capacity ())
    {
      // Allocate a temporary buffer large enough for this string rounded up
      int nDesiredLength = nExpectedLength;
      if ((nDesiredLength & SIZE_ALIGNMENT_MASK) != 0)
      {
        // round up
        nDesiredLength = (nExpectedLength + SIZE_ALIGNMENT) & ~SIZE_ALIGNMENT_MASK;
      }
      assert nDesiredLength % SIZE_ALIGNMENT == 0;

      m_aBuffer = CharBuffer.allocate (nDesiredLength);
    }
    if (m_aBuffer.position () != 0)
      throw new IllegalStateException ("Buffer position weird!");
    if (nExpectedLength > m_aBuffer.capacity ())
      throw new IllegalStateException ();
  }
151658
boolean allocateTiny(PoolArena<?> area, PooledByteBuf<?> buf, int reqCapacity, int normCapacity) {
        return allocate(cacheForTiny(area, normCapacity), buf, reqCapacity);
    }
1329370
public static void boundsCheck(int capacity, int index, int length) {
        if (capacity < 0 || index < 0 || length < 0 || (index > (capacity - length))) {
            throw new IndexOutOfBoundsException(String.format("index=%d, length=%d, capacity=%d", index, length, capacity));
        }
    }
1297977
private void ensureParams() {
        if (this.isDirty) {
            // note, it would only be dirty if we actually have inserted a value
            // so therefore no need to check that the parammap is null
            final Buffer restOfParams = this.params;
            this.params = allcoateNewParamBuffer();
            for (final Map.Entry<Buffer, Buffer> entry : this.paramMap.entrySet()) {
                this.params.write(SipParser.SEMI);
                final Buffer key = entry.getKey();
                final Buffer value = entry.getValue();
                key.getBytes(0, this.params);
                if (value != null && !value.isEmpty()) {
                    this.params.write(SipParser.EQ);
                    value.getBytes(0, this.params);
                }
            }
            this.paramMap.clear();
            restOfParams.getBytes(this.params);
            this.originalParams = this.params.slice();
            this.isDirty = false;
        }
    }
1262512
private void ensureCapacity(int newSize) {
        int oldSize;
        if ((oldSize = branchingEnumerators.length) < newSize) {
            branchingEnumerators = Arrays.copyOfRange(branchingEnumerators, 0, newSize);
            for (int i = oldSize; i < newSize; ++i)
                branchingEnumerators[i] = new BranchingEnumerator<>(reference, guide);
        }
    }
72943
private void ensureCapacity(final int index, final int length)
    {
        if (index < 0)
        {
            throw new IndexOutOfBoundsException("index cannot be negative: index=" + index);
        }

        final long resultingPosition = index + (long)length;
        final int currentArrayLength = byteArray.length;
        if (resultingPosition > currentArrayLength)
        {
            if (currentArrayLength >= MAX_ARRAY_LENGTH)
            {
                throw new IndexOutOfBoundsException(
                    "index=" + index + " length=" + length + " maxCapacity=" + MAX_ARRAY_LENGTH);
            }

            byteArray = Arrays.copyOf(byteArray, calculateExpansion(currentArrayLength, (int)resultingPosition));
        }
    }