code: public long single() {
          if (!iterator.hasNext()) {
              throw new NoSuchElementException("LongStream contains no element");
          }
  
          final long singleCandidate = iterator.nextLong();
          if (iterator.hasNext()) {
              throw new IllegalStateException("LongStream contains more than one element");
          }
          return singleCandidate;
      }
docs: Returns the single element of stream.
  If stream is empty, throws {@code NoSuchElementException}.
  If stream contains more than one element, throws {@code IllegalStateException}.
  
  <p>This is a short-circuiting terminal operation.
  
  <p>Example:
  <pre>
  stream: []
  result: NoSuchElementException
  
  stream: [1]
  result: 1
  
  stream: [1, 2, 3]
  result: IllegalStateException
  </pre>
  
  @return single element of stream
  @throws NoSuchElementException if stream is empty
  @throws IllegalStateException if stream contains more than one element