public static <E extends Document> Optional<E> ancestor(
            final Document document,
            final Class<E> clazz) {
        
        requireNonNull(document);
        requireNonNull(clazz);
        return document.ancestors()
            .filter(clazz::isInstance)
            .map(clazz::cast)
            .findFirst();
    }
Returns the first ancestor found of the specified type to the specified
document when walking up the tree. If there was no ancestor of the
specified type and the root was reached, an empty {@code Optional} is
returned.

@param <E>       ancestor type
@param document  the starting point
@param clazz     the ancestor type to look for
@return          first ancestor found or empty
runtime-parent/runtime-config/src/main/java/com/speedment/runtime/config/util/DocumentUtil.java