You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
862 B
34 lines
862 B
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
|
|
*
|
|
* @Copyright: 2019 www.shinwoten.com Inc. All rights reserved.
|
|
*/
|
|
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;
|
|
}
|
|
|
|
}
|
|
|