Class MathUtil
java.lang.Object
io.netty.util.internal.MathUtil
Math utility methods.
-
Method Summary
Modifier and TypeMethodDescriptionstatic intcompare(int x, int y) Deprecated.not used anymore.static intcompare(long x, long y) Deprecated.not used anymore.static intfindNextPositivePowerOfTwo(int value) Fast method of finding the next power of 2 greater than or equal to the supplied value.static booleanisOutOfBounds(int index, int length, int capacity) Determine if the requestedindexandlengthwill fit withincapacity.static intsafeFindNextPositivePowerOfTwo(int value) Fast method of finding the next power of 2 greater than or equal to the supplied value.
-
Method Details
-
findNextPositivePowerOfTwo
public static int findNextPositivePowerOfTwo(int value) Fast method of finding the next power of 2 greater than or equal to the supplied value.If the value is
<= 0then 1 will be returned. This method is not suitable forInteger.MIN_VALUEor numbers greater than 2^30.- Parameters:
value- from which to search for next power of 2- Returns:
- The next power of 2 or the value itself if it is a power of 2
-
safeFindNextPositivePowerOfTwo
public static int safeFindNextPositivePowerOfTwo(int value) Fast method of finding the next power of 2 greater than or equal to the supplied value.This method will do runtime bounds checking and call
findNextPositivePowerOfTwo(int)if within a valid range.- Parameters:
value- from which to search for next power of 2- Returns:
- The next power of 2 or the value itself if it is a power of 2.
Special cases for return values are as follows:
<= 0-> 1>= 2^30-> 2^30
-
isOutOfBounds
public static boolean isOutOfBounds(int index, int length, int capacity) Determine if the requestedindexandlengthwill fit withincapacity.- Parameters:
index- The starting index.length- The length which will be utilized (starting fromindex).capacity- The capacity thatindex + lengthis allowed to be within.- Returns:
falseif the requestedindexandlengthwill fit withincapacity.trueif this would result in an index out of bounds exception.
-
compare
Deprecated.not used anymore. User Integer.compare() instead. For removal. Compares twointvalues.- Parameters:
x- the firstintto comparey- the secondintto compare- Returns:
- the value
0ifx == y;-1ifx < y; and1ifx > y
-
compare
Deprecated.not used anymore. User Long.compare() instead. For removal. Compare twolongvalues.- Parameters:
x- the firstlongto compare.y- the secondlongto compare.- Returns:
- 0 if
x == y > 0ifx > y< 0ifx < y
- 0 if
-