| | |
| | | import cn.hutool.core.collection.CollectionUtil; |
| | | import cn.hutool.core.util.ArrayUtil; |
| | | import com.google.common.collect.ImmutableMap; |
| | | import com.iailab.framework.common.pojo.PageResult; |
| | | |
| | | import java.util.*; |
| | | import java.util.function.*; |
| | |
| | | return new ArrayList<>(); |
| | | } |
| | | return from.stream().filter(filter).map(func).filter(Objects::nonNull).collect(Collectors.toList()); |
| | | } |
| | | |
| | | public static <T, U> PageResult<U> convertPage(PageResult<T> from, Function<T, U> func) { |
| | | if (ArrayUtil.isEmpty(from)) { |
| | | return new PageResult<>(from.getTotal()); |
| | | } |
| | | return new PageResult<>(convertList(from.getList(), func), from.getTotal()); |
| | | } |
| | | |
| | | public static <T, U> List<U> convertListByFlatMap(Collection<T> from, |
| | |
| | | return valueFunc.apply(t); |
| | | } |
| | | |
| | | public static <T, V extends Comparable<? super V>> V getSumValue(List<T> from, Function<T, V> valueFunc, |
| | | public static <T, V extends Comparable<? super V>> T getMinObject(List<T> from, Function<T, V> valueFunc) { |
| | | if (CollUtil.isEmpty(from)) { |
| | | return null; |
| | | } |
| | | assert from.size() > 0; // 断言,避免告警 |
| | | return from.stream().min(Comparator.comparing(valueFunc)).get(); |
| | | } |
| | | |
| | | public static <T, V extends Comparable<? super V>> V getSumValue(Collection<T> from, Function<T, V> valueFunc, |
| | | BinaryOperator<V> accumulator) { |
| | | return getSumValue(from, valueFunc, accumulator, null); |
| | | } |
| | |
| | | } |
| | | |
| | | public static <T> List<T> newArrayList(List<List<T>> list) { |
| | | return list.stream().flatMap(Collection::stream).collect(Collectors.toList()); |
| | | return list.stream().filter(Objects::nonNull).flatMap(Collection::stream).collect(Collectors.toList()); |
| | | } |
| | | |
| | | } |