Package org.codehaus.groovy.vmplugin.v8
Class PluginDefaultGroovyMethods
java.lang.Object
org.codehaus.groovy.runtime.DefaultGroovyMethodsSupport
org.codehaus.groovy.vmplugin.v8.PluginDefaultGroovyMethods
public class PluginDefaultGroovyMethods extends DefaultGroovyMethodsSupport
Defines new Groovy methods which appear on standard Java 8 classes within the
 Groovy environment.
- Since:
- 2.5.0
- 
Method SummaryModifier and Type Method Description static booleanasBoolean(java.util.Optional<?> optional)Coerce anOptionalinstance to abooleanvalue.static <S, T> java.util.concurrent.Future<T>collect(java.util.concurrent.Future<S> self, Closure<T> transform)Returns a Future asynchronously returning a transformed result.static <S, T> java.util.Optional<T>collect(java.util.Optional<S> self, Closure<T> transform)If the optional contains a value, returns an optional containing the transformed value obtained using thetransformclosure or otherwise an empty optional.static java.util.stream.DoubleStreamdoubleStream(double[] self)Returns a sequentialDoubleStreamwith the specified array as its source.static <T> java.util.Optional<T>filter(java.util.Optional<?> self, java.lang.Class<T> type)Tests given value against specified type and changes generics of result.static java.util.OptionalDoublefilter(java.util.OptionalDouble self, java.util.function.DoublePredicate test)If a value is present in theOptionalDouble, tests the value using the given predicate and returns the optional if the test returns true or empty otherwise.static java.util.OptionalIntfilter(java.util.OptionalInt self, java.util.function.IntPredicate test)If a value is present in theOptionalInt, tests the value using the given predicate and returns the optional if the test returns true or else empty.static java.util.OptionalLongfilter(java.util.OptionalLong self, java.util.function.LongPredicate test)If a value is present in theOptionalLong, tests the value using the given predicate and returns the optional if the test returns true or else empty.static doubleget(java.util.OptionalDouble self)If a value is present in theOptionalDouble, returns the value, otherwise throwsNoSuchElementException.static intget(java.util.OptionalInt self)If a value is present in theOptionalInt, returns the value, otherwise throwsNoSuchElementException.static longget(java.util.OptionalLong self)If a value is present in theOptionalLong, returns the value, otherwise throwsNoSuchElementException.static java.util.stream.IntStreamintStream(int[] self)Returns a sequentialIntStreamwith the specified array as its source.static java.lang.StringBuilderleftShift(java.lang.StringBuilder self, java.lang.Object value)Overloads the left shift operator to provide an easy way to append multiple objects as string representations to a StringBuilder.static java.util.stream.LongStreamlongStream(long[] self)Returns a sequentialLongStreamwith the specified array as its source.static <T> java.util.OptionalDoublemapToDouble(java.util.Optional<T> self, java.util.function.ToDoubleFunction<? super T> mapper)If a value is present in theOptional, returns anOptionalDoubleconsisting of the result of applying the given function to the value or else empty.static <T> java.util.OptionalIntmapToInt(java.util.Optional<T> self, java.util.function.ToIntFunction<? super T> mapper)If a value is present in theOptional, returns anOptionalIntconsisting of the result of applying the given function to the value or else empty.static <T> java.util.OptionalLongmapToLong(java.util.Optional<T> self, java.util.function.ToLongFunction<? super T> mapper)If a value is present in theOptional, returns anOptionalLongconsisting of the result of applying the given function to the value or else empty.static <T> java.util.Optional<T>mapToObj(java.util.OptionalDouble self, java.util.function.DoubleFunction<? extends T> mapper)If a value is present in theOptionalDouble, returns anOptionalconsisting of the result of applying the given function to the value or else empty.static <T> java.util.Optional<T>mapToObj(java.util.OptionalInt self, java.util.function.IntFunction<? extends T> mapper)If a value is present in theOptionalInt, returns anOptionalconsisting of the result of applying the given function to the value or else empty.static <T> java.util.Optional<T>mapToObj(java.util.OptionalLong self, java.util.function.LongFunction<? extends T> mapper)If a value is present in theOptionalLong, returns anOptionalconsisting of the result of applying the given function to the value or else empty.static java.lang.Objectnext(java.lang.Enum self)Overloads the++operator for enums.static <T> java.util.Optional<T>orOptional(java.util.Optional<T> self, java.util.function.Supplier<? extends java.util.Optional<? extends T>> supplier)Provide similar functionality to JDK9oron JDK8.static java.lang.Stringplus(java.lang.StringBuilder self, java.lang.String value)Appends a String to this StringBuilder.static java.lang.Objectprevious(java.lang.Enum self)Overloads the--operator for enums.static voidputAt(java.lang.StringBuilder self, EmptyRange range, java.lang.Object value)Supports the range subscript operator for StringBuilder.static voidputAt(java.lang.StringBuilder self, IntRange range, java.lang.Object value)Supports the range subscript operator for StringBuilder.static intsize(java.lang.StringBuilder self)Deprecated.static java.util.stream.Stream<java.lang.Boolean>stream(boolean[] self)Returns a sequentialStreamwith the specified array as its source.static java.util.stream.Stream<java.lang.Byte>stream(byte[] self)Returns a sequentialStreamwith the specified array as its source.static java.util.stream.Stream<java.lang.Character>stream(char[] self)Returns a sequentialStreamwith the specified array as its source.static java.util.stream.Stream<java.lang.Double>stream(double[] self)Returns a sequentialStreamwith the specified array as its source.static java.util.stream.Stream<java.lang.Float>stream(float[] self)Returns a sequentialStreamwith the specified array as its source.static java.util.stream.Stream<java.lang.Integer>stream(int[] self)Returns a sequentialStreamwith the specified array as its source.static java.util.stream.Stream<java.lang.Long>stream(long[] self)Returns a sequentialStreamwith the specified array as its source.static java.util.stream.Stream<java.lang.Short>stream(short[] self)Returns a sequentialStreamwith the specified array as its source.static <T> java.util.stream.Stream<T>stream(java.lang.Iterable<T> self)Returns a sequentialStreamwith the specified element(s) as its source.static <T> java.util.stream.Stream<T>stream(java.util.Enumeration<T> self)Returns a sequentialStreamwith the specified element(s) as its source.static <T> java.util.stream.Stream<T>stream(java.util.Iterator<T> self)Returns a sequentialStreamwith the specified element(s) as its source.static <T> java.util.stream.Stream<T>stream(java.util.Optional<T> self)If a value is present in theOptional, returns aStreamwith the value as its source or else an empty stream.static java.util.stream.DoubleStreamstream(java.util.OptionalDouble self)If a value is present in theOptionalDouble, returns aDoubleStreamwith the value as its source or else an empty stream.static java.util.stream.IntStreamstream(java.util.OptionalInt self)If a value is present in theOptionalInt, returns anIntStreamwith the value as its source or else an empty stream.static java.util.stream.LongStreamstream(java.util.OptionalLong self)If a value is present in theOptionalLong, returns aLongStreamwith the value as its source or else an empty stream.static <T> java.util.stream.Stream<T>stream(java.util.Spliterator<T> self)Returns a sequentialStreamwith the specified element(s) as its source.static <T> java.util.stream.Stream<T>stream(NullObject self)Returns an empty sequentialStream.static <T> java.util.stream.Stream<T>stream(T self)Returns a sequentialStreamcontaining a single element.static <T> java.util.stream.Stream<T>stream(T[] self)Returns a sequentialStreamwith the specified array as its source.static <T> T[]toArray(java.util.stream.Stream<? extends T> self, java.lang.Class<T> type)Returns an array containing the elements of the stream.static <T> java.util.List<T>toList(java.util.stream.BaseStream<T,? extends java.util.stream.BaseStream> self)Accumulates the elements of stream into a new List.static <T> java.util.List<T>toList(java.util.stream.Stream<T> self)Accumulates the elements of stream into a new List.static <T> java.util.Set<T>toSet(java.util.stream.BaseStream<T,? extends java.util.stream.BaseStream> self)Accumulates the elements of stream into a new Set.static <T> java.util.Set<T>toSet(java.util.stream.Stream<T> self)Accumulates the elements of stream into a new Set.Methods inherited from class org.codehaus.groovy.runtime.DefaultGroovyMethodsSupportcloneSimilarCollection, cloneSimilarMap, closeQuietly, closeWithWarning, createSimilarArray, createSimilarCollection, createSimilarCollection, createSimilarCollection, createSimilarList, createSimilarMap, createSimilarOrDefaultCollection, createSimilarQueue, createSimilarSet, normaliseIndex, sameType, subListBorders, subListBorders, writeUTF16BomIfRequired, writeUTF16BomIfRequired, writeUTF16BomIfRequired, writeUTF16BomIfRequiredMethods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
- 
Method Details- 
asBooleanpublic static boolean asBoolean(java.util.Optional<?> optional)Coerce anOptionalinstance to abooleanvalue.assert !Optional.empty().asBoolean() assert Optional.of(1234).asBoolean() - Parameters:
- optional- the Optional
- Returns:
- trueif a value is present, otherwise- false
- Since:
- 2.5.0
 
