Package: org.codehaus.groovy.vmplugin.v8

## [Java] Class PluginDefaultGroovyMethods

- 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

- - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `public static boolean` | `asBoolean(Optional<?> optional)` Coerce an `Optional` instance to a `boolean` value.
    `<S, T>` | `public static Future<T>` | `collect(Future<S> self, Closure<T> transform)` Returns a `Future` asynchronously returning a transformed result.
    `<S, T>` | `public static Optional<T>` | `collect(Optional<S> self, Closure<T> transform)` If a value is present in the `Optional`, returns transformed value obtained using the `transform` closure or no value as an optional.
    `` | `public static DoubleStream` | `doubleStream(double[] self)`
    `<T>` | `public static Optional<T>` | `filter(Optional<?> self, Class<T> type)` Tests given value against specified type and changes generics of result.
    `` | `public static OptionalInt` | `filter(OptionalInt self, IntPredicate test)` If a value is present in the `OptionalInt`, tests the value using the given predicate and returns the optional if the test returns true or else empty.
    `` | `public static OptionalLong` | `filter(OptionalLong self, LongPredicate test)` If a value is present in the `OptionalLong`, tests the value using the given predicate and returns the optional if the test returns true or else empty.
    `` | `public static OptionalDouble` | `filter(OptionalDouble self, DoublePredicate test)` If a value is present in the `OptionalDouble`, tests the value using the given predicate and returns the optional if the test returns true or empty otherwise.
    `` | `public static int` | `get(OptionalInt self)` If a value is present in the `OptionalInt`, returns the value.
    `` | `public static long` | `get(OptionalLong self)` If a value is present in the `OptionalLong`, returns the value.
    `` | `public static double` | `get(OptionalDouble self)` If a value is present in the `OptionalDouble`, returns the value.
    `<T>` | `public static T` | `getAt(Optional<T> self, int index)` If a value is present in the `Optional`, returns the value or null.
    `` | `public static String` | `getPid(Runtime self)` Gets the pid of the current Java process.
    `` | `public static IntStream` | `intStream(int[] self)`
    `` | `public 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.
    `` | `public static LongStream` | `longStream(long[] self)`
    `<T>` | `public static OptionalDouble` | `mapToDouble(Optional<T> self, ToDoubleFunction<? super T> mapper)` If a value is present in the `OptionalDouble`, returns an `OptionalDouble` consisting of the result of applying the given function to the value or else empty.
    `<T>` | `public static OptionalInt` | `mapToInt(Optional<T> self, ToIntFunction<? super T> mapper)` If a value is present in the `OptionalInt`, returns an `OptionalInt` consisting of the result of applying the given function to the value or else empty.
    `<T>` | `public static OptionalLong` | `mapToLong(Optional<T> self, ToLongFunction<? super T> mapper)` If a value is present in the `OptionalLong`, returns an `OptionalLong` consisting of the result of applying the given function to the value or else empty.
    `<T>` | `public static Optional<T>` | `mapToObj(OptionalInt self, IntFunction<? extends T> mapper)` If a value is present in the `OptionalInt`, returns an `Optional` consisting of the result of applying the given function to the value or else empty.
    `<T>` | `public static Optional<T>` | `mapToObj(OptionalLong self, LongFunction<? extends T> mapper)` If a value is present in the `OptionalLong`, returns an `Optional` consisting of the result of applying the given function to the value or else empty.
    `<T>` | `public static Optional<T>` | `mapToObj(OptionalDouble self, DoubleFunction<? extends T> mapper)` If a value is present in the `OptionalDouble`, returns an `Optional` consisting of the result of applying the given function to the value or else empty.
    `` | `public static Object` | `next(Enum self)` Overloads the `++` operator for enums.
    `<T>` | `public static Optional<T>` | `orOptional(Optional<T> self, Supplier<Optional<? extends T>> supplier)` Provides similar functionality to JDK9 `or` on JDK8.
    `` | `public static OptionalInt` | `peek(OptionalInt self, IntConsumer action)` If a value is present in the `OptionalInt`, executes the specified `action` with the value as input and then returns `self`.
    `` | `public static OptionalLong` | `peek(OptionalLong self, LongConsumer action)` If a value is present in the `OptionalLong`, executes the specified `action` with the value as input and then returns `self`.
    `` | `public static OptionalDouble` | `peek(OptionalDouble self, DoubleConsumer action)` If a value is present in the `OptionalDouble`, executes the specified `action` with the value as input and then returns `self`.
    `<T>` | `public static Optional<T>` | `peek(Optional<T> self, Consumer<? super T> action)` If a value is present in the `Optional`, executes the specified `action` with the value as input and then returns `self`.
    `` | `public static String` | `plus(StringBuilder self, String value)` Appends a String to this StringBuilder.
    `` | `public static Object` | `previous(Enum self)` Overloads the `--` operator for enums.
    `` | `public static void` | `putAt(StringBuilder self, EmptyRange range, Object value)` Supports the range subscript operator for StringBuilder.
    `` | `public static void` | `putAt(StringBuilder self, IntRange range, Object value)` Supports the range subscript operator for StringBuilder.
    `` | `public static int` | `size(StringBuilder self)` Provides the standard Groovy `size()` method for StringBuilder.
    `<T>` | `public static Stream<T>` | `stream(T self)`
    `<T>` | `public static Stream<T>` | `stream(T[] self)`
    `` | `public static Stream<Integer>` | `stream(int[] self)`
    `` | `public static Stream<Long>` | `stream(long[] self)`
    `` | `public static Stream<Double>` | `stream(double[] self)`
    `` | `public static Stream<Character>` | `stream(char[] self)`
    `` | `public static Stream<Byte>` | `stream(byte[] self)`
    `` | `public static Stream<Short>` | `stream(short[] self)`
    `` | `public static Stream<Boolean>` | `stream(boolean[] self)`
    `` | `public static Stream<Float>` | `stream(float[] self)`
    `<T>` | `public static Stream<T>` | `stream(Enumeration<T> self)`
    `<T>` | `public static Stream<T>` | `stream(Iterable<T> self)`
    `<T>` | `public static Stream<T>` | `stream(Iterator<T> self)`
    `<T>` | `public static Stream<T>` | `stream(Spliterator<T> self)`
    `<T>` | `public static Stream<T>` | `stream(NullObject self)`
    `<T>` | `public static Stream<T>` | `stream(Optional<T> self)`
    `` | `public static IntStream` | `stream(OptionalInt self)`
    `` | `public static LongStream` | `stream(OptionalLong self)`
    `` | `public static DoubleStream` | `stream(OptionalDouble self)`
    `<T>` | `public static T[]` | `toArray(Stream<? extends T> self, Class<T> type)`
    `<T>` | `public static List<T>` | `toList(Stream<T> self)`
    `<T>` | `public static List<T>` | `toList(BaseStream<T, ? extends BaseStream> self)`
    `<T>` | `public static Set<T>` | `toSet(Stream<T> self)`
    `<T>` | `public static Set<T>` | `toSet(BaseStream<T, ? extends BaseStream> self)`

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class DefaultGroovyMethodsSupport` | `cloneSimilarCollection, cloneSimilarMap, closeQuietly, closeWithWarning, createSimilarArray, createSimilarCollection, createSimilarCollection, createSimilarCollection, createSimilarList, createSimilarMap, createSimilarOrDefaultCollection, createSimilarQueue, createSimilarSet, normaliseIndex, sameType, sameType, subListBorders, subListBorders, subListRange, writeUTF16BomIfRequired, writeUTF16BomIfRequired, writeUTF16BomIfRequired, writeUTF16BomIfRequired`

