return the next power of two after @param capacity or
capacity if it is already
162566
public static int getCapacity(int capacity) {
        int c = 1;
        if(capacity >= MAX_POWER2) {
            c = MAX_POWER2;
        } else {
            while(c < capacity) c <<= 1;
        }

        if(isPowerOf2(c)) {
            return c;
        } else {
            throw new RuntimeException("Capacity is not a power of 2.");
        }
    }
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;
    }
596295
private int nextBoundaryAfter(int startIndex) {
        BreakIterator breakiterator = search_.breakIter();

        if (breakiterator == null) {
            breakiterator = search_.internalBreakIter_;
        }

        if (breakiterator != null) {
            return breakiterator.following(startIndex);
        }

        return startIndex;
    }
1075047
@Override
    public int nextInt(int n) {
        if (n <= 0) {
            throw new IllegalArgumentException("n must be positive");
        }

        // the special treatment of powers of 2 as in Random.nextInt(int) shouldn't be necessary
        int bits, val;
        do {
            bits = nextInt() >>> 1;
            val = bits % n;
        } while (bits - val + (n - 1) < 0);
        return val;
    }
879630
public Buffer capacity(int capacity) {
    if (capacity > maxCapacity) {
      throw new IllegalArgumentException("capacity cannot be greater than maximum capacity");
    } else if (capacity < this.capacity) {
      throw new IllegalArgumentException("capacity cannot be decreased");
    } else if (capacity != this.capacity) {
      // It's possible that the bytes could already meet the requirements of the capacity.
      if (offset(capacity) > bytes.size()) {
        bytes.resize((int) Math.min(Memory.Util.toPow2(offset(capacity)), Integer.MAX_VALUE));
      }
      this.capacity = capacity;
    }
    return this;
  }
745264
def next_prime( starting_value ):
  ""

  if starting_value < 2: return 2
  result = ( starting_value + 1 ) | 1
  while not is_prime( result ): result = result + 2
  return result
1237216
public static int nextPow2Int(int x) {
    --x;
    x |= x >>> 1;
    x |= x >>> 2;
    x |= x >>> 4;
    x |= x >>> 8;
    x |= x >>> 16;
    return ++x;
  }
1234444
private Long computeUpdatedAmount(@Nullable Long currentAmount, @Nullable Long newAmount) {

        currentAmount = currentAmount == null ? 0L : currentAmount;
        newAmount = newAmount == null ? 0L : newAmount;

        if (usage.getUsageType() == UsageType.CAPACITY) {
            return Math.max(currentAmount, newAmount);
        } else /* UsageType.CONSUMABLE */ {
            return currentAmount + newAmount;
        }
    }
19614
public static IoBuffer allocate(int capacity, boolean direct) {
    if (capacity < 0) {
      throw new IllegalArgumentException("capacity: " + capacity);
    }

    return allocator.allocate(capacity, direct);
  }
472665
public static ByteBuffer createByteBuffer(int capacity) {
        return ByteBuffer.allocateDirect(capacity * DataType.BYTE.getByteSize()).order(ByteOrder.nativeOrder());
    }
10238
protected int chooseShrinkCapacity(int size, double minLoad, double maxLoad) {
    return nextPrime(Math.max(size+1, (int) ((4*size / (minLoad+3*maxLoad)))));
  }
291157
def next(self):
        
        if self.count < len(self.reservoir):
            self.count += 1
            return self.reservoir[self.count-1]

        raise StopIteration("Reservoir exhausted")
1203136
public int ensureCapacity(int requiredCapacity, int currentCapacity) {
        if (requiredCapacity > currentCapacity) {
            int newCapacity = (currentCapacity * 3) / 2 + 1;
            if (newCapacity < requiredCapacity) {
                newCapacity = requiredCapacity;
            }
            return newCapacity;
        } else {
            return currentCapacity;
        }
    }
1161594
private static int computeCapacity(final int expectedSize) {
        if (expectedSize == 0) {
            return 1;
        }
        final int capacity   = (int) InternalFastMath.ceil(expectedSize / LOAD_FACTOR);
        final int powerOfTwo = Integer.highestOneBit(capacity);
        if (powerOfTwo == capacity) {
            return capacity;
        }
        return nextPowerOfTwo(capacity);
    }
485060
private void ensurePowerOfTwo(String parameter, int number) {
        if (Integer.bitCount(number) > 1) {
            LOG.warn("Parameter {} should be power of two but was {}", parameter, number);
        }
    }
898474
public static byte[] ensureCapacity(byte array[], int capacity){
        if(capacity<=0 || capacity-array.length<=0)
            return array;

        int newCapacity = array.length*2;
        if(newCapacity-capacity< 0)
            newCapacity = capacity;
        if(newCapacity<0){
            if(capacity<0) // overflow
                throw new OutOfMemoryError();
            newCapacity = Integer.MAX_VALUE;
        }
        return Arrays.copyOf(array, newCapacity);
    }
1065842
public static int getPowerOf2(long value) {
        Preconditions.checkArgument(isPowerOf2(value));
        return Long.SIZE-(Long.numberOfLeadingZeros(value)+1);
    }