All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.avegera.stream.utils.Lists Maven / Gradle / Ivy

Go to download

The library of laconic method-aliases for the safety Stream API operations on Java-collections

The newest version!
package io.github.avegera.stream.utils;

import java.util.Collection;
import java.util.Comparator;
import java.util.List;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Stream;

import static io.github.avegera.stream.utils.Streams.safeStream;
import static java.util.stream.Collectors.toList;

/**
 * The class contains laconic method-aliases for safety stream operations with collections in Java.
 * The result of class methods operations is {@link java.util.List}
 */
public class Lists {

    private Lists() {
        //empty private constructor
    }

    public static  List collect(Collection collection) {
        return safeStream(collection)
                .collect(toList());
    }

    public static  List distinct(Collection collection) {
        return safeStream(collection)
                .distinct()
                .collect(toList());
    }

    public static  List filter(Collection collection, Predicate predicate) {
        return safeStream(collection)
                .filter(predicate)
                .collect(toList());
    }

    public static  List flatMap(Collection collection, Function> flatMapper) {
        return safeStream(collection)
                .flatMap(flatMapper)
                .collect(toList());
    }

    public static  List flatMapCollections(Collection collection, Function> flatMapper) {
        return safeStream(collection)
                .flatMap(e -> safeStream(flatMapper.apply(e)))
                .collect(toList());
    }

    public static  List map(Collection collection, Function mapper) {
        return safeStream(collection)
                .map(mapper)
                .collect(toList());
    }

    public static  List sort(Collection collection, Comparator comparator) {
        return safeStream(collection)
                .sorted(comparator)
                .collect(toList());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy