Class Utils

java.lang.Object
dev.comfast.util.Utils

public class Utils extends Object
  • Constructor Details

    • Utils

      public Utils()
  • Method Details

    • sleep

      public static void sleep(long ms)
      Unchecked sleep. Checked InterruptedException is wrapped into RuntimeException.
    • trimString

      public static String trimString(Object input, int maxLength)
      Parameters:
      input - string or object
      maxLength - max length of result string
      Returns:
      First characters from input string
    • isNullOrEmpty

      public static boolean isNullOrEmpty(Object anyString)
      Can pass any object to check, it will be converted to string.
      Returns:
      true if string/object is null or its toString() is empty
    • transposeMatrix

      public static <T> List<List<T>> transposeMatrix(List<List<T>> matrix)
      Parameters:
      matrix - list of lists eg.
      
         ["1", "2", "3", "4"],
         ["5", "6", "7", "8"]
       
      Returns:
      transposed list of lists, eg.
      
         ["1", "5"],
         ["2", "6"],
         ["3", "7"],
         ["4", "8"],
       
    • withSystemProp

      public static void withSystemProp(String systemPropertyName, Runnable func)
      Restore system property after func is done. It's safe to edit it inside given function, for test purposes or any other. e.g.
      
           // here "my.timeout" is 3000
           withSystemProp("my.timeout", () -> {
               System.setProperty("my.timeout", "0");
               doSomeTests();
           })
           // here "my.timeout" is restored to 3000
       
      Parameters:
      func - within this function can edit system prop freely without side effects for the rest of the code }
    • isTruthly

      public static boolean isTruthly(Object input)
      Parameters:
      input - any object
      Returns:
      false if null, false, 0, trimmed empty string
    • readResourceFile

      public static String readResourceFile(String resourcePath)
      Read resource file content.
      Parameters:
      resourcePath - e.g. fileNAme.txt or some/folder/file.txt
      Returns:
      file content