Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MergeUtil -- 合并两个list中的属性 #2

Open
wave-gbt opened this issue Nov 15, 2018 · 0 comments
Open

MergeUtil -- 合并两个list中的属性 #2

wave-gbt opened this issue Nov 15, 2018 · 0 comments

Comments

@wave-gbt
Copy link

wave-gbt commented Nov 15, 2018

/**
     * 把 sourceList 的一些属性合并到 targetList 中
     * 基于 testFunction 的条件,合入逻辑实现为 biConsumer
     * @param targetList
     * @param sourceList
     * @param testFunction
     * @param biConsumer
     * @param <T>
     * @param <S>
     */
    public static <T, S> void merge(List<T> targetList, List<S> sourceList,
                                    BiFunction<? super T, ? super S,Boolean> testFunction,
                                    BiConsumer<? super T, ? super S> biConsumer) {
        targetList.forEach((t)->{
            Optional<S> optional = sourceList.stream().filter(s -> testFunction.apply(t,s)).findFirst();
            if (optional.isPresent()) {
                biConsumer.accept(t,optional.get());
            }
        });
    }
Repository owner deleted a comment from roneyfraga Mar 18, 2024
@github-staff github-staff deleted a comment from wenxingxing Mar 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants
@wave-gbt and others