- 
getpublic static int get(java.util.OptionalInt self)If a value is present in theOptionalInt, returns the value, otherwise throwsNoSuchElementException.assert OptionalInt.of(1234).get() == 1234 - Since:
- 3.0.0
 
- 
getpublic static long get(java.util.OptionalLong self)If a value is present in theOptionalLong, returns the value, otherwise throwsNoSuchElementException.assert OptionalLong.of(1234L).get() == 1234L - Since:
- 3.0.0
 
- 
getpublic static double get(java.util.OptionalDouble self)If a value is present in theOptionalDouble, returns the value, otherwise throwsNoSuchElementException.assert OptionalDouble.of(Math.PI).get() == Math.PI - Since:
- 3.0.0
 
- 
filterpublic static <T> java.util.Optional<T> filter(java.util.Optional<?> self, java.lang.Class<T> type)Tests given value against specified type and changes generics of result. This is equivalent to:self.filter(it -> it instanceof Type).map(it -> (Type) it)assert !Optional.empty().filter(Number).isPresent() assert !Optional.of('x').filter(Number).isPresent() assert Optional.of(1234).filter(Number).isPresent() assert Optional.of(1234).filter(Number).get().equals(1234)- Since:
- 3.0.0
 
- 
filterpublic static java.util.OptionalInt filter(java.util.OptionalInt self, java.util.function.IntPredicate test)If a value is present in theOptionalInt, tests the value using the given predicate and returns the optional if the test returns true or else empty.assert !OptionalInt.empty().filter(i -> true).isPresent() assert OptionalInt.of(1234).filter(i -> true).isPresent() assert !OptionalInt.of(1234).filter(i -> false).isPresent() assert OptionalInt.of(1234).filter(i -> true).getAsInt() == 1234 - Since:
- 3.0.0
 
