Class KiwiStreams


  • public final class KiwiStreams
    extends Object
    Utilities related to Streams that are not already in the JDKs Stream or Guava's Streams.
    • Constructor Detail

      • KiwiStreams

        public KiwiStreams()
    • Method Detail

      • findFirst

        public static <T> Optional<T> findFirst​(Stream<?> stream,
                                                Class<T> typeToFind)
        Find the first object having the given typeToFind in a stream of objects.
        Type Parameters:
        T - the type token of the type we want to find
        Parameters:
        stream - the stream of objects of some (unknown) type
        typeToFind - the class of the object to find
        Returns:
        an Optional containing the first object of the given type, or empty
      • findFirst

        public static <T> Optional<T> findFirst​(Stream<?> stream,
                                                Class<T> typeToFind,
                                                Predicate<T> predicate)
        Find the first object having the given typeToFind and matching the supplied predicate in a stream of objects.
        Type Parameters:
        T - the type token of the type we want to find
        Parameters:
        stream - the stream of objects of some (unknown) type
        typeToFind - the class of the object to find
        predicate - the condition that must be satisfied for a match to occur
        Returns:
        an Optional containing the first object of the given type, or empty