io.github.avegera.stream.utils.Iterators Maven / Gradle / Ivy
Show all versions of stream-utils Show documentation
package io.github.avegera.stream.utils;
import java.util.Collection;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.Function;
import static io.github.avegera.stream.utils.Streams.safeStream;
/**
* For-each iterators method-aliases.
*
* The class contains laconic method-aliases for safe iteration through the collections in Java.
* The result of class methods operations is {@link java.lang.Void}.
*/
public class Iterators {
private Iterators() {
//empty private constructor
}
public static void forEach(Collection collection, Consumer consumer) {
safeStream(collection)
.forEach(consumer);
}
public static void setForEach(Collection collection, BiConsumer setter, Function valueExtractor) {
safeStream(collection)
.forEach(item -> setter.accept(item, valueExtractor.apply(item)));
}
public static void setValueForEach(Collection collection, BiConsumer setter, R value) {
safeStream(collection)
.forEach(item -> setter.accept(item, value));
}
//TODO: ADR whe different naming
}