Skip to content

合并两个 list 中的元素属性 #1

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

Open
wave-gbt opened this issue Apr 28, 2019 · 0 comments
Open

合并两个 list 中的元素属性 #1

wave-gbt opened this issue Apr 28, 2019 · 0 comments

Comments

@wave-gbt
Copy link
Owner

wave-gbt commented Apr 28, 2019

/**
     * 把 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());
            }
        });
    }
@wave-gbt wave-gbt added enhancement New feature or request and removed enhancement New feature or request labels Apr 28, 2019
@wave-gbt wave-gbt changed the title 合并两个list中的元素属性 合并两个 list 中的元素属性 Apr 28, 2019
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

1 participant