Class MoreStreams


  • @ParametersAreNonnullByDefault
    public final class MoreStreams
    extends Object
    Static utility methods related to Stream instances.
    • Method Detail

      • indexOf

        @Nonnull
        public static Optional<Integer> indexOf​(Stream<?> stream,
                                                Object value)
        Finds the index of the given value in the stream.
        Parameters:
        stream - the stream to search through for the object
        value - the value to find
        Returns:
        an Optional containing the index of the value within the stream, Optional.empty() if not found
      • lastIndexOf

        @Nonnull
        public static Optional<Integer> lastIndexOf​(Stream<?> stream,
                                                    Object value)
        Finds the last index of the given value in the stream.
        Parameters:
        stream - the stream to traverse for looking for the object
        value - the value to find, may be null
        Returns:
        an Optional containing the index of the value within the stream, Optional.empty() if not found
      • size

        @Nonnull
        public static Optional<Integer> size​(Stream<?> stream)
        Returns the number of element in the stream as an integer;
        Parameters:
        stream - the stream
        Returns:
        an Optional containing the size, Optional.empty() if the stream is empty
      • reverseOrder

        @Nonnull
        public static IntUnaryOperator reverseOrder​(int startInclusive,
                                                    int endExclusive)
        Returns an unary operator to iterates over an IntStream in the reverse direction.
        Parameters:
        startInclusive - the (inclusive) initial value
        endExclusive - the exclusive upper bound
        Returns:
        an unary operator
        See Also:
        IntStream.range(int, int)
      • reverseOrder

        @Nonnull
        public static LongUnaryOperator reverseOrder​(long startInclusive,
                                                     long endExclusive)
        Returns an unary operator to iterates over an LongStream in the reverse direction.
        Parameters:
        startInclusive - the (inclusive) initial value
        endExclusive - the exclusive upper bound
        Returns:
        an unary operator
        See Also:
        LongStream.range(long, long)