9 天以前 84e29c9adb718b42a693e954d2b771651ef36796
yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/collection/CollectionUtils.java
@@ -17,7 +17,7 @@
/**
 * Collection 工具类
 *
 * @author 芋道源码
 * @author 超级管理员
 */
public class CollectionUtils {
@@ -122,6 +122,22 @@
            return new HashSet<>();
        }
        return from.stream().filter(filter).map(func).filter(Objects::nonNull).collect(Collectors.toSet());
    }
    public static <T, U> Set<U> convertLinkedSet(Collection<T> from, Function<T, U> func) {
        if (CollUtil.isEmpty(from)) {
            return new LinkedHashSet<>();
        }
        return from.stream().map(func).filter(Objects::nonNull)
                .collect(Collectors.toCollection(LinkedHashSet::new));
    }
    public static <T, U> Set<U> convertLinkedSet(Collection<T> from, Function<T, U> func, Predicate<T> filter) {
        if (CollUtil.isEmpty(from)) {
            return new LinkedHashSet<>();
        }
        return from.stream().filter(filter).map(func).filter(Objects::nonNull)
                .collect(Collectors.toCollection(LinkedHashSet::new));
    }
    public static <T, K> Map<K, T> convertMapByFilter(Collection<T> from, Predicate<T> filter, Function<T, K> keyFunc) {
@@ -372,4 +388,14 @@
        return false;
    }
    /**
     * 把单元素 head 与集合 tail 合并成新 List(head 在前,tail 顺序保留)
     */
    public static <T> List<T> of(T head, Collection<T> tail) {
        List<T> list = new ArrayList<>();
        list.add(head);
        CollUtil.addAll(list, tail);
        return list;
    }
}