code: public static <T> Collector<T, ?, Optional<T>> singleOrEmpty() {
  		return Collectors.collectingAndThen(Collectors.toList(),
  				lst -> lst.size() == 1 ? Optional.of(lst.get(0)) : Optional.empty());
  	}
docs: Collector which traverses a stream and returns either a single element
  (if there was only one element) or empty (if there were 0 or more than 1
  elements).  It traverses the entire stream, even if two elements
  have been encountered and the empty return value is now certain.
  <p>
  Implementation credit to Misha <a href="http://stackoverflow.com/a/26812693/1153071">on StackOverflow</a>.