@Test public void testSingletonOptionalCollector() throws Exception { assertEquals("1", asList("1").stream().collect(singletonOptionalCollector()).get()); assertFalse(new ArrayList<String>().stream().collect(singletonOptionalCollector()).isPresent()); }
public static <T> Collector<T, List<T>, Optional<T>> singletonOptionalCollector() { return Collector.of( ArrayList::new, List::add, (left, right) -> left, list -> list.isEmpty() ? Optional.empty() : Optional.of(list.get(0)) ); }
StreamUtils { public static <T> Collector<T, List<T>, Optional<T>> singletonOptionalCollector() { return Collector.of( ArrayList::new, List::add, (left, right) -> left, list -> list.isEmpty() ? Optional.empty() : Optional.of(list.get(0)) ); } }
StreamUtils { public static <T> Collector<T, List<T>, Optional<T>> singletonOptionalCollector() { return Collector.of( ArrayList::new, List::add, (left, right) -> left, list -> list.isEmpty() ? Optional.empty() : Optional.of(list.get(0)) ); }  }
StreamUtils { public static <T> Collector<T, List<T>, Optional<T>> singletonOptionalCollector() { return Collector.of( ArrayList::new, List::add, (left, right) -> left, list -> list.isEmpty() ? Optional.empty() : Optional.of(list.get(0)) ); }  static Collector<T, List<T>, Optional<T>> singletonOptionalCollector(); static Collector<T, List<T>, T> singletonCollector(); static List<T> iteratorToList(Iterator<T> iterator); }
StreamUtils { public static <T> Collector<T, List<T>, Optional<T>> singletonOptionalCollector() { return Collector.of( ArrayList::new, List::add, (left, right) -> left, list -> list.isEmpty() ? Optional.empty() : Optional.of(list.get(0)) ); }  static Collector<T, List<T>, Optional<T>> singletonOptionalCollector(); static Collector<T, List<T>, T> singletonCollector(); static List<T> iteratorToList(Iterator<T> iterator);  }