public class EnumUtils {
public static <T, V, S> S getEnumProperty(T t, Function<T, V> function1, Function<V, S> function2) {
return getEnumProperty(t, function1, null, function2);
}
public static <T, V, S> S getEnumProperty(T t, Function<T, V> function1, V defaultEnum, Function<V, S> function2) {
if (t == null) {
return defaultEnum != null ? function2.apply(defaultEnum) : null;
}
V instance = function1.apply(t);
if (instance == null) {
return defaultEnum != null ? function2.apply(defaultEnum) : null;
}
S res = function2.apply(instance);
return res;
}
public static <T, V, S> List<S> getEnumProperty(List<T> list, Function<T, V> function1, Function<V, S> function2) {
List<S> res = new ArrayList<>();
if (list == null || list.size() == 0) {
return res;
}
for (T t : list) {
S s = null;
V instance = null;
if (t != null) {
instance = function1.apply(t);
}
if (instance != null) {
s = function2.apply(instance);
}
if (s != null) {
res.add(s);
}
}
return res;
}
}
EnumUtils 枚举工具类
最新推荐文章于 2023-08-22 05:00:00 发布