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

internal.sdmxdl.desktop.Collectors2 Maven / Gradle / Ivy

The newest version!
package internal.sdmxdl.desktop;

import java.util.List;
import java.util.Optional;
import java.util.stream.Collector;

import static java.util.stream.Collectors.collectingAndThen;
import static java.util.stream.Collectors.toList;

public final class Collectors2 {

    private Collectors2() {
        throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
    }

    public static  Collector> single() {
        return collectingAndThen(toList(), Collectors2::getSingle);
    }

    public static  Optional getSingle(List list) {
        return list.size() == 1 ? Optional.ofNullable(list.get(0)) : Optional.empty();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy