common/src/main/java/org/jboss/pnc/common/util/StreamCollectors.java
public static <T> Collector<T, List<T>, T> singletonCollector() {
        return Collector.of(
                ArrayList::new,
                List::add,
                (left, right) -> {
                    left.addAll(right);
                    return left;
                },
                list -> {
                    if (list.size() == 0) {
                        return null;
                    }
                    if (list.size() > 1) {
                        throw new IllegalStateException();
                    }
                    return list.get(0);
                }
        );
    }
public static <T> Collector<T, List<T>, T> singletonCollector() {
        return Collector.of(
                ArrayList::new,
                List::add,
                (left, right) -> {
                    left.addAll(right);
                    return left;
                },
                list -> {
                    if (list.size() == 0) {
                        return null;
                    }
                    if (list.size() > 1) {
                        throw new IllegalStateException();
                    }
                    return list.get(0);
                }
        );
    }
public static < T > Collector < T , List < T > , T > singletonCollector ( ) { return Collector . of ( ArrayList :: new , List :: add , ( left , right ) -> { left . addAll ( right ) ; return left ; } , list -> { if ( list . size ( ) == 0 ) { return null ; } if ( list . size ( ) > 1 ) { throw new IllegalStateException ( ) ; } return list . get ( 0 ) ; } ) ; }
Collect element(s) into a list and then return the single element of this list.
If there is not exactly one element, throw an exception.
@param <T> module config
@return
Collect element ( s ) into a list and then return the single element of this list . If there is not exactly one element throw an exception .