Class Streams


  • public final class Streams
    extends Object
    Utility class to help with the usage of the Java 8 Streams API in Gaffer.
    • Method Detail

      • toStream

        public static <T> Stream<T> toStream​(Iterable<T> iterable)
        Convert an Iterable to a Stream The stream returned must be closed.
        Type Parameters:
        T - the type of object stored in the iterable
        Parameters:
        iterable - the input iterable
        Returns:
        a stream containing the contents of the iterable
      • toStream

        public static <T> Stream<T> toStream​(T... array)
        Convert an array to a Stream.
        Type Parameters:
        T - the type of object stored in the array
        Parameters:
        array - the input array
        Returns:
        a stream containing the contents of the array
      • toStream

        public static <T> Stream<T> toStream​(Iterator<T> iterator)
        Convert an Iterator to a Stream The stream returned must be closed.
        Type Parameters:
        T - the type of object stored in the iterator
        Parameters:
        iterator - the input iterator
        Returns:
        a stream containing the contents of the iterator
      • toParallelStream

        public static <T> Stream<T> toParallelStream​(Iterable<T> iterable)
        Convert an Iterable to a Stream The stream returned must be closed.
        Type Parameters:
        T - the type of object stored in the iterable
        Parameters:
        iterable - the input iterable
        Returns:
        a stream containing the contents of the iterable
      • toParallelStream

        public static <T> Stream<T> toParallelStream​(Iterator<T> iterator)
        Convert an Iterator to a Stream The stream returned must be closed.
        Type Parameters:
        T - the type of object stored in the iterator
        Parameters:
        iterator - the input iterator
        Returns:
        a stream containing the contents of the iterator
      • toParallelStream

        public static <T> Stream<T> toParallelStream​(T... array)
        Convert an array to a Stream.
        Type Parameters:
        T - the type of object stored in the array
        Parameters:
        array - the input array
        Returns:
        a stream containing the contents of the array
      • toBatches

        public static <T> Stream<List<T>> toBatches​(Iterable<T> iterable,
                                                    int size)
        Convert an iterable to a Stream of List.
        Type Parameters:
        T - the type of object stored in the stream
        Parameters:
        iterable - the input iterable
        size - the size of the batch
        Returns:
        a stream containing the contents of the iterable in a list