Package common.utils
Class GenUtils
java.lang.Object
common.utils.GenUtils
Collection of general purpose utilities.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> List<T>
arrayToList
(T[] arr) Converts a templated array to a list.static void
assertEquals
(Object expected, Object actual) Asserts that the given values are equal.static void
assertEquals
(String failMsg, Object expected, Object actual) Asserts that the given values are equal.static void
assertFalse
(boolean val) Asserts that the given boolean is false.static void
assertFalse
(String failMsg, boolean val) Asserts that the given boolean is false.static void
assertNotEquals
(Object val1, Object val2) Asserts that the given values are not equal.static void
assertNotEquals
(String failMsg, Object val1, Object val2) Asserts that the given values are not equal.static void
assertNotNull
(Object val) Asserts that the given value is not null.static void
assertNotNull
(String failMsg, Object val) Asserts that the given value is not null.static void
assertNull
(Object val) Asserts that the given value is null.static void
assertNull
(String failMsg, Object val) Asserts that the given value is null.static void
assertTrue
(boolean val) Asserts that the given boolean is true.static void
assertTrue
(String failMsg, boolean val) Asserts that the given boolean is true.static void
executeTasks
(Collection<Runnable> tasks) Execute tasks in parallel.static void
executeTasks
(Collection<Runnable> tasks, int maxConcurrency) Execute tasks in parallel.<T> List<T>
executeTasks
(List<Callable<T>> tasks) Execute tasks in parallel.<T> List<T>
executeTasks
(List<Callable<T>> tasks, int maxConcurrency) Execute tasks in parallel.static String
getIndent
(int length) Returns a string indentation of the given length;static String
getUUID()
Generates a UUID.static boolean
Indicates if the given argument is a hexidemal string.static String
Returns a human-friendly key value line.static String
Returns a human-friendly key value line.static byte[]
listToByteArray
(List<Byte> list) Converts a list of integers to an int array.static int[]
listToIntArray
(List<Integer> list) Converts a list of integers to an int array.static <T> T
reconcile
(T val1, T val2) Convenience method to reconcile two values with default configuration by calling reconcile(val1, val2, null, null, null).static <T> T
Reconciles two values.static byte[]
reconcileByteArrays
(byte[] arr1, byte[] arr2) Reconciles two byte arrays.static int[]
reconcileIntArrays
(int[] arr1, int[] arr2) Reconciles two int arrays.static int[]
subarray
(int[] array, int startIndexInclusive, int endIndexExclusive) Produces a new array containing the elements between the start and end indices.static void
waitFor
(long durationMs) Wait for the duration.
-
Constructor Details
-
GenUtils
public GenUtils()
-
-
Method Details
-
assertTrue
public static void assertTrue(boolean val) Asserts that the given boolean is true.- Parameters:
val
- is the boolean to assert as true
-
assertTrue
Asserts that the given boolean is true.- Parameters:
failMsg
- is the failure message if the booelean is not trueval
- is the boolean to assert as true
-
assertFalse
public static void assertFalse(boolean val) Asserts that the given boolean is false.- Parameters:
val
- is the boolean to assert as false
-
assertFalse
Asserts that the given boolean is false.- Parameters:
failMsg
- is the failure message if the booelean is not falseval
- is the boolean to assert as false
-
assertNull
Asserts that the given value is null.- Parameters:
val
- is the value to assert as null
-
assertNull
Asserts that the given value is null.- Parameters:
failMsg
- is the failure message if the value is not nullval
- is the value to assert as null
-
assertNotNull
Asserts that the given value is not null.- Parameters:
val
- is the value to assert as not null
-
assertNotNull
Asserts that the given value is not null.- Parameters:
failMsg
- is the failure message if the value is nullval
- is the value to assert as not null
-
assertEquals
Asserts that the given values are equal. Throws an exception if not equal.- Parameters:
expected
- is the expected value to assert as equalactual
- is the actual value to assert as equal
-
assertEquals
Asserts that the given values are equal. Throws an exception if not equal.- Parameters:
failMsg
- is the failure message if the values are not equalexpected
- is the expected value to assert as equalactual
- is the actual value to assert as equal
-
assertNotEquals
Asserts that the given values are not equal. Throws an exception if equal.- Parameters:
val1
- is a value to assert as not equalval2
- is a value to assert as not equal
-
assertNotEquals
Asserts that the given values are not equal. Throws an exception if equal.- Parameters:
failMsg
- is the failure message if the values are equalval1
- is a value to assert as not equalval2
- is a value to assert as not equal
-
isHex
Indicates if the given argument is a hexidemal string.- Parameters:
str
- is the string to test- Returns:
- true if the given string is hexidecimal, false otherwise
-
arrayToList
Converts a templated array to a list.- Type Parameters:
T
- templated type- Parameters:
arr
- is an array of type T to convert to a list- Returns:
- the array converted to a list
-
listToIntArray
Converts a list of integers to an int array.- Parameters:
list
- is the list to convert- Returns:
- the int array
-
listToByteArray
Converts a list of integers to an int array.- Parameters:
list
- is the list to convert- Returns:
- the int array
-
getIndent
Returns a string indentation of the given length;- Parameters:
length
- is the length of the indentation- Returns:
- an indentation string of the given length
-
subarray
public static int[] subarray(int[] array, int startIndexInclusive, int endIndexExclusive) Produces a new array containing the elements between the start and end indices.Code from Apache Commons Lang.
- Parameters:
array
- is the array to derive a subarray fromstartIndexInclusive
- is the start index of the subarray, inclusiveendIndexExclusive
- is the end index of the subarray, exclusive- Returns:
- the subarray
-
reconcile
public static <T> T reconcile(T val1, T val2) Convenience method to reconcile two values with default configuration by calling reconcile(val1, val2, null, null, null).- Type Parameters:
T
- templated type- Parameters:
val1
- is a value to reconcileval2
- is a value to reconcile- Returns:
- the reconciled value if reconcilable, throws exception otherwise
-
reconcile
public static <T> T reconcile(T val1, T val2, Boolean resolveDefined, Boolean resolveTrue, Boolean resolveMax) Reconciles two values.- Type Parameters:
T
- templated type- Parameters:
val1
- is a value to reconcileval2
- is a value to reconcileresolveDefined
- uses defined value if true or null, null if falseresolveTrue
- uses true over false if true, false over true if false, must be equal if nullresolveMax
- uses max over min if true, min over max if false, must be equal if null- Returns:
- the reconciled value if reconcilable, throws exception otherwise
-
reconcileIntArrays
public static int[] reconcileIntArrays(int[] arr1, int[] arr2) Reconciles two int arrays. The arrays must be identical or an exception is thrown.- Parameters:
arr1
- is an array to reconcilearr2
- is an array to reconcile- Returns:
- int[] is the reconciled array
-
reconcileByteArrays
public static byte[] reconcileByteArrays(byte[] arr1, byte[] arr2) Reconciles two byte arrays. The arrays must be identical or an exception is thrown.- Parameters:
arr1
- is an array to reconcilearr2
- is an array to reconcile- Returns:
- byte[] is the reconciled array
-
kvLine
Returns a human-friendly key value line.- Parameters:
key
- is the keyvalue
- is the valueindent
- indents the line- Returns:
- the human-friendly key value line
-
kvLine
public static String kvLine(Object key, Object value, int indent, boolean newline, boolean ignoreUndefined) Returns a human-friendly key value line.- Parameters:
key
- is the keyvalue
- is the valueindent
- indents the linenewline
- specifies if the string should be terminated with a newline or notignoreUndefined
- specifies if undefined values should return an empty string- Returns:
- the human-friendly key value line
-
getUUID
Generates a UUID.- Returns:
- the UUID
-
waitFor
public static void waitFor(long durationMs) Wait for the duration.- Parameters:
durationMs
- the duration to wait for in milliseconds
-
executeTasks
Execute tasks in parallel.- Parameters:
tasks
- are tasks to execute in parallel
-
executeTasks
Execute tasks in parallel.- Parameters:
tasks
- are tasks to execute in parallelmaxConcurrency
- the maximum number of tasks to run in parallel
-
executeTasks
public <T> List<T> executeTasks(List<Callable<T>> tasks) throws InterruptedException, ExecutionException Execute tasks in parallel.- Type Parameters:
T
- parameterized type- Parameters:
tasks
- the tasks to execute in parallel- Returns:
- the results of each task
- Throws:
InterruptedException
ExecutionException
-
executeTasks
public <T> List<T> executeTasks(List<Callable<T>> tasks, int maxConcurrency) throws InterruptedException, ExecutionException Execute tasks in parallel.- Type Parameters:
T
- parameterized type- Parameters:
tasks
- the tasks to execute in parallelmaxConcurrency
- the maximum number of tasks to run in parallel- Returns:
- the results of each task
- Throws:
InterruptedException
ExecutionException
-