Created
July 27, 2018 20:22
-
-
Save unrelentingfox/844e4bc7da0eb15be0aba2b3889bc167 to your computer and use it in GitHub Desktop.
Useful java safe comparison helper functions
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
private static boolean safeEquals(Integer first, Integer second) { | |
return (first == null && second == null) || (first != null && first.equals(second)); | |
} | |
private static boolean safeContains(String str, String substr) { | |
return str != null && str.contains(substr); | |
} | |
private static <K> List<K> safe(List<K> list) { | |
return list != null ? list : Collections.EMPTY_LIST; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment