public class Lambdas extends Object
Modifier and Type | Method and Description |
---|---|
static <K> Collector<K,Map<K,Integer>,Map<K,Integer>> |
groupAndCount()
Can be used to group a given stream by identity and count the occurrences of each entity.
|
static <T,C extends Collection<T>> |
into(C collection)
Used to collect the results of a stream operation into an existing collection.
|
static <T> Function<T,T> |
touch(Consumer<T> consumer)
Provides an identity function which permits to "touch" the element for which it was called.
|
static <O> O |
unsupportedBiOperation(O a,
O b)
Can be used as lambda for unsupported BiOperations.
|
public static <T> Function<T,T> touch(Consumer<T> consumer)
This is designed to be used with Optional
like this:
return Optional.of("Test").map(Lambdas.touch(s -> System.out.println(s)))
T
- the type of the elements accepted by the consumerconsumer
- the lambda used to "touch" (use) each parameterpublic static <T,C extends Collection<T>> Collector<T,?,C> into(C collection)
T
- the type of the elements accepted by the collectorC
- the type of the collection which is filled by the collectorcollection
- the target collectionCollector
inserting all elements into the given collectionpublic static <K> Collector<K,Map<K,Integer>,Map<K,Integer>> groupAndCount()
K
- the type of the key by which the values are groupedStream.collect(java.util.stream.Collector)
.public static <O> O unsupportedBiOperation(O a, O b)
This is intended to be a dummy parameter (e.g. for Collector.of. It will always throw an UnsupportedOperationException if invoked.
O
- the type of objects for which the operation is to be useda
- the first parameter of the binary operationb
- the second parameter of the binary operationUnsupportedOperationException
- always thrown by this methodCopyright © 2018. All rights reserved.