All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.penglecode.codeforce.common.util.StreamUtils Maven / Gradle / Ivy

The newest version!
package com.penglecode.codeforce.common.util;

import java.util.function.BinaryOperator;

/**
 * Java8 Stream工具类
 *
 * @author pengpeng
 * @version 1.0
 */
public class StreamUtils {

    private StreamUtils() {}

    /**
     * 针对Collectors.toMap(Function keyMapper, Function valueMapper, BinaryOperator mergeFunction)方法的第三个参数mergeFunction的工具类,
     * 该preferNewMergeFunction()方法返回的Lambda表达式返回倾向于新的那个value值
     *
     * @param 
     * @return
     */
    public static  BinaryOperator preferNew() {
        return (oldValue, newValue) -> newValue;
    }

    /**
     * 针对Collectors.toMap(Function keyMapper, Function valueMapper, BinaryOperator mergeFunction)方法的第三个参数mergeFunction的工具类,
     * 该preferOldMergeFunction()方法返回的Lambda表达式返回倾向于旧的那个value值
     *
     * @param 
     * @return
     */
    public static  BinaryOperator preferOld() {
        return (oldValue, newValue) -> newValue;
    }

}