- 
filterpublic static java.util.OptionalLong filter(java.util.OptionalLong self, java.util.function.LongPredicate test)If a value is present in theOptionalLong, tests the value using the given predicate and returns the optional if the test returns true or else empty.assert !OptionalLong.empty().filter(n -> true).isPresent() assert OptionalLong.of(123L).filter(n -> true).isPresent() assert !OptionalLong.of(123L).filter(n -> false).isPresent() assert OptionalLong.of(123L).filter(n -> true).getAsLong() == 123L - Since:
- 3.0.0
 
- 
filterpublic static java.util.OptionalDouble filter(java.util.OptionalDouble self, java.util.function.DoublePredicate test)If a value is present in theOptionalDouble, tests the value using the given predicate and returns the optional if the test returns true or empty otherwise.assert !OptionalDouble.empty().filter(n -> true).isPresent() assert OptionalDouble.of(Math.PI).filter(n -> true).isPresent() assert !OptionalDouble.of(Math.PI).filter(n -> false).isPresent() assert OptionalDouble.of(Math.PI).filter(n -> true).getAsDouble() == Math.PI - Since:
- 3.0.0
 
- 
mapToObjpublic static <T> java.util.Optional<T> mapToObj(java.util.OptionalInt self, java.util.function.IntFunction<? extends T> mapper)If a value is present in theOptionalInt, returns anOptionalconsisting of the result of applying the given function to the value or else empty.assert !OptionalInt.empty().mapToObj(x -> new Object()).isPresent() assert OptionalInt.of(1234).mapToObj(x -> new Object()).isPresent() assert !OptionalInt.of(1234).mapToObj(x -> null).isPresent() assert OptionalInt.of(1234).mapToObj(Integer::toString).get() == '1234' - Since:
- 3.0.0
 
- 
mapToObjpublic static <T> java.util.Optional<T> mapToObj(java.util.OptionalLong self, java.util.function.LongFunction<? extends T> mapper)If a value is present in theOptionalLong, returns anOptionalconsisting of the result of applying the given function to the value or else empty.assert !OptionalLong.empty().mapToObj(x -> new Object()).isPresent() assert OptionalLong.of(123L).mapToObj(x -> new Object()).isPresent() assert !OptionalLong.of(123L).mapToObj(x -> null).isPresent() assert OptionalLong.of(1234L).mapToObj(Long::toString).get() == '1234' - Since:
- 3.0.0
 
