Class PluginDefaultGroovyMethods


  • public class PluginDefaultGroovyMethods
    extends java.lang.Object
    Defines new Groovy methods which appear on normal JDK 8 classes inside the Groovy environment.
    Since:
    2.5.0
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean asBoolean​(java.util.Optional<?> optional)
      Coerce an Optional instance to a boolean value.
      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 the transform closure or otherwise an empty optional.
      static java.util.stream.Stream<java.lang.Boolean> stream​(boolean[] self)
      Returns a sequential Stream with the specified array as its source.
      static java.util.stream.Stream<java.lang.Byte> stream​(byte[] self)
      Returns a sequential Stream with the specified array as its source.
      static java.util.stream.Stream<java.lang.Character> stream​(char[] self)
      Returns a sequential Stream with the specified array as its source.
      static java.util.stream.Stream<java.lang.Double> stream​(double[] self)
      Returns a sequential Stream with the specified array as its source.
      static java.util.stream.Stream<java.lang.Float> stream​(float[] self)
      Returns a sequential Stream with the specified array as its source.
      static java.util.stream.Stream<java.lang.Integer> stream​(int[] self)
      Returns a sequential Stream with the specified array as its source.
      static java.util.stream.Stream<java.lang.Long> stream​(long[] self)
      Returns a sequential Stream with the specified array as its source.
      static java.util.stream.Stream<java.lang.Short> stream​(short[] self)
      Returns a sequential Stream with the specified array as its source.
      static <T> java.util.stream.Stream<T> stream​(T[] self)
      Returns a sequential Stream with the specified array as its source.
      static <T> java.util.List<T> toList​(java.util.stream.BaseStream<T,​? extends java.util.stream.BaseStream> stream)
      Accumulates the elements of stream into a new List.
      static <T> java.util.List<T> toList​(java.util.stream.Stream<T> stream)
      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> stream)
      Accumulates the elements of stream into a new Set.
      static <T> java.util.Set<T> toSet​(java.util.stream.Stream<T> stream)
      Accumulates the elements of stream into a new Set.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • asBoolean

        public static boolean asBoolean​(java.util.Optional<?> optional)
        Coerce an Optional instance to a boolean value.
        Parameters:
        optional - the Optional
        Returns:
        true if a value is present, otherwise false
      • collect

        public 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 the transform 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 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
      • collect

        public 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
      • toList

        public static <T> java.util.List<T> toList​(java.util.stream.Stream<T> stream)
        Accumulates the elements of stream into a new List.
        Type Parameters:
        T - the type of element
        Parameters:
        stream - the Stream
        Returns:
        a new java.util.List instance
      • toSet

        public static <T> java.util.Set<T> toSet​(java.util.stream.Stream<T> stream)
        Accumulates the elements of stream into a new Set.
        Type Parameters:
        T - the type of element
        Parameters:
        stream - the Stream
        Returns:
        a new java.util.Set instance
      • toList

        public static <T> java.util.List<T> toList​(java.util.stream.BaseStream<T,​? extends java.util.stream.BaseStream> stream)
        Accumulates the elements of stream into a new List.
        Type Parameters:
        T - the type of element
        Parameters:
        stream - the java.util.stream.BaseStream
        Returns:
        a new java.util.List instance
      • toSet

        public static <T> java.util.Set<T> toSet​(java.util.stream.BaseStream<T,​? extends java.util.stream.BaseStream> stream)
        Accumulates the elements of stream into a new Set.
        Type Parameters:
        T - the type of element
        Parameters:
        stream - the java.util.stream.BaseStream
        Returns:
        a new java.util.Set instance
      • stream

        public static <T> java.util.stream.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
      • stream

        public static java.util.stream.Stream<java.lang.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
      • stream

        public static java.util.stream.Stream<java.lang.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
      • stream

        public static java.util.stream.Stream<java.lang.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
      • stream

        public static java.util.stream.Stream<java.lang.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
      • stream

        public static java.util.stream.Stream<java.lang.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
      • stream

        public static java.util.stream.Stream<java.lang.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
      • stream

        public static java.util.stream.Stream<java.lang.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
      • stream

        public static java.util.stream.Stream<java.lang.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