public class MathUtils extends Object
Modifier and Type | Method and Description |
---|---|
static void |
checkPowerOf2(int len)
Check if a value is a power of two.
|
static int |
compareInt(int a,
int b)
Compare two values.
|
static int |
compareLong(long a,
long b)
Compare two values.
|
static int |
convertLongToInt(long l)
Convert a long value to an int value.
|
static int |
nextPowerOf2(int x)
Get the value that is equal or higher than this value, and that is a
power of two.
|
static void |
randomBytes(byte[] bytes)
Get a number of pseudo random bytes.
|
static int |
randomInt(int lowerThan)
Get a pseudo random int value between 0 (including and the given value
(excluding).
|
static int |
reverseInt(int x)
Reverse the bits in a 32 bit integer.
|
static long |
reverseLong(long x)
Reverse the bits in a 64 bit long.
|
static int |
roundUpInt(int x,
int blockSizePowerOf2)
Round the value up to the next block size.
|
static long |
roundUpLong(long x,
long blockSizePowerOf2)
Round the value up to the next block size.
|
static byte[] |
secureRandomBytes(int len)
Get a number of cryptographically secure pseudo random bytes.
|
static int |
secureRandomInt(int lowerThan)
Get a cryptographically secure pseudo random int value between 0
(including and the given value (excluding).
|
static long |
secureRandomLong()
Get a cryptographically secure pseudo random long value.
|
static BigDecimal |
setScale(BigDecimal bd,
int scale)
Set the scale of a BigDecimal value.
|
public static int roundUpInt(int x, int blockSizePowerOf2)
x
- the value to be roundedblockSizePowerOf2
- the block sizepublic static long roundUpLong(long x, long blockSizePowerOf2)
x
- the value to be roundedblockSizePowerOf2
- the block sizepublic static void checkPowerOf2(int len)
len
- the value to checkRuntimeException
- if it is not a power of twopublic static int nextPowerOf2(int x)
x
- the original valuepublic static BigDecimal setScale(BigDecimal bd, int scale)
bd
- the BigDecimal valuescale
- the new scalepublic static int convertLongToInt(long l)
l
- the value to convertpublic static int reverseInt(int x)
x
- the original valuepublic static long reverseLong(long x)
x
- the original valuepublic static int compareInt(int a, int b)
a
- the first valueb
- the second valuepublic static int compareLong(long a, long b)
a
- the first valueb
- the second valuepublic static long secureRandomLong()
public static void randomBytes(byte[] bytes)
bytes
- the target arraypublic static byte[] secureRandomBytes(int len)
len
- the number of bytespublic static int randomInt(int lowerThan)
lowerThan
- the value returned will be lower than this valuepublic static int secureRandomInt(int lowerThan)
lowerThan
- the value returned will be lower than this valueCopyright © 2012 JBoss by Red Hat. All Rights Reserved.