package com.qianwen.smartman.common.utils; import java.util.concurrent.ConcurrentHashMap; import java.util.function.Function; import java.util.function.Predicate; public final class DistinctKeyUtil { private DistinctKeyUtil() { throw new UnsupportedOperationException("This is a utility class and cannot be instantiated"); } public static Predicate distinctByKey(Function keyExtractor) { ConcurrentHashMap map = new ConcurrentHashMap<>(16); return t -> { return map.putIfAbsent(keyExtractor.apply(t), Boolean.TRUE) == null; }; } }