Class GenUtils

java.lang.Object
zephyr.lib.utils.GenUtils

public class GenUtils extends Object
Collection of general purpose utilities.
  • Constructor Summary

    Constructors
    Constructor
    Description
    The implicit public constructor, made explicit to document it: every member is static.
  • Method Summary

    Modifier and Type
    Method
    Description
    static <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
    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
    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
    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 String
    binToHex(byte[] bytes)
    Encodes bytes as a lowercase hexadecimal string, two characters per byte.
    static void
    Execute tasks in parallel.
    static void
    executeTasks(Collection<Runnable> tasks, int maxConcurrency)
    Execute tasks in parallel.
    static String
    getIndent(int length)
    Returns a string indentation of the given length;
    static String
    Generates a UUID.
    static boolean
    Indicates if the given argument is a hexidemal string.
    static String
    kvLine(Object key, Object value, int indent)
    Returns a human-friendly key value line.
    static String
    kvLine(Object key, Object value, int indent, boolean newline, boolean ignoreUndefined)
    Returns a human-friendly key value line.
    static int[]
    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
    reconcile(T val1, T val2, Boolean resolveDefined, Boolean resolveTrue, Boolean resolveMax)
    Reconciles two values.
    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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • GenUtils

      public GenUtils()
      The implicit public constructor, made explicit to document it: every member is static.
  • 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
    • binToHex

      public static String binToHex(byte[] bytes)
      Encodes bytes as a lowercase hexadecimal string, two characters per byte.
      Parameters:
      bytes - are the bytes to encode
      Returns:
      the hexadecimal string
    • 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 ot 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:
      T[] 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 - is the duration to wait for in milliseconds
    • executeTasks

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

      public static void executeTasks(Collection<Runnable> tasks, int maxConcurrency)
      Execute tasks in parallel.
      Parameters:
      tasks - are the tasks to execute in parallel
      maxConcurrency - is the maximum number of tasks to run in parallel