-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Expand file tree
/
Copy pathObjectUtils.java
More file actions
33 lines (25 loc) · 1018 Bytes
/
ObjectUtils.java
File metadata and controls
33 lines (25 loc) · 1018 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package com.reactnativenavigation.utils;
import com.reactnativenavigation.utils.Functions.Func1;
import com.reactnativenavigation.utils.Functions.FuncR1;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
public class ObjectUtils {
public static <T> void perform(@Nullable T obj, Func1<T> action) {
if (obj != null) action.run(obj);
}
public static <T, S> S perform(@Nullable T obj, S defaultValue, FuncR1<T, S> action) {
return obj == null ? defaultValue : action.run(obj);
}
public static <T> T take(@Nullable T obj, @NonNull T defaultValue) {
return obj == null ? defaultValue : obj;
}
public static <T> T getOrCreate(@Nullable T obj, @NonNull Functions.FuncR<T> creator) {
return obj == null ? creator.run() : obj;
}
public static boolean notNull(Object o) {
return o != null;
}
public static <T> boolean equalsNotNull(@Nullable T a, @Nullable T b) {
return a != null && a.equals(b);
}
}