- 
mapToObjpublic static <T> java.util.Optional<T> mapToObj(java.util.OptionalDouble self, java.util.function.DoubleFunction<? extends T> mapper)If a value is present in theOptionalDouble, returns anOptionalconsisting of the result of applying the given function to the value or else empty.assert !OptionalDouble.empty().mapToObj(x -> new Object()).isPresent() assert OptionalDouble.of(Math.PI).mapToObj(x -> new Object()).isPresent() assert !OptionalDouble.of(Math.PI).mapToObj(x -> null).isPresent() assert OptionalDouble.of(Math.PI).mapToObj(Double::toString).get().startsWith('3.14')- Since:
- 3.0.0
 
- 
mapToIntpublic static <T> java.util.OptionalInt mapToInt(java.util.Optional<T> self, java.util.function.ToIntFunction<? super T> mapper)If a value is present in theOptional, returns anOptionalIntconsisting of the result of applying the given function to the value or else empty.assert !Optional.empty().mapToInt(x -> 42).isPresent() assert Optional.of('x').mapToInt(x -> 42).getAsInt() == 42- Since:
- 3.0.0
 
- 
mapToLongpublic static <T> java.util.OptionalLong mapToLong(java.util.Optional<T> self, java.util.function.ToLongFunction<? super T> mapper)If a value is present in theOptional, returns anOptionalLongconsisting of the result of applying the given function to the value or else empty.assert !Optional.empty().mapToLong(x -> 42L).isPresent() assert Optional.of('x').mapToLong(x -> 42L).getAsLong() == 42L- Since:
- 3.0.0
 
- 
mapToDoublepublic static <T> java.util.OptionalDouble mapToDouble(java.util.Optional<T> self, java.util.function.ToDoubleFunction<? super T> mapper)If a value is present in theOptional, returns anOptionalDoubleconsisting of the result of applying the given function to the value or else empty.assert !Optional.empty().mapToDouble(x -> Math.PI).isPresent() assert Optional.of('x').mapToDouble(x -> Math.PI).getAsDouble() == Math.PI- Since:
- 3.0.0
 
- 
collectpublic static <S, T> java.util.Optional<T> collect(java.util.Optional<S> self, Closure<T> transform)If the optional contains a value, returns an optional containing the transformed value obtained using thetransformclosure or otherwise an empty optional.assert Optional.of("foobar").collect{ it.size() }.get() == 6 assert !Optional.empty().collect{ it.size() }.isPresent()- Parameters:
- self- an Optional
- transform- the closure used to transform the optional value if present
- Returns:
- an Optional containing the transformed value or empty if the optional is empty or the transform returns null
- Since:
- 3.0.0
 
- 
collectpublic static <S, T> java.util.concurrent.Future<T> collect(java.util.concurrent.Future<S> self, Closure<T> transform)Returns a Future asynchronously returning a transformed result.import java.util.concurrent.* def executor = Executors.newSingleThreadExecutor() Future foobar = executor.submit{ "foobar" } Future foobarSize = foobar.collect{ it.size() } assert foobarSize.get() == 6 executor.shutdown() - Parameters:
- self- a Future
- transform- the closure used to transform the Future value
- Returns:
- a Future allowing the transformed value to be obtained asynchronously
- Since:
- 3.0.0
 
- 
nextpublic static java.lang.Object next(java.lang.Enum self)Overloads the++operator for enums. It will invoke Groovy's default next behaviour for enums that do not have their own next method.- Parameters:
- self- an Enum
- Returns:
- the next defined enum from the enum class
- Since:
- 1.5.2
 
- 
previouspublic static java.lang.Object previous(java.lang.Enum self)Overloads the--operator for enums. It will invoke Groovy's default previous behaviour for enums that do not have their own previous method.- Parameters:
- self- an Enum
- Returns:
- the previous defined enum from the enum class
- Since:
- 1.5.2
 
- 
size@Deprecated public static int size(java.lang.StringBuilder self)Deprecated.Provides the standard Groovysize()method forStringBuilder.- Parameters:
- self- a StringBuilder
- Returns:
- the length of the StringBuilder
- Since:
- 1.5.2
- See Also:
- StringGroovyMethods.size(CharSequence)
 
- 
leftShiftpublic static java.lang.StringBuilder leftShift(java.lang.StringBuilder self, java.lang.Object value)Overloads the left shift operator to provide an easy way to append multiple objects as string representations to a StringBuilder.- Parameters:
- self- a StringBuilder
- value- a value to append
- Returns:
- the StringBuilder on which this operation was invoked
- Since:
- 1.5.2
 
- 
putAtSupports the range subscript operator for StringBuilder. Index values are treated as characters within the builder.- Parameters:
- self- a StringBuilder
- range- a Range
- value- the object that's toString() will be inserted
- Since:
- 1.5.2
 
- 
putAtSupports the range subscript operator for StringBuilder.- Parameters:
- self- a StringBuilder
- range- a Range
- value- the object that's toString() will be inserted
- Since:
- 1.5.2
 
- 
pluspublic static java.lang.String plus(java.lang.StringBuilder self, java.lang.String value)Appends a String to this StringBuilder.- Parameters:
- self- a StringBuilder
- value- a String
- Returns:
- a String
- Since:
- 1.5.2
 
- 
toArraypublic static <T> T[] toArray(java.util.stream.Stream<? extends T> self, java.lang.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
 
- 
toListpublic static <T> java.util.List<T> toList(java.util.stream.Stream<T> self)Accumulates the elements of stream into a new List.- Type Parameters:
- T- the type of element
- Parameters:
- self- the stream
- Returns:
- a new java.util.Listinstance
- Since:
- 2.5.0
 
- 
toSetpublic static <T> java.util.Set<T> toSet(java.util.stream.Stream<T> self)Accumulates the elements of stream into a new Set.- Type Parameters:
- T- the type of element
- Parameters:
- self- the stream
- Returns:
- a new java.util.Setinstance
- Since:
- 2.5.0
 
- 
toListpublic static <T> java.util.List<T> toList(java.util.stream.BaseStream<T,? extends java.util.stream.BaseStream> self)Accumulates the elements of stream into a new List.- Type Parameters:
- T- the type of element
- Parameters:
- self- the- java.util.stream.BaseStream
- Returns:
- a new java.util.Listinstance
- Since:
- 2.5.0
 
- 
toSetpublic static <T> java.util.Set<T> toSet(java.util.stream.BaseStream<T,? extends java.util.stream.BaseStream> self)Accumulates the elements of stream into a new Set.- Type Parameters:
- T- the type of element
- Parameters:
- self- the- java.util.stream.BaseStream
- Returns:
- a new java.util.Setinstance
- Since:
- 2.5.0
 
- 
streamReturns an empty sequentialStream.def item = null assert item.stream().toList() == [] assert !item.stream().findFirst().isPresent() - Since:
- 3.0.0
 
- 
streampublic static <T> java.util.stream.Stream<T> stream(T self)Returns a sequentialStreamcontaining a single element.def item = 'string' assert item.stream().toList() == ['string'] assert item.stream().findFirst().isPresent() - Since:
- 3.0.0
 
- 
streampublic static <T> java.util.stream.Stream<T> stream(T[] self)Returns a sequentialStreamwith 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 Streamfor the array
- Since:
- 2.5.0
 
- 
streampublic static java.util.stream.Stream<java.lang.Integer> stream(int[] self)Returns a sequentialStreamwith the specified array as its source.- Parameters:
- self- The array, assumed to be unmodified during use
- Returns:
- a Streamfor the array
- Since:
- 2.5.0
 
- 
intStreampublic static java.util.stream.IntStream intStream(int[] self)Returns a sequentialIntStreamwith the specified array as its source.- Parameters:
- self- The array, assumed to be unmodified during use
- Returns:
- a Streamfor the array
- Since:
- 3.0.8
 
- 
streampublic static java.util.stream.Stream<java.lang.Long> stream(long[] self)Returns a sequentialStreamwith the specified array as its source.- Parameters:
- self- The array, assumed to be unmodified during use
- Returns:
- a Streamfor the array
- Since:
- 2.5.0
 
- 
longStreampublic static java.util.stream.LongStream longStream(long[] self)Returns a sequentialLongStreamwith the specified array as its source.- Parameters:
- self- The array, assumed to be unmodified during use
- Returns:
- a Streamfor the array
- Since:
- 3.0.8
 
- 
streampublic static java.util.stream.Stream<java.lang.Double> stream(double[] self)Returns a sequentialStreamwith the specified array as its source.- Parameters:
- self- The array, assumed to be unmodified during use
- Returns:
- a Streamfor the array
- Since:
- 2.5.0
 
- 
doubleStreampublic static java.util.stream.DoubleStream doubleStream(double[] self)Returns a sequentialDoubleStreamwith the specified array as its source.- Parameters:
- self- The array, assumed to be unmodified during use
- Returns:
- a Streamfor the array
- Since:
- 3.0.8
 
- 
streampublic static java.util.stream.Stream<java.lang.Character> stream(char[] self)Returns a sequentialStreamwith the specified array as its source.- Parameters:
- self- The array, assumed to be unmodified during use
- Returns:
- a Streamfor the array
- Since:
- 2.5.0
 
- 
streampublic static java.util.stream.Stream<java.lang.Byte> stream(byte[] self)Returns a sequentialStreamwith the specified array as its source.- Parameters:
- self- The array, assumed to be unmodified during use
- Returns:
- a Streamfor the array
- Since:
- 2.5.0
 
- 
streampublic static java.util.stream.Stream<java.lang.Short> stream(short[] self)Returns a sequentialStreamwith the specified array as its source.- Parameters:
- self- The array, assumed to be unmodified during use
- Returns:
- a Streamfor the array
- Since:
- 2.5.0
 
- 
streampublic static java.util.stream.Stream<java.lang.Boolean> stream(boolean[] self)Returns a sequentialStreamwith the specified array as its source.- Parameters:
- self- The array, assumed to be unmodified during use
- Returns:
- a Streamfor the array
- Since:
- 2.5.0
 
- 
streampublic static java.util.stream.Stream<java.lang.Float> stream(float[] self)Returns a sequentialStreamwith the specified array as its source.- Parameters:
- self- The array, assumed to be unmodified during use
- Returns:
- a Streamfor the array
- Since:
- 2.5.0
 
- 
streampublic static <T> java.util.stream.Stream<T> stream(java.util.Enumeration<T> self)Returns a sequentialStreamwith the specified element(s) as its source.def tokens = new StringTokenizer('one two') assert tokens.stream().toList() == ['one', 'two']- Since:
- 3.0.0
 
- 
streampublic static <T> java.util.stream.Stream<T> stream(java.lang.Iterable<T> self)Returns a sequentialStreamwith the specified element(s) as its source.class Items implements Iterable { Iterator iterator() { ['one', 'two'].iterator() } } def items = new Items() assert items.stream().toList() == ['one', 'two'] - Since:
- 3.0.0
 
- 
streampublic static <T> java.util.stream.Stream<T> stream(java.util.Iterator<T> self)Returns a sequentialStreamwith the specified element(s) as its source.[].iterator().stream().toList().isEmpty() ['one', 'two'].iterator().stream().toList() == ['one', 'two'] - Since:
- 3.0.0
 
- 
streampublic static <T> java.util.stream.Stream<T> stream(java.util.Spliterator<T> self)Returns a sequentialStreamwith the specified element(s) as its source.[].spliterator().stream().toList().isEmpty() ['one', 'two'].spliterator().stream().toList() == ['one', 'two'] - Since:
- 3.0.0
 
- 
streampublic static <T> java.util.stream.Stream<T> stream(java.util.Optional<T> self)If a value is present in theOptional, returns aStreamwith the value as its source or else an empty stream.- Since:
- 3.0.0
 
- 
streampublic static java.util.stream.IntStream stream(java.util.OptionalInt self)If a value is present in theOptionalInt, returns anIntStreamwith the value as its source or else an empty stream.- Since:
- 3.0.0
 
- 
streampublic static java.util.stream.LongStream stream(java.util.OptionalLong self)If a value is present in theOptionalLong, returns aLongStreamwith the value as its source or else an empty stream.- Since:
- 3.0.0
 
- 
streampublic static java.util.stream.DoubleStream stream(java.util.OptionalDouble self)If a value is present in theOptionalDouble, returns aDoubleStreamwith the value as its source or else an empty stream.- Since:
- 3.0.0
 
- 
orOptionalpublic static <T> java.util.Optional<T> orOptional(java.util.Optional<T> self, java.util.function.Supplier<? extends java.util.Optional<? extends T>> supplier)Provide similar functionality to JDK9oron JDK8.- Since:
- 3.0.6
 
 
-