- - ### Method Detail

    - #### public static boolean asBoolean(Optional<?> optional)

      Coerce an `Optional` instance to a `boolean` value.

           assert !Optional.empty().asBoolean()
           assert Optional.of(1234).asBoolean()

      Returns:
        `true` if a value is present, `false` otherwise
      Since:
        2.5.0

    - #### <S, T> public static Future<T> collect(Future<S> self, @ClosureParams(FirstParam.FirstGenericType.class)
      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

    - #### <S, T> public static Optional<T> collect(Optional<S> self, @ClosureParams(FirstParam.FirstGenericType.class)
      Closure<T> transform)

      If a value is present in the `Optional`, returns transformed value obtained using the `transform` closure or no value as an optional.

           assert Optional.of("foobar").collect{ it.size() }.get() == 6
           assert !Optional.empty().collect{ it.size() }.isPresent()

      Parameters:
        `transform` - the closure used to transform the optional value if present
      Returns:
        an Optional containing the transformed value or empty if the input is empty or the transform returns null
      Since:
        3.0.0

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

    - #### <T> public static Optional<T> filter(Optional<?> self, 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

    - #### public static OptionalInt filter(OptionalInt self, IntPredicate test)

      If a value is present in the `OptionalInt`, 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

    - #### public static OptionalLong filter(OptionalLong self, LongPredicate test)

      If a value is present in the `OptionalLong`, 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

    - #### public static OptionalDouble filter(OptionalDouble self, DoublePredicate test)

      If a value is present in the `OptionalDouble`, 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

    - #### public static int get(OptionalInt self)

      If a value is present in the `OptionalInt`, returns the value.

           assert OptionalInt.of(1234).get() == 1234

      throws:
        NoSuchElementException if no value is present
      Since:
        3.0.0

    - #### public static long get(OptionalLong self)

      If a value is present in the `OptionalLong`, returns the value.

           assert OptionalLong.of(1234L).get() == 1234L

      throws:
        NoSuchElementException if no value is present
      Since:
        3.0.0

    - #### public static double get(OptionalDouble self)

      If a value is present in the `OptionalDouble`, returns the value.

           assert OptionalDouble.of(Math.PI).get() == Math.PI

      throws:
        NoSuchElementException if no value is present
      Since:
        3.0.0

    - #### <T> public static T getAt(Optional<T> self, int index)

      If a value is present in the `Optional`, returns the value or null.

           def opt = Optional.empty()
           assert opt[-1] == null
           assert opt[0] == null
           opt = Optional.of('')
           assert opt[-1] == ''
           assert opt[0] == ''

           groovy.test.GroovyAssert.shouldFail(IndexOutOfBoundsException) { opt[1] }

           // use via destructuring
           opt = Optional.empty()
           def (String s) = opt
           assert s == null
           opt = Optional.of('')
           (s) = opt
           assert s == ''

      throws:
        IndexOutOfBoundsException if index is not 0 or -1
      Since:
        5.0.0

    - #### public static String getPid(Runtime self)

      Gets the pid of the current Java process.

      Since:
        4.0.0

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

    - #### public 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.

      Parameters:
        `self` - a StringBuilder
        `value` - a value to append
      Returns:
        the StringBuilder on which this operation was invoked
      Since:
        1.5.2

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

    - #### <T> public static OptionalDouble mapToDouble(Optional<T> self, ToDoubleFunction<? super T> mapper)

      If a value is present in the `OptionalDouble`, returns an `OptionalDouble` 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

    - #### <T> public static OptionalInt mapToInt(Optional<T> self, ToIntFunction<? super T> mapper)

      If a value is present in the `OptionalInt`, returns an `OptionalInt` 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

    - #### <T> public static OptionalLong mapToLong(Optional<T> self, ToLongFunction<? super T> mapper)

      If a value is present in the `OptionalLong`, returns an `OptionalLong` 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

    - #### <T> public static Optional<T> mapToObj(OptionalInt self, IntFunction<? extends T> mapper)

      If a value is present in the `OptionalInt`, returns an `Optional` 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

    - #### <T> public static Optional<T> mapToObj(OptionalLong self, LongFunction<? extends T> mapper)

      If a value is present in the `OptionalLong`, returns an `Optional` 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

    - #### <T> public static Optional<T> mapToObj(OptionalDouble self, DoubleFunction<? extends T> mapper)

      If a value is present in the `OptionalDouble`, returns an `Optional` 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

    - #### public static Object next(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

    - #### <T> public static Optional<T> orOptional(Optional<T> self, Supplier<Optional<? extends T>> supplier)

      Provides similar functionality to JDK9 `or` 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

    - #### public static OptionalInt peek(OptionalInt self, IntConsumer action)

      If a value is present in the `OptionalInt`, executes the specified `action` with the value as input and then returns `self`.

           boolean called = false
           def opt = OptionalInt.empty()
           def out = opt.peek{ called = true }
           assert out === opt
           assert !called

           opt = OptionalInt.of(42)
           out = opt.peek{ assert it == 42; called = true }
           assert out === opt
           assert called

      Since:
        5.0.0

    - #### public static OptionalLong peek(OptionalLong self, LongConsumer action)

      If a value is present in the `OptionalLong`, executes the specified `action` with the value as input and then returns `self`.

           boolean called = false
           def opt = OptionalLong.empty()
           def out = opt.peek{ called = true }
           assert out === opt
           assert !called

           opt = OptionalLong.of(42L)
           out = opt.peek{ assert it == 42L; called = true }
           assert out === opt
           assert called

      Since:
        5.0.0

    - #### public static OptionalDouble peek(OptionalDouble self, DoubleConsumer action)

      If a value is present in the `OptionalDouble`, executes the specified `action` with the value as input and then returns `self`.

           boolean called = false
           def opt = OptionalDouble.empty()
           def out = opt.peek{ called = true }
           assert out === opt
           assert !called

           opt = OptionalDouble.of(Math.PI)
           out = opt.peek{ assert it == Math.PI; called = true }
           assert out === opt
           assert called

      Since:
        5.0.0

    - #### <T> public static Optional<T> peek(Optional<T> self, Consumer<? super T> action)

      If a value is present in the `Optional`, executes the specified `action` with the value as input and then returns `self`.

           boolean called = false
           def opt = Optional.empty()
           def out = opt.peek{ called = true }
           assert out === opt
           assert !called

           opt = Optional.of('x')
           out = opt.peek{ assert it == 'x'; called = true }
           assert out === opt
           assert called

      Since:
        5.0.0

    - #### public static String plus(StringBuilder self, String value)

      Appends a String to this StringBuilder.

      Parameters:
        `self` - a StringBuilder
        `value` - a String
      Returns:
        a String
      Since:
        1.5.2

    - #### public static Object previous(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

    - #### public static void putAt(StringBuilder self, EmptyRange range, Object value)

      Supports 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

    - #### public static void putAt(StringBuilder self, IntRange range, Object value)

      Supports 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

    - #### @Deprecated
      public static int size(StringBuilder self)

      Provides the standard Groovy `size()` method for StringBuilder.

      Parameters:
        `self` - a StringBuilder
      Returns:
        the length of the StringBuilder
      Since:
        1.5.2
      See Also:
        StringGroovyMethods.size

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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