MathUtil Class — netty Architecture
Architecture documentation for the MathUtil class in MathUtil.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD 5b445184_30a8_2bb4_c4a5_5d15a9e41b3e["MathUtil"] f515ffb6_6d00_2114_820e_b4e0ebc0531c["MathUtil.java"] 5b445184_30a8_2bb4_c4a5_5d15a9e41b3e -->|defined in| f515ffb6_6d00_2114_820e_b4e0ebc0531c 01de9eaa_5fc3_2d1e_9f3d_7233e4757633["MathUtil()"] 5b445184_30a8_2bb4_c4a5_5d15a9e41b3e -->|method| 01de9eaa_5fc3_2d1e_9f3d_7233e4757633 31bf06c7_7aeb_d997_7524_7d7b339c18a5["findNextPositivePowerOfTwo()"] 5b445184_30a8_2bb4_c4a5_5d15a9e41b3e -->|method| 31bf06c7_7aeb_d997_7524_7d7b339c18a5 62492001_6c05_14e4_4f1c_6a2393eb5d70["safeFindNextPositivePowerOfTwo()"] 5b445184_30a8_2bb4_c4a5_5d15a9e41b3e -->|method| 62492001_6c05_14e4_4f1c_6a2393eb5d70 62b88388_3b25_38a8_1549_ef9f06d0d6ca["isOutOfBounds()"] 5b445184_30a8_2bb4_c4a5_5d15a9e41b3e -->|method| 62b88388_3b25_38a8_1549_ef9f06d0d6ca c86c060a_d2c3_03ae_0da5_6a966575e4fe["compare()"] 5b445184_30a8_2bb4_c4a5_5d15a9e41b3e -->|method| c86c060a_d2c3_03ae_0da5_6a966575e4fe
Relationship Graph
Source Code
common/src/main/java/io/netty/util/internal/MathUtil.java lines 20–100
public final class MathUtil {
private MathUtil() {
}
/**
* Fast method of finding the next power of 2 greater than or equal to the supplied value.
*
* <p>If the value is {@code <= 0} then 1 will be returned.
* This method is not suitable for {@link Integer#MIN_VALUE} or numbers greater than 2^30.
*
* @param value from which to search for next power of 2
* @return The next power of 2 or the value itself if it is a power of 2
*/
public static int findNextPositivePowerOfTwo(final int value) {
assert value > Integer.MIN_VALUE && value < 0x40000000;
return 1 << (32 - Integer.numberOfLeadingZeros(value - 1));
}
/**
* Fast method of finding the next power of 2 greater than or equal to the supplied value.
* <p>This method will do runtime bounds checking and call {@link #findNextPositivePowerOfTwo(int)} if within a
* valid range.
* @param value from which to search for next power of 2
* @return The next power of 2 or the value itself if it is a power of 2.
* <p>Special cases for return values are as follows:
* <ul>
* <li>{@code <= 0} -> 1</li>
* <li>{@code >= 2^30} -> 2^30</li>
* </ul>
*/
public static int safeFindNextPositivePowerOfTwo(final int value) {
return value <= 0 ? 1 : value >= 0x40000000 ? 0x40000000 : findNextPositivePowerOfTwo(value);
}
/**
* Determine if the requested {@code index} and {@code length} will fit within {@code capacity}.
* @param index The starting index.
* @param length The length which will be utilized (starting from {@code index}).
* @param capacity The capacity that {@code index + length} is allowed to be within.
* @return {@code false} if the requested {@code index} and {@code length} will fit within {@code capacity}.
* {@code true} if this would result in an index out of bounds exception.
*/
public static boolean isOutOfBounds(int index, int length, int capacity) {
return (index | length | capacity | index + length) < 0 || index + length > capacity;
}
/**
* @deprecated not used anymore. User Integer.compare() instead. For removal.
* Compares two {@code int} values.
*
* @param x the first {@code int} to compare
* @param y the second {@code int} to compare
* @return the value {@code 0} if {@code x == y};
* {@code -1} if {@code x < y}; and
* {@code 1} if {@code x > y}
*/
@Deprecated
public static int compare(final int x, final int y) {
// do not subtract for comparison, it could overflow
return Integer.compare(x, y);
}
/**
* @deprecated not used anymore. User Long.compare() instead. For removal.
* Compare two {@code long} values.
* @param x the first {@code long} to compare.
* @param y the second {@code long} to compare.
* @return
* <ul>
* <li>0 if {@code x == y}</li>
* <li>{@code > 0} if {@code x > y}</li>
* <li>{@code < 0} if {@code x < y}</li>
* </ul>
*/
@Deprecated
public static int compare(long x, long y) {
return Long.compare(x, y);
}
}
Source
Frequently Asked Questions
What is the MathUtil class?
MathUtil is a class in the netty codebase, defined in common/src/main/java/io/netty/util/internal/MathUtil.java.
Where is MathUtil defined?
MathUtil is defined in common/src/main/java/io/netty/util/internal/MathUtil.java at line 20.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free