Package common.utils

Class GenUtils

java.lang.Object
common.utils.GenUtils

public class GenUtils extends Object
Collection of general purpose utilities.
  • 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

      public static void assertTrue(String failMsg, boolean val)
      Asserts that the given boolean is true.
      Parameters:
      failMsg - is the failure message if the booelean is not true
      val - 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

      public static void assertFalse(String failMsg, boolean val)
      Asserts that the given boolean is false.
      Parameters:
      failMsg - is the failure message if the booelean is not false
      val - is the boolean to assert as false
    • assertNull

      public static void assertNull(Object val)
      Asserts that the given value is null.
      Parameters:
      val - is the value to assert as null
    • assertNull

      public static void assertNull(String failMsg, Object val)
      Asserts that the given value is null.
      Parameters:
      failMsg - is the failure message if the value is not null
      val - is the value to assert as null
    • assertNotNull

      public static void assertNotNull(Object val)
      Asserts that the given value is not null.
      Parameters:
      val - is the value to assert as not null
    • assertNotNull

      public static void assertNotNull(String failMsg, Object val)
      Asserts that the given value is not null.
      Parameters:
      failMsg - is the failure message if the value is null
      val - is the value to assert as not null
    • assertEquals

      public static void assertEquals(Object expected, Object actual)
      Asserts that the given values are equal. Throws an exception if not equal.
      Parameters:
      expected - is the expected value to assert as equal
      actual - is the actual value to assert as equal
    • assertEquals

      public static void assertEquals(String failMsg, Object expected, Object actual)
      Asserts that the given values are equal. Throws an exception if not equal.
      Parameters:
      failMsg - is the failure message if the values are not equal
      expected - is the expected value to assert as equal
      actual - is the actual value to assert as equal
    • assertNotEquals

      public static void assertNotEquals(Object val1, Object val2)
      Asserts that the given values are not equal. Throws an exception if equal.
      Parameters:
      val1 - is a value to assert as not equal
      val2 - is a value to assert as not equal
    • assertNotEquals

      public static void assertNotEquals(String failMsg, Object val1, Object val2)
      Asserts that the given values are not equal. Throws an exception if equal.
      Parameters:
      failMsg - is the failure message if the values are equal
      val1 - is a value to assert as not equal
      val2 - is a value to assert as not equal
    • isHex

      public static boolean isHex(String str)
      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

      public static <T> List<T> arrayToList(T[] arr)
      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

      public static int[] listToIntArray(List<Integer> list)
      Converts a list of integers to an int array.
      Parameters:
      list - is the list to convert
      Returns:
      the int array
    • listToByteArray

      public static byte[] listToByteArray(List<Byte> list)
      Converts a list of integers to an int array.
      Parameters:
      list - is the list to convert
      Returns:
      the int array
    • getIndent

      public static String getIndent(int length)
      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 from
      startIndexInclusive - is the start index of the subarray, inclusive
      endIndexExclusive - 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 reconcile
      val2 - 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 reconcile
      val2 - is a value to reconcile
      resolveDefined - uses defined value if true or null, null if false
      resolveTrue - uses true over false if true, false over true if false, must be equal if null
      resolveMax - 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 reconcile
      arr2 - 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 reconcile
      arr2 - is an array to reconcile
      Returns:
      byte[] is the reconciled array
    • kvLine

      public static String kvLine(Object key, Object value, int indent)
      Returns a human-friendly key value line.
      Parameters:
      key - is the key
      value - is the value
      indent - 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 key
      value - is the value
      indent - indents the line
      newline - specifies if the string should be terminated with a newline or not
      ignoreUndefined - specifies if undefined values should return an empty string
      Returns:
      the human-friendly key value line
    • getUUID

      public static String 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

      public static void executeTasks(Collection<Runnable> tasks)
      Execute tasks in parallel.
      Parameters:
      tasks - are tasks to execute in parallel
    • executeTasks

      public static void executeTasks(Collection<Runnable> tasks, int maxConcurrency)
      Execute tasks in parallel.
      Parameters:
      tasks - are tasks to execute in parallel
      maxConcurrency - 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 parallel
      maxConcurrency - the maximum number of tasks to run in parallel
      Returns:
      the results of each task
      Throws:
      InterruptedException
      ExecutionException