### Question:
Collectors { public static <T> Collector<T, ?, T> single() throws IllegalArgumentException { Supplier<T> thrower = () -> { throw new IllegalArgumentException( "No or more than one element in stream" ); }; return java.util.stream.Collectors.collectingAndThen( java.util.stream.Collectors.reducing( ( a, b ) -> null ), optional -> optional.orElseGet( thrower ) ); } private  Collectors(); static Collector<T, ?, T> single(); static Collector<T, ?, Optional<T>> singleOrEmpty(); static Collector<T, ?, Map<K, U>> toMap(); static Collector<T, ?, M> toMap( Supplier<M> mapSupplier ); static Collector<T, ?, M> toMap( Function<? super T, ? extends K> keyMapper,
                              Function<? super T, ? extends U> valueMapper,
                              Supplier<M> mapSupplier ); static Collector<T, ?, Map<K, U>> toMapWithNullValues(); static Collector<T, ?, M> toMapWithNullValues( Supplier<M> mapSupplier ); static Collector<T, ?, M> toMapWithNullValues( Function<? super T, ? extends K> keyMapper,
                                            Function<? super T, ? extends U> valueMapper,
                                            Supplier<M> mapSupplier );  }### Answer:
@Test public void single() { assertThat( Stream.of( 1L ).collect( Collectors.single() ), is( 1L ) ); try { Stream.of().collect( Collectors.single() ); fail( "Should have failed" ); } catch( IllegalArgumentException ex ) {} try { Stream.of( 1, 1 ).collect( Collectors.single() ); fail( "Should have failed" ); } catch( IllegalArgumentException ex ) {} try { Stream.of( 1, 1, 1 ).collect( Collectors.single() ); fail( "Should have failed" ); } catch( IllegalArgumentException ex ) {} }