Calculating int next power of two
Java has Integer.highestOneBit that can make this a bit simpler:

int highestOneBit = Integer.highestOneBit(value);
if (value == highestOneBit) {
    return value;
}
return highestOneBit &lt;&lt; 1;