Package dev.comfast.util
Class Utils
java.lang.Object
dev.comfast.util.Utils
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanisNullOrEmpty(Object anyString) Can pass any object to check, it will be converted to string.static booleanstatic StringreadResourceFile(String resourcePath) Read resource file content.static voidsleep(long ms) Unchecked sleep.transposeMatrix(List<List<T>> matrix) static StringtrimString(Object input, int maxLength) static voidwithSystemProp(String systemPropertyName, Runnable func) Restore system property after func is done.
-
Constructor Details
-
Utils
public Utils()
-
-
Method Details
-
sleep
public static void sleep(long ms) Unchecked sleep. CheckedInterruptedExceptionis wrapped intoRuntimeException. -
trimString
- Parameters:
input- string or objectmaxLength- max length of result string- Returns:
- First characters from input string
-
isNullOrEmpty
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
- 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
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
- Parameters:
input- any object- Returns:
- false if null, false, 0, trimmed empty string
-
readResourceFile
Read resource file content.- Parameters:
resourcePath- e.g. fileNAme.txt or some/folder/file.txt- Returns:
- file content
-