public Optional<T> onlyOne() throws DuplicatedResultException, E {
        assertNotClosed();

        try {
            Optional<T> result = Optional.empty();

            if (elements.hasNext()) {
                result = Optional.of(elements.next());

                if (elements.hasNext()) {
                    throw new DuplicatedResultException("There are at least two elements: " + Strings.concat(result.get(), ", ", elements.next()));
                }
            }

            return result;
        } finally {
            close();
        }
    }
public Optional < T > onlyOne ( ) throws DuplicatedResultException , E { assertNotClosed ( ) ; try { Optional < T > result = Optional . empty ( ) ; if ( elements . hasNext ( ) ) { result = Optional . of ( elements . next ( ) ) ; if ( elements . hasNext ( ) ) { throw new DuplicatedResultException ( "There are at least two elements: " + Strings . concat ( result . get ( ) , ", " , elements . next ( ) ) ) ; } } return result ; } finally { close ( ) ; } }
@return
@throws DuplicatedResultException if there are more than one elements.
@throws E