@Test public void shouldReturnNextPositivePowerOfTwo() { assertThat(findNextPositivePowerOfTwo(MIN_VALUE), is(MIN_VALUE)); assertThat(findNextPositivePowerOfTwo(MIN_VALUE + 1), is(1)); assertThat(findNextPositivePowerOfTwo(-1), is(1)); assertThat(findNextPositivePowerOfTwo(0), is(1)); assertThat(findNextPositivePowerOfTwo(1), is(1)); assertThat(findNextPositivePowerOfTwo(2), is(2)); assertThat(findNextPositivePowerOfTwo(3), is(4)); assertThat(findNextPositivePowerOfTwo(4), is(4)); assertThat(findNextPositivePowerOfTwo(31), is(32)); assertThat(findNextPositivePowerOfTwo(32), is(32)); assertThat(findNextPositivePowerOfTwo(1 << 30), is(1 << 30)); assertThat(findNextPositivePowerOfTwo((1 << 30) + 1), is(MIN_VALUE)); }
public static int findNextPositivePowerOfTwo(final int value) { return 1 << (Integer.SIZE - Integer.numberOfLeadingZeros(value - 1)); }
BitUtil { public static int findNextPositivePowerOfTwo(final int value) { return 1 << (Integer.SIZE - Integer.numberOfLeadingZeros(value - 1)); } }
BitUtil { public static int findNextPositivePowerOfTwo(final int value) { return 1 << (Integer.SIZE - Integer.numberOfLeadingZeros(value - 1)); } private  BitUtil(); }
BitUtil { public static int findNextPositivePowerOfTwo(final int value) { return 1 << (Integer.SIZE - Integer.numberOfLeadingZeros(value - 1)); } private  BitUtil(); static int findNextPositivePowerOfTwo(final int value); static long findNextPositivePowerOfTwo(final long value); static int align(final int value, final int alignment); static byte[] fromHexByteArray(final byte[] buffer); static byte[] toHexByteArray(final byte[] buffer); static byte[] toHexByteArray(final byte[] buffer, final int offset, final int length); static byte[] toHexByteArray(final CharSequence charSequence, final int offset, final int length); static byte[] fromHex(final String string); static String toHex(final byte[] buffer, final int offset, final int length); static String toHex(final byte[] buffer); static boolean isEven(final int value); static boolean isEven(final long value); static boolean isPowerOfTwo(final int value); static boolean isPowerOfTwo(final long value); static int next(final int current, final int max); static int previous(final int current, final int max); static int calculateShiftForScale(final int scale); static int generateRandomisedId(); static boolean isAligned(final long address, final int alignment); }
BitUtil { public static int findNextPositivePowerOfTwo(final int value) { return 1 << (Integer.SIZE - Integer.numberOfLeadingZeros(value - 1)); } private  BitUtil(); static int findNextPositivePowerOfTwo(final int value); static long findNextPositivePowerOfTwo(final long value); static int align(final int value, final int alignment); static byte[] fromHexByteArray(final byte[] buffer); static byte[] toHexByteArray(final byte[] buffer); static byte[] toHexByteArray(final byte[] buffer, final int offset, final int length); static byte[] toHexByteArray(final CharSequence charSequence, final int offset, final int length); static byte[] fromHex(final String string); static String toHex(final byte[] buffer, final int offset, final int length); static String toHex(final byte[] buffer); static boolean isEven(final int value); static boolean isEven(final long value); static boolean isPowerOfTwo(final int value); static boolean isPowerOfTwo(final long value); static int next(final int current, final int max); static int previous(final int current, final int max); static int calculateShiftForScale(final int scale); static int generateRandomisedId(); static boolean isAligned(final long address, final int alignment); static final int SIZE_OF_BYTE; static final int SIZE_OF_BOOLEAN; static final int SIZE_OF_CHAR; static final int SIZE_OF_SHORT; static final int SIZE_OF_INT; static final int SIZE_OF_FLOAT; static final int SIZE_OF_LONG; static final int SIZE_OF_DOUBLE; static final int CACHE_LINE_LENGTH; }