Skip to content

Commit

Permalink
ifNull multi argument
Browse files Browse the repository at this point in the history
  • Loading branch information
azum committed Apr 4, 2017
1 parent f4c2183 commit b8bcc3e
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions zen-core/src/main/java/com/nominanuda/zen/common/Check.java
Expand Up @@ -224,9 +224,18 @@ public long assertGtZero(long val) {
return val;
}

public static <T> T ifNull(T o, T defaultVal) {
return o == null ? defaultVal : o;
}
// public static <T> T ifNull(T o, T defaultVal) {
// return o == null ? defaultVal : o;
// }
@SafeVarargs
public static <T> T ifNull(T... objs) {
for (T obj : objs) {
if (obj != null) {
return obj;
}
}
return null;
}

public static <T> T ifNull(T o, Supplier<T> defaultVal) {
return o == null ? defaultVal.get() : o;
Expand Down

0 comments on commit b8bcc3e

Please sign in to comment.