Package: org.codehaus.groovy.runtime

## [Java] Class StreamGroovyMethods

- org.codehaus.groovy.runtime.StreamGroovyMethods

-     public class StreamGroovyMethods
      extends Object

- - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `public static DoubleStream` | `doubleStream(double[] self)` Returns a sequential DoubleStream with the specified array as its source.
    `` | `public void` | `forEachRemaining(Consumer<? super T> action)`
    `` | `public static IntStream` | `intStream(int[] self)` Returns a sequential IntStream with the specified array as its source.
    `` | `public static LongStream` | `longStream(long[] self)` Returns a sequential LongStream with the specified array as its source.
    `<T>` | `public static Stream<T>` | `plus(Stream<? extends T> lhs, Collection<? extends T> rhs)` Returns a lazily concatenated stream whose elements are all the elements of this stream followed by all the elements of the Collection object.
    `<T>` | `public static Stream<T>` | `plus(Stream<? extends T> lhs, Iterable<? extends T> rhs)` Returns a lazily concatenated stream whose elements are all the elements of this stream followed by all the elements of the Iterable object.
    `<T>` | `public static Stream<T>` | `plus(Stream<? extends T> lhs, Stream<? extends T> rhs)` Returns a lazily concatenated stream whose elements are all the elements of this stream followed by all the elements of the second stream.
    `<T>` | `public static Stream<T>` | `stream(T self)` Returns a sequential Stream containing a single element.
    `<T>` | `public static Stream<T>` | `stream(T[] self)` Returns a sequential Stream with the specified array as its source.
    `` | `public static Stream<Integer>` | `stream(int[] self)` Returns a sequential Stream with the specified array as its source.
    `` | `public static Stream<Long>` | `stream(long[] self)` Returns a sequential Stream with the specified array as its source.
    `` | `public static Stream<Double>` | `stream(double[] self)` Returns a sequential Stream with the specified array as its source.
    `` | `public static Stream<Character>` | `stream(char[] self)` Returns a sequential Stream with the specified array as its source.
    `` | `public static Stream<Byte>` | `stream(byte[] self)` Returns a sequential Stream with the specified array as its source.
    `` | `public static Stream<Short>` | `stream(short[] self)` Returns a sequential Stream with the specified array as its source.
    `` | `public static Stream<Boolean>` | `stream(boolean[] self)` Returns a sequential Stream with the specified array as its source.
    `` | `public static Stream<Float>` | `stream(float[] self)` Returns a sequential Stream with the specified array as its source.
    `<T>` | `public static Stream<T>` | `stream(Enumeration<T> self)` Returns a sequential Stream with the specified element(s) as its source.
    `<T>` | `public static Stream<T>` | `stream(Iterable<T> self)` Returns a sequential Stream with the specified element(s) as its source.
    `<T>` | `public static Stream<T>` | `stream(Iterator<T> self)` Returns a sequential Stream with the specified element(s) as its source.
    `<T>` | `public static Stream<T>` | `stream(Spliterator<T> self)` Returns a sequential Stream with the specified element(s) as its source.
    `<T>` | `public static Stream<T>` | `stream(NullObject self)` Returns an empty sequential Stream.
    `<T>` | `public static Stream<T>` | `stream(Optional<T> self)` If a value is present in the Optional, returns a Stream with the value as its source or else an empty stream.
    `` | `public static IntStream` | `stream(OptionalInt self)` If a value is present in the OptionalInt, returns an IntStream with the value as its source or else an empty stream.
    `` | `public static LongStream` | `stream(OptionalLong self)` If a value is present in the OptionalLong, returns a LongStream with the value as its source or else an empty stream.
    `` | `public static DoubleStream` | `stream(OptionalDouble self)` If a value is present in the OptionalDouble, returns a DoubleStream with the value as its source or else an empty stream.
    `<T>` | `public static T[]` | `toArray(Stream<? extends T> self, Class<T> type)` Returns an array containing the elements of the stream.
    `<T>` | `public static List<T>` | `toList(Stream<T> self)` Accumulates the elements of stream into a new List.
    `<T>` | `public static List<T>` | `toList(BaseStream<T, ? extends BaseStream> self)` Accumulates the elements of stream into a new List.
    `<T>` | `public static Set<T>` | `toSet(Stream<T> self)` Accumulates the elements of stream into a new Set.
    `<T>` | `public static Set<T>` | `toSet(BaseStream<T, ? extends BaseStream> self)` Accumulates the elements of stream into a new Set.
    `` | `public boolean` | `tryAdvance(Consumer<? super T> action)`

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class Object` | `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Method Detail

    - #### public static DoubleStream doubleStream(double[] self)

      Returns a sequential DoubleStream with the specified array as its source.

      Parameters:
        `self` - The array, assumed to be unmodified during use
      Returns:
        a `Stream` for the array
      Since:
        3.0.8

    - #### @Override
      public void forEachRemaining(Consumer<? super T> action)

    - #### public static IntStream intStream(int[] self)

      Returns a sequential IntStream with the specified array as its source.

      Parameters:
        `self` - The array, assumed to be unmodified during use
      Returns:
        a `Stream` for the array
      Since:
        3.0.8

    - #### public static LongStream longStream(long[] self)

      Returns a sequential LongStream with the specified array as its source.

      Parameters:
        `self` - The array, assumed to be unmodified during use
      Returns:
        a `Stream` for the array
      Since:
        3.0.8

    - #### <T> public static Stream<T> plus(Stream<? extends T> lhs, Collection<? extends T> rhs)

      Returns a lazily concatenated stream whose elements are all the elements of this stream followed by all the elements of the Collection object.

           import java.util.stream.Stream
           assert (Stream.of(1) + [2]).toList() == [1,2]
           assert (Stream.of(1) + []).toList() == [1]

      Since:
        4.0.0

    - #### <T> public static Stream<T> plus(Stream<? extends T> lhs, Iterable<? extends T> rhs)

      Returns a lazily concatenated stream whose elements are all the elements of this stream followed by all the elements of the Iterable object.

           import java.util.stream.Stream
           assert (Stream.of(1) + [2]).toList() == [1,2]
           assert (Stream.of(1) + []).toList() == [1]

      Since:
        4.0.0

    - #### <T> public static Stream<T> plus(Stream<? extends T> lhs, Stream<? extends T> rhs)

      Returns a lazily concatenated stream whose elements are all the elements of this stream followed by all the elements of the second stream.

           import java.util.stream.Stream
           assert (Stream.of(1) + Stream.<Integer>empty()).toList() == [1]
           assert (Stream.of(1) + Stream.of(2)).toList() == [1,2]
           assert (Stream.of(1) + [2].stream()).toList() == [1,2]

      Since:
        4.0.0

    - #### <T> public static Stream<T> stream(T self)

      Returns a sequential Stream containing a single element.

           def item = 'string'
           assert item.stream().toList() == ['string']
           assert item.stream().findFirst().isPresent()

      Since:
        3.0.0

    - #### <T> public static Stream<T> stream(T[] self)

      Returns a sequential Stream with the specified array as its source.

      Type Parameters:
        `T` - The type of the array elements
      Parameters:
        `self` - The array, assumed to be unmodified during use
      Returns:
        a `Stream` for the array
      Since:
        2.5.0

    - #### public static Stream<Integer> stream(int[] self)

      Returns a sequential Stream with the specified array as its source.

      Parameters:
        `self` - The array, assumed to be unmodified during use
      Returns:
        a `Stream` for the array
      Since:
        2.5.0

    - #### public static Stream<Long> stream(long[] self)

      Returns a sequential Stream with the specified array as its source.

      Parameters:
        `self` - The array, assumed to be unmodified during use
      Returns:
        a `Stream` for the array
      Since:
        2.5.0

    - #### public static Stream<Double> stream(double[] self)

      Returns a sequential Stream with the specified array as its source.

      Parameters:
        `self` - The array, assumed to be unmodified during use
      Returns:
        a `Stream` for the array
      Since:
        2.5.0

    - #### public static Stream<Character> stream(char[] self)

      Returns a sequential Stream with the specified array as its source.

      Parameters:
        `self` - The array, assumed to be unmodified during use
      Returns:
        a `Stream` for the array
      Since:
        2.5.0

    - #### public static Stream<Byte> stream(byte[] self)

      Returns a sequential Stream with the specified array as its source.

      Parameters:
        `self` - The array, assumed to be unmodified during use
      Returns:
        a `Stream` for the array
      Since:
        2.5.0

    - #### public static Stream<Short> stream(short[] self)

      Returns a sequential Stream with the specified array as its source.

      Parameters:
        `self` - The array, assumed to be unmodified during use
      Returns:
        a `Stream` for the array
      Since:
        2.5.0

    - #### public static Stream<Boolean> stream(boolean[] self)

      Returns a sequential Stream with the specified array as its source.

      Parameters:
        `self` - The array, assumed to be unmodified during use
      Returns:
        a `Stream` for the array
      Since:
        2.5.0

    - #### public static Stream<Float> stream(float[] self)

      Returns a sequential Stream with the specified array as its source.

      Parameters:
        `self` - The array, assumed to be unmodified during use
      Returns:
        a `Stream` for the array
      Since:
        2.5.0

    - #### <T> public static Stream<T> stream(Enumeration<T> self)

      Returns a sequential Stream with the specified element(s) as its source.

           def tokens = new StringTokenizer('one two')
           assert tokens.stream().toList() == ['one', 'two']

      Since:
        3.0.0

    - #### <T> public static Stream<T> stream(Iterable<T> self)

      Returns a sequential Stream with the specified element(s) as its source.

           class Items implements Iterable {
             Iterator<String> iterator() {
               ['one', 'two'].iterator()
             }
           }
           def items = new Items()
           assert items.stream().toList() == ['one', 'two']

      Since:
        3.0.0

    - #### <T> public static Stream<T> stream(Iterator<T> self)

      Returns a sequential Stream with the specified element(s) as its source.

           [].iterator().stream().toList().isEmpty()
           ['one', 'two'].iterator().stream().toList() == ['one', 'two']

      Since:
        3.0.0

    - #### <T> public static Stream<T> stream(Spliterator<T> self)

      Returns a sequential Stream with the specified element(s) as its source.

           assert [].spliterator().stream().toList().isEmpty()
           assert ['one', 'two'].spliterator().stream().toList() == ['one', 'two']

      Since:
        3.0.0

    - #### <T> public static Stream<T> stream(NullObject self)

      Returns an empty sequential Stream.

           def item = null
           assert item.stream().toList() == []
           assert !item.stream().findFirst().isPresent()

      Since:
        3.0.0

    - #### <T> public static Stream<T> stream(Optional<T> self)

      If a value is present in the Optional, returns a Stream with the value as its source or else an empty stream.

      Since:
        3.0.0

    - #### public static IntStream stream(OptionalInt self)

      If a value is present in the OptionalInt, returns an IntStream with the value as its source or else an empty stream.

      Since:
        3.0.0

    - #### public static LongStream stream(OptionalLong self)

      If a value is present in the OptionalLong, returns a LongStream with the value as its source or else an empty stream.

      Since:
        3.0.0

    - #### public static DoubleStream stream(OptionalDouble self)

      If a value is present in the OptionalDouble, returns a DoubleStream with the value as its source or else an empty stream.

      Since:
        3.0.0

    - #### <T> public static T[] toArray(Stream<? extends T> self, Class<T> type)

      Returns an array containing the elements of the stream.

           import static groovy.test.GroovyAssert.shouldFail

           assert Arrays.equals([].stream().toArray(Object), new Object[0])
           assert Arrays.equals([].stream().toArray(String), new String[0])
           assert Arrays.equals([].stream().toArray(String[]), new String[0][])
           assert Arrays.equals(['x'].stream().toArray(Object), ['x'].toArray())
           assert Arrays.equals(['x'].stream().toArray(String), ['x'] as String[])
           assert Arrays.deepEquals([['x'] as String[]].stream().toArray(String[]), [['x'] as String[]] as String[][])
           assert Arrays.equals(['x'].stream().toArray(CharSequence), ['x'] as CharSequence[])

           shouldFail(ArrayStoreException) {
               ['x'].stream().toArray(Thread)
           }

           shouldFail(IllegalArgumentException) {
               ['x'].stream().toArray((Class) null)
           }

           // Stream#toArray(IntFunction) should still be used for closure literal:
           assert Arrays.equals(['x'].stream().toArray { n -> new String[n] }, ['x'] as String[])

           // Stream#toArray(IntFunction) should still be used for method reference:
           assert Arrays.equals(['x'].stream().toArray(String[]::new), ['x'] as String[])

      Parameters:
        `self` - the stream
        `type` - the array element type
      Since:
        3.0.4

    - #### <T> public static List<T> toList(Stream<T> self)

      Accumulates the elements of stream into a new List.

      Parameters:
        `self` - the stream
      Type Parameters:
        `T` - the type of element
      Returns:
        a new `java.util.List` instance
      Since:
        2.5.0

    - #### <T> public static List<T> toList(BaseStream<T, ? extends BaseStream> self)

      Accumulates the elements of stream into a new List.

      Parameters:
        `self` - the `java.util.stream.BaseStream`
      Type Parameters:
        `T` - the type of element
      Returns:
        a new `java.util.List` instance
      Since:
        2.5.0

    - #### <T> public static Set<T> toSet(Stream<T> self)

      Accumulates the elements of stream into a new Set.

      Parameters:
        `self` - the stream
      Type Parameters:
        `T` - the type of element
      Returns:
        a new `java.util.Set` instance
      Since:
        2.5.0

    - #### <T> public static Set<T> toSet(BaseStream<T, ? extends BaseStream> self)

      Accumulates the elements of stream into a new Set.

      Parameters:
        `self` - the `java.util.stream.BaseStream`
      Type Parameters:
        `T` - the type of element
      Returns:
        a new `java.util.Set` instance
      Since:
        2.5.0

    - #### @Override
      public boolean tryAdvance(Consumer<? super T> action)