Top Description Constructors Methods
io.netty.util.internal

public final Class MathUtil

extends Object
Class Inheritance

Math utility methods.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static int

Returns:

the value 0 if x == y; -1 if x < y; and 1 if x > y
compare
(final int
the first int to compare
x
,
final int
the second int to compare
y
)

Compares two int values.

public static int

Returns:

  • 0 if x == y
  • > 0 if x > y
  • < 0 if x < y
compare
(long
the first long to compare.
x
,
long
the second long to compare.
y
)

Compare two long values.

public static int

Returns:

The next power of 2 or the value itself if it is a power of 2
findNextPositivePowerOfTwo
(final int
from which to search for next power of 2
value
)

Fast method of finding the next power of 2 greater than or equal to the supplied value.

public static boolean

Returns:

false if the requested index and length will fit within capacity. true if this would result in an index out of bounds exception.
isOutOfBounds
(int
The starting index.
index
,
int
The length which will be utilized (starting from index).
length
,
int
The capacity that index + length is allowed to be within.
capacity
)

Determine if the requested index and length will fit within capacity.

public static int

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
safeFindNextPositivePowerOfTwo
(final int
from which to search for next power of 2
value
)

Fast method of finding the next power of 2 greater than or equal to the supplied value.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

MathUtilback to summary
private MathUtil()

Method Detail

compareback to summary
public static int compare(final int x, final int y)

Compares two int values.

Parameters
x:int

the first int to compare

y:int

the second int to compare

Returns:int

the value 0 if x == y; -1 if x < y; and 1 if x > y

compareback to summary
public static int compare(long x, long y)

Compare two long values.

Parameters
x:long

the first long to compare.

y:long

the second long to compare.

Returns:int

  • 0 if x == y
  • > 0 if x > y
  • < 0 if x < y
findNextPositivePowerOfTwoback to summary
public static int findNextPositivePowerOfTwo(final int value)

Fast method of finding the next power of 2 greater than or equal to the supplied value.

If the value is <= 0 then 1 will be returned. This method is not suitable for Integer#MIN_VALUE or numbers greater than 2^30.

Parameters
value:int

from which to search for next power of 2

Returns:int

The next power of 2 or the value itself if it is a power of 2

isOutOfBoundsback to summary
public static boolean isOutOfBounds(int index, int length, int capacity)

Determine if the requested index and length will fit within capacity.

Parameters
index:int

The starting index.

length:int

The length which will be utilized (starting from index).

capacity:int

The capacity that index + length is allowed to be within.

Returns:boolean

false if the requested index and length will fit within capacity. true if this would result in an index out of bounds exception.

safeFindNextPositivePowerOfTwoback to summary
public static int safeFindNextPositivePowerOfTwo(final 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:int

from which to search for next power of 2

Returns:int

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