Class CustomCollectors
- java.lang.Object
-
- gov.nist.secauto.metaschema.core.util.CustomCollectors
-
public final class CustomCollectors extends Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
CustomCollectors.DuplicateHandler<K,V>
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <V,K>
Stream<V>distinctByKey(Stream<V> stream, Function<? super V,? extends K> keyMapper)
Produce a new stream with duplicates removed based on the providedkeyMapper
.static <V,K>
Stream<V>distinctByKey(Stream<V> stream, Function<? super V,? extends K> keyMapper, CustomCollectors.DuplicateHandler<K,V> duplicateHander)
Produce a new stream with duplicates removed based on the providedkeyMapper
.static <T> Function<T,T>
identity()
static Collector<CharSequence,?,String>
joiningWithOxfordComma(String conjunction)
static <T,K,V>
Collector<T,?,Map<K,V>>toMap(Function<? super T,? extends K> keyMapper, Function<? super T,? extends V> valueMapper, CustomCollectors.DuplicateHandler<K,V> duplicateHander)
static <T,K,V,M extends Map<K,V>>
Collector<T,?,M>toMap(Function<? super T,? extends K> keyMapper, Function<? super T,? extends V> valueMapper, CustomCollectors.DuplicateHandler<K,V> duplicateHander, Supplier<M> supplier)
static <T> BinaryOperator<T>
useFirstMapper()
static <T> BinaryOperator<T>
useLastMapper()
-
-
-
Method Detail
-
joiningWithOxfordComma
public static Collector<CharSequence,?,String> joiningWithOxfordComma(@NonNull String conjunction)
-
distinctByKey
public static <V,K> Stream<V> distinctByKey(@NonNull Stream<V> stream, @NonNull Function<? super V,? extends K> keyMapper)
Produce a new stream with duplicates removed based on the providedkeyMapper
. When a duplicate key is encountered, the second item is used. The original sequencing is preserved if the input stream is sequential.- Type Parameters:
V
- the item value for the streamsK
- the key type- Parameters:
stream
- the stream to reducekeyMapper
- the key function to use to find unique items- Returns:
- a new stream
-
distinctByKey
public static <V,K> Stream<V> distinctByKey(@NonNull Stream<V> stream, @NonNull Function<? super V,? extends K> keyMapper, @NonNull CustomCollectors.DuplicateHandler<K,V> duplicateHander)
Produce a new stream with duplicates removed based on the providedkeyMapper
. When a duplicate key is encountered, the providedduplicateHandler
is used to determine which item to keep. The original sequencing is preserved if the input stream is sequential.- Type Parameters:
V
- the item value for the streamsK
- the key type- Parameters:
stream
- the stream to reducekeyMapper
- the key function to use to find unique itemsduplicateHander
- used to determine which of two duplicates to keep- Returns:
- a new stream
-
toMap
@NonNull public static <T,K,V> Collector<T,?,Map<K,V>> toMap(@NonNull Function<? super T,? extends K> keyMapper, @NonNull Function<? super T,? extends V> valueMapper, @NonNull CustomCollectors.DuplicateHandler<K,V> duplicateHander)
-
toMap
@NonNull public static <T,K,V,M extends Map<K,V>> Collector<T,?,M> toMap(@NonNull Function<? super T,? extends K> keyMapper, @NonNull Function<? super T,? extends V> valueMapper, @NonNull CustomCollectors.DuplicateHandler<K,V> duplicateHander, Supplier<M> supplier)
-
useFirstMapper
@NonNull public static <T> BinaryOperator<T> useFirstMapper()
-
useLastMapper
@NonNull public static <T> BinaryOperator<T> useLastMapper()
-
-