package com.hfkj.common.utils;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;
import java.util.function.Predicate;

/**
 *
 * @ClassName:  StreamUtil
 * @Description:TODO(List Steam)
 * @author: 胡锐
 * @date:   2019年3月25日 下午4:14:00
 *
 
 */
public class StreamUtil {

    /**
     *
     * @Title: distinctByKey
     * @Description: TODO(对象 去重)
     * @author: 胡锐
     * @param: @param keyExtractor
     * @param: @return
     * @return: Predicate<T>
     * @throws
     */
    public static <T> Predicate<T> distinctByKey(Function<? super T, ?> keyExtractor) {
        Map<Object,Boolean> seen = new ConcurrentHashMap<>();
        return t -> seen.putIfAbsent(keyExtractor.apply(t), Boolean.TRUE) == null;
    }

}
