Class Utils
- Author:
- Beat Hörmann
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int[]
The value ofbnd4
[x] for 0 ≤ x < 4 is equal to 256x - 1 and the value ofbnd4
[4] is equal to the value of theInteger.MAX_VALUE
constant.static final long[]
The value ofbnd8
[x] for 0 ≤ x < 8 is equal to 256x - 1 and the value ofbnd8
[8] is equal to the value of theLong.MAX_VALUE
constant.static final int
One mebibyte has 1024 * 1024 = 1048576 bytes.static final byte[][]
The value ofzeros
[x] for 0 ≤ x ≤ 8 is equal to a byte array of length x filled with zeros. -
Method Summary
Modifier and TypeMethodDescriptionstatic final int
bitCount
(byte[] bytes, int offset, int len) Returns the number of one-bits in the specified subarray of bytes.static final int
bmLength
(int n) Returns the number of bytes of a bitmap withn
bits represented as an array of bytes.static final Path
Builds a path from the specified path string and the optional directory path.static final boolean
equals
(byte[] arr1, byte[] arr2, int offset, int n) Finds out ifarr1[k]
==arr2[k]
foroffset
≤k
<offset
+n
.static final boolean
Finds out if at least one element of the specified array is equal tonull
.static final boolean
isZero
(byte[] bytes, int offset, int len) Finds out if all the bytes of the specified subarray of bytes are zero.static final int
lor
(long x) Computes ⌊log
256(x)⌋ + 1 for x ≥ 1.static final long
unsFromBytes
(byte[] bytes, int len) Converts the specified byte array of the specified length to an unsigned integer value.static final long
unsFromBytes
(byte[] bytes, int offset, int len) Converts the specified byte subarray to an unsigned integer value.static final byte[]
unsToBytes
(long val, int len) Converts the specified unsigned integer value of the specified length to a byte array of the same length.static final void
unsToBytes
(long val, int len, byte[] bytes) Converts the specified unsigned integer value of the specified length to a byte array and stores it into the specified byte array.static final void
unsToBytes
(long val, int len, byte[] bytes, int offset) Converts the specified unsigned integer value of the specified length to a byte array and stores it into the specified byte array starting at the specified offset.
-
Field Details
-
oneMiB
public static final int oneMiBOne mebibyte has 1024 * 1024 = 1048576 bytes.- See Also:
-
bnd8
public static final long[] bnd8The value ofbnd8
[x] for 0 ≤ x < 8 is equal to 256x - 1 and the value ofbnd8
[8] is equal to the value of theLong.MAX_VALUE
constant.The value of
bnd8
[x] is equal to the largest unsigned integer with a width (or precision) equal to x bytes using the binary numeral system. The value ofbnd8
[8] is equal to Java's largest positive built-in integer number.Treat this array as if it were immutable: Don't change any of its elements. (This variable is not used inside ACDP.)
-
bnd4
public static final int[] bnd4The value ofbnd4
[x] for 0 ≤ x < 4 is equal to 256x - 1 and the value ofbnd4
[4] is equal to the value of theInteger.MAX_VALUE
constant.Treat this array as if it were immutable: Don't change any of its elements. (This variable is not used inside ACDP.)
-
zeros
public static final byte[][] zerosThe value ofzeros
[x] for 0 ≤ x ≤ 8 is equal to a byte array of length x filled with zeros. Note thatzeros
[0] returns an empty byte array.Treat this array as if it were immutable: Don't change any of its elements. (This variable is not used inside ACDP.)
-
-
Method Details
-
lor
public static final int lor(long x) Computes ⌊log
256(x)⌋ + 1 for x ≥ 1.The result of this method is equal to the minimum number of bytes necessary to represent the argument as an unsigend integer using the binary numeral system.
Note that
lor
(bnd8
[x]) equalsx
for 1 ≤ x ≤ 8.- Parameters:
x
- The argument.- Returns:
- The value of the described function or 1 if x < 1.
-
bmLength
public static final int bmLength(int n) Returns the number of bytes of a bitmap withn
bits represented as an array of bytes.- Parameters:
n
- The number of bits of the bitmap.- Returns:
- The length of the bitmap or 0 if
n
is less than 1.
-
buildPath
public static final Path buildPath(String pathStr, Path dirPath) throws NullPointerException, IllegalArgumentException, InvalidPathException Builds a path from the specified path string and the optional directory path. If the specified path string turns out to denote a relative path then it is resolved against the specified directory path.- Parameters:
pathStr
- The path string, not allowed to benull
or an empty string.dirPath
- The directory path. This value is allowed to benull
if and only ifpathStr
denotes an absolute path.- Returns:
- The resulting path.
- Throws:
NullPointerException
- If the path string denotes a relative path and the directory path isnull
.IllegalArgumentException
- If the path string isnull
or an empty string.InvalidPathException
- If the path string is invalid.
-
isZero
public static final boolean isZero(byte[] bytes, int offset, int len) throws NullPointerException, IndexOutOfBoundsException Finds out if all the bytes of the specified subarray of bytes are zero.- Parameters:
bytes
- The byte array to test, not allowed to benull
. The length of the array must be greater than or equal to the value ofoffset + len
. This method reads the elements with indicesoffset
,offset + 1
, ...,offset + len - 1
of the array. The other elements of the array remain untouched.offset
- The index withinbytes
where to start testing the bytes. The value must be greater than or equal to zero.len
- The number of bytes to test. The value must be greater than or equal to zero.- Returns:
- The boolean value
true
if the byte array has at least one byte and all bytes are equal 0,false
otherwise. - Throws:
NullPointerException
- Ifbytes
isnull
.IndexOutOfBoundsException
- If the condition described in thebytes
parameter description is not met.
-
bitCount
public static final int bitCount(byte[] bytes, int offset, int len) throws NullPointerException, IndexOutOfBoundsException Returns the number of one-bits in the specified subarray of bytes.- Parameters:
bytes
- The byte array, not allowed to benull
. The length of the array must be greater than or equal to the value ofoffset + len
. This method reads the elements with indicesoffset
,offset + 1
, ...,offset + len - 1
of the array. The other elements of the array remain untouched.offset
- The index withinbytes
where to start counting the one-bits. The value must be greater than or equal to zero.len
- The number of bytes. The value must be greater than or equal to zero.- Returns:
- The number of one-bits in the specified subarray of bytes.
- Throws:
NullPointerException
- Ifbytes
isnull
.IndexOutOfBoundsException
- If the condition described in thebytes
parameter description is not met.
-
hasNull
Finds out if at least one element of the specified array is equal tonull
.- Parameters:
arr
- The array to test, not allowed to benull
.- Returns:
- The boolean value
true
if at least one element of the specified array is equal tonull
,false
otherwise. - Throws:
NullPointerException
- Ifarr
isnull
.
-
equals
public static final boolean equals(byte[] arr1, byte[] arr2, int offset, int n) throws NullPointerException, IndexOutOfBoundsException Finds out ifarr1[k]
==arr2[k]
foroffset
≤k
<offset
+n
.- Parameters:
arr1
- The first byte array, not allowed to benull
. The array must contain at leastoffset
+n
bytes.arr2
- The second byte array, not allowed to benull
. The array must contain at leastoffset
+n
bytes.offset
- The index where to start the comparison.n
- The number of bytes to compare. Must be greater than or equal to zero.- Returns:
- The boolean value
true
if the specified arrays have equal byte values for all indices in the specified range,false
otherwise. - Throws:
NullPointerException
- Ifarr1
orarr2
isnull
.IndexOutOfBoundsException
- If the condition described in thearr1
orarr2
parameter description is not met.
-
unsToBytes
public static final byte[] unsToBytes(long val, int len) Converts the specified unsigned integer value of the specified length to a byte array of the same length.- Parameters:
val
- The value of the unsigned integer. The value must be greater than or equal to zero.len
- The length of the unsigned integer value in bytes. The value must be greater than 0 and less than or equal to 8.- Returns:
- The byte array of length
len
housing the converted unsigned integer. - Throws:
IndexOutOfBoundsException
- If the condition described in thelen
parameter description is not met.
-
unsToBytes
public static final void unsToBytes(long val, int len, byte[] bytes) throws NullPointerException, IndexOutOfBoundsException Converts the specified unsigned integer value of the specified length to a byte array and stores it into the specified byte array.Internally this method just calls the
unsToBytes(long, int, byte[], int)
method with the last parameter set to zero.- Parameters:
val
- The value of the unsigned integer. The value must be greater than or equal to zero.len
- The length of the unsigned integer value in bytes. The value must be greater than 0 and less than or equal to 8.bytes
- The byte array which houses the byte representation of the unsigned integer, not allowed to benull
. The length of the array must be greater than or equal to the value oflen
. This method sets the firstlen
elements of the array. The other elements of the array remain untouched.- Throws:
NullPointerException
- Ifbytes
isnull
.IndexOutOfBoundsException
- If the condition described in thebytes
parameter description is not met.
-
unsToBytes
public static final void unsToBytes(long val, int len, byte[] bytes, int offset) throws NullPointerException, IndexOutOfBoundsException Converts the specified unsigned integer value of the specified length to a byte array and stores it into the specified byte array starting at the specified offset.- Parameters:
val
- The value of the unsigned integer. The value must be greater than or equal to zero.len
- The length of the unsigned integer value in bytes. The value must be greater than 0 and less than or equal to 8.bytes
- The byte array which houses the byte representation of the unsigned integer, not allowed to benull
. The length of the array must be greater than or equal to the value ofoffset + len
. This method sets the elements with indicesoffset
,offset + 1
, ...,offset + len - 1
of the array. The other elements of the array remain untouched.offset
- The index withinbytes
where to start saving the result. The value must be greater than or equal to zero.- Throws:
NullPointerException
- Ifbytes
isnull
.IndexOutOfBoundsException
- If the condition described in thebytes
parameter description is not met.
-
unsFromBytes
public static final long unsFromBytes(byte[] bytes, int len) throws NullPointerException, IndexOutOfBoundsException Converts the specified byte array of the specified length to an unsigned integer value.Internally this method just calls the
unsFromBytes(byte[], int, int)
method with the second parameter set to zero.- Parameters:
bytes
- The byte array representing the unsigned integer value, not allowed to benull
. The length of the array must be greater than or equal to the value oflen
. This method reads the firstlen
elements of the array. The other elements of the array remain untouched.len
- The length of the unsigned integer in bytes. The value must be greater than 0 and less than or equal to 8.- Returns:
- The unsigned integer value.
- Throws:
NullPointerException
- Ifbytes
isnull
.IndexOutOfBoundsException
- If the condition described in thebytes
parameter description is not met.
-
unsFromBytes
public static final long unsFromBytes(byte[] bytes, int offset, int len) throws NullPointerException, IndexOutOfBoundsException Converts the specified byte subarray to an unsigned integer value.- Parameters:
bytes
- The byte array representing the unsigned integer value, not allowed to benull
. The length of the array must be greater than or equal to the value ofoffset + len
. This method reads the elements with indicesoffset
,offset + 1
, ...,offset + len - 1
of the array. The other elements of the array remain untouched.offset
- The index withinbytes
where to start reading the bytes of the unsigned integer. The value must be greater than or equal to zero.len
- The length of the unsigned integer in bytes. The value must be greater than 0 and less than or equal to 8.- Returns:
- The unsigned integer value.
- Throws:
NullPointerException
- Ifbytes
isnull
.IndexOutOfBoundsException
- If the condition described in thebytes
parameter description is not met.
-