# Conflicts: # v1/src/main/resources/prod/application.ymldev-discount
commit
57767f3b2a
@ -0,0 +1,34 @@ |
|||||||
|
package com.hai.config; |
||||||
|
|
||||||
|
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; |
||||||
|
} |
||||||
|
|
||||||
|
} |
Loading…
Reference in new issue