Last active
March 23, 2023 14:22
-
-
Save zencd/b2035b1249bcf6e376a9defb29ee0c8e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static boolean match(@Nullable Pattern pattern, @Nullable String input) { | |
if (pattern == null || input == null) { | |
return false; | |
} | |
return pattern.matcher(input).matches(); | |
} | |
@Nullable | |
public static String toStr(@Nullable Object value) { | |
return (value != null) ? value.toString() : null; | |
} | |
public static <T> Stream<T> safeStream(@Nullable T[] array) { | |
if (array == null || array.length == 0) { | |
return Stream.empty(); | |
} else { | |
return Arrays.stream(array); | |
} | |
} | |
public static int toInt(Integer value, int fallback) { | |
return value != null ? value : fallback; | |
} | |
@Nullable | |
public static <T> T first(@Nullable Collection<T> collection) { | |
if (collection == null) { | |
return null; | |
} | |
for (T elem : collection) { | |
return elem; | |
} | |
return null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment