Package org.codehaus.groovy.vmplugin.v8
Class PluginDefaultGroovyMethods
java.lang.Object
org.codehaus.groovy.runtime.DefaultGroovyMethodsSupport
org.codehaus.groovy.vmplugin.v8.PluginDefaultGroovyMethods
Defines new Groovy methods which appear on standard Java 8 classes within the
Groovy environment.
- Since:
- 2.5.0
-
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
Coerce anOptional
instance to aboolean
value.static <S,
T> Future<T> Returns a Future asynchronously returning a transformed result.static <S,
T> Optional<T> If the optional contains a value, returns an optional containing the transformed value obtained using thetransform
closure or otherwise an empty optional.static DoubleStream
doubleStream
(double[] self) Deprecated.static <T> Optional<T>
Tests given value against specified type and changes generics of result.static OptionalDouble
filter
(OptionalDouble self, 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 OptionalInt
filter
(OptionalInt self, 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 OptionalLong
filter
(OptionalLong self, 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 double
get
(OptionalDouble self) If a value is present in theOptionalDouble
, returns the value, otherwise throwsNoSuchElementException
.static int
get
(OptionalInt self) If a value is present in theOptionalInt
, returns the value, otherwise throwsNoSuchElementException
.static long
get
(OptionalLong self) If a value is present in theOptionalLong
, returns the value, otherwise throwsNoSuchElementException
.static String
Gets the pid of the current Java process.static IntStream
intStream
(int[] self) Deprecated.static StringBuilder
leftShift
(StringBuilder self, Object value) Overloads the left shift operator to provide an easy way to append multiple objects as string representations to a StringBuilder.static LongStream
longStream
(long[] self) Deprecated.static <T> OptionalDouble
mapToDouble
(Optional<T> self, ToDoubleFunction<? super T> mapper) If a value is present in theOptionalDouble
, returns anOptionalDouble
consisting of the result of applying the given function to the value or else empty.static <T> OptionalInt
mapToInt
(Optional<T> self, ToIntFunction<? super T> mapper) If a value is present in theOptionalInt
, returns anOptionalInt
consisting of the result of applying the given function to the value or else empty.static <T> OptionalLong
mapToLong
(Optional<T> self, ToLongFunction<? super T> mapper) If a value is present in theOptionalLong
, returns anOptionalLong
consisting of the result of applying the given function to the value or else empty.static <T> Optional<T>
mapToObj
(OptionalDouble self, DoubleFunction<? extends T> mapper) If a value is present in theOptionalDouble
, returns anOptional
consisting of the result of applying the given function to the value or else empty.static <T> Optional<T>
mapToObj
(OptionalInt self, IntFunction<? extends T> mapper) If a value is present in theOptionalInt
, returns anOptional
consisting of the result of applying the given function to the value or else empty.static <T> Optional<T>
mapToObj
(OptionalLong self, LongFunction<? extends T> mapper) If a value is present in theOptionalLong
, returns anOptional
consisting of the result of applying the given function to the value or else empty.static Object
Overloads the++
operator for enums.static <T> Optional<T>
orOptional
(Optional<T> self, Supplier<Optional<? extends T>> supplier) Provides similar functionality to JDK9or
on JDK8.static String
plus
(StringBuilder self, String value) Appends a String to this StringBuilder.static Object
Overloads the--
operator for enums.static void
putAt
(StringBuilder self, EmptyRange range, Object value) Supports the range subscript operator for StringBuilder.static void
putAt
(StringBuilder self, IntRange range, Object value) Supports the range subscript operator for StringBuilder.static int
size
(StringBuilder self) Deprecated.stream
(boolean[] self) Deprecated.stream
(byte[] self) Deprecated.stream
(char[] self) Deprecated.stream
(double[] self) Deprecated.stream
(float[] self) Deprecated.stream
(int[] self) Deprecated.stream
(long[] self) Deprecated.stream
(short[] self) Deprecated.static <T> Stream<T>
Deprecated.static <T> Stream<T>
stream
(Enumeration<T> self) Deprecated.static <T> Stream<T>
Deprecated.static <T> Stream<T>
Deprecated.static DoubleStream
stream
(OptionalDouble self) Deprecated.static IntStream
stream
(OptionalInt self) Deprecated.static LongStream
stream
(OptionalLong self) Deprecated.static <T> Stream<T>
stream
(Spliterator<T> self) Deprecated.static <T> Stream<T>
stream
(NullObject self) Deprecated.static <T> Stream<T>
stream
(T self) Deprecated.static <T> Stream<T>
stream
(T[] self) Deprecated.static <T> T[]
Deprecated.static <T> List<T>
toList
(BaseStream<T, ? extends BaseStream> self) Deprecated.static <T> List<T>
Deprecated.static <T> Set<T>
toSet
(BaseStream<T, ? extends BaseStream> self) Deprecated.static <T> Set<T>
Deprecated.Methods inherited from class org.codehaus.groovy.runtime.DefaultGroovyMethodsSupport
cloneSimilarCollection, cloneSimilarMap, closeQuietly, closeWithWarning, createSimilarArray, createSimilarCollection, createSimilarCollection, createSimilarCollection, createSimilarList, createSimilarMap, createSimilarOrDefaultCollection, createSimilarQueue, createSimilarSet, normaliseIndex, sameType, subListBorders, subListBorders, subListRange, writeUTF16BomIfRequired, writeUTF16BomIfRequired, writeUTF16BomIfRequired, writeUTF16BomIfRequired
-
Method Details
-
next
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
-
previous
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
-
collect
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 Futuretransform
- the closure used to transform the Future value- Returns:
- a Future allowing the transformed value to be obtained asynchronously
- Since:
- 3.0.0
-
asBoolean
Coerce anOptional
instance to aboolean
value.assert !Optional.empty().asBoolean() assert Optional.of(1234).asBoolean()
- Parameters:
optional
- the Optional- Returns:
true
if a value is present, otherwisefalse
- Since:
- 2.5.0
-
get
If a value is present in theOptionalInt
, returns the value, otherwise throwsNoSuchElementException
.assert OptionalInt.of(1234).get() == 1234
- Since:
- 3.0.0
-
get
If a value is present in theOptionalLong
, returns the value, otherwise throwsNoSuchElementException
.assert OptionalLong.of(1234L).get() == 1234L
- Since:
- 3.0.0
-
get
If a value is present in theOptionalDouble
, returns the value, otherwise throwsNoSuchElementException
.assert OptionalDouble.of(Math.PI).get() == Math.PI
- Since:
- 3.0.0
-
collect
If the optional contains a value, returns an optional containing the transformed value obtained using thetransform
closure or otherwise an empty optional.assert Optional.of("foobar").collect{ it.size() }.get() == 6 assert !Optional.empty().collect{ it.size() }.isPresent()
- Parameters:
self
- an Optionaltransform
- 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
-
filter
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
-
filter
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
-
filter
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
-
filter
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
-
mapToObj
If a value is present in theOptionalInt
, returns anOptional
consisting 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
-
mapToObj
If a value is present in theOptionalLong
, returns anOptional
consisting 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
-
mapToObj
If a value is present in theOptionalDouble
, returns anOptional
consisting 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
-
mapToInt
If a value is present in theOptionalInt
, returns anOptionalInt
consisting 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
-
mapToLong
If a value is present in theOptionalLong
, returns anOptionalLong
consisting 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
-
mapToDouble
If a value is present in theOptionalDouble
, returns anOptionalDouble
consisting 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
-
orOptional
public static <T> Optional<T> orOptional(Optional<T> self, Supplier<Optional<? extends T>> supplier) Provides similar functionality to JDK9or
on JDK8.def x = Optional.empty() def y = Optional.of('y') assert y.orOptional(() -> Optional.of('z')).get() == 'y' assert x.orOptional(() -> Optional.of('z')).get() == 'z'
- Since:
- 3.0.6
-
getPid
Gets the pid of the current Java process.- Since:
- 4.0.0
-
leftShift
Overloads the left shift operator to provide an easy way to append multiple objects as string representations to a StringBuilder.- Parameters:
self
- a StringBuildervalue
- a value to append- Returns:
- the StringBuilder on which this operation was invoked
- Since:
- 1.5.2
-
plus
Appends a String to this StringBuilder.- Parameters:
self
- a StringBuildervalue
- a String- Returns:
- a String
- Since:
- 1.5.2
-
putAt
Supports the range subscript operator for StringBuilder.- Parameters:
self
- a StringBuilderrange
- a Rangevalue
- the object that's toString() will be inserted- Since:
- 1.5.2
-
putAt
Supports the range subscript operator for StringBuilder. Index values are treated as characters within the builder.- Parameters:
self
- a StringBuilderrange
- a Rangevalue
- the object that's toString() will be inserted- Since:
- 1.5.2
-
size
Deprecated.Provides the standard Groovysize()
method for StringBuilder.- Parameters:
self
- a StringBuilder- Returns:
- the length of the StringBuilder
- Since:
- 1.5.2
- See Also:
-
stream
Deprecated. -
stream
Deprecated. -
stream
Deprecated. -
stream
Deprecated. -
stream
Deprecated. -
stream
Deprecated. -
stream
Deprecated. -
stream
Deprecated. -
stream
Deprecated. -
stream
Deprecated. -
stream
Deprecated. -
stream
Deprecated. -
stream
Deprecated. -
stream
Deprecated. -
stream
Deprecated. -
stream
Deprecated. -
stream
Deprecated. -
stream
Deprecated. -
stream
Deprecated. -
intStream
Deprecated. -
longStream
Deprecated. -
doubleStream
Deprecated. -
toArray
Deprecated. -
toList
Deprecated. -
toList
Deprecated. -
toSet
Deprecated. -
toSet
Deprecated.
-