public static <T> Stream<T> instancesOf(Stream<?> stream, Class<? extends T> clazz) {
    return stream.filter(clazz::isInstance).map(clazz::cast);
  }
Filters a stream for instances of a class and returns a typed stream
@param stream the stream to filter
@param clazz stream will be filtered to instances of this class
@param <T> the type of the class
@return A stream of containing only instances of {@link T}
ambari-server/src/main/java/org/apache/ambari/server/utils/StreamUtils.java