public class PluginDefaultGroovyMethods extends DefaultGroovyMethodsSupport
Modifier and Type | Method and Description |
---|---|
static boolean |
asBoolean(Optional<?> optional)
Coerce an
Optional instance to a boolean value. |
static <S,T> Future<T> |
collect(Future<S> self,
Closure<T> transform)
Returns a Future asynchronously returning a transformed result.
|
static <S,T> Optional<T> |
collect(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 <T> Optional<T> |
filter(Optional<?> self,
Class<T> type)
Tests given value against specified type and changes generics of result.
|
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. |
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. |
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. |
static double |
get(OptionalDouble self)
If a value is present in the
OptionalDouble , returns the value,
otherwise throws NoSuchElementException . |
static int |
get(OptionalInt self)
If a value is present in the
OptionalInt , returns the value,
otherwise throws NoSuchElementException . |
static long |
get(OptionalLong self)
If a value is present in the
OptionalLong , returns the value,
otherwise throws NoSuchElementException . |
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 <T> 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. |
static <T> 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. |
static <T> 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. |
static <T> 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. |
static <T> 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. |
static <T> 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. |
static Object |
next(Enum self)
This method is called by the ++ operator for enums.
|
static String |
plus(StringBuilder self,
String value)
Appends a String to this StringBuilder.
|
static Object |
previous(Enum self)
This method is called by the -- operator for enums.
|
static void |
putAt(StringBuilder self,
EmptyRange range,
Object value)
Support the range subscript operator for StringBuilder.
|
static void |
putAt(StringBuilder self,
IntRange range,
Object value)
Support the range subscript operator for StringBuilder.
|
static int |
size(StringBuilder builder)
Standard Groovy size() method for StringBuilders.
|
static Stream<Boolean> |
stream(boolean[] self)
Returns a sequential
Stream with the specified array as its
source. |
static Stream<Byte> |
stream(byte[] self)
Returns a sequential
Stream with the specified array as its
source. |
static Stream<Character> |
stream(char[] self)
Returns a sequential
Stream with the specified array as its
source. |
static Stream<Double> |
stream(double[] self)
Returns a sequential
Stream with the specified array as its
source. |
static <T> Stream<T> |
stream(Enumeration<T> self)
Returns a sequential
Stream with the specified element(s) as its
source. |
static Stream<Float> |
stream(float[] self)
Returns a sequential
Stream with the specified array as its
source. |
static Stream<Integer> |
stream(int[] self)
Returns a sequential
Stream with the specified array as its
source. |
static <T> Stream<T> |
stream(Iterable<T> self)
Returns a sequential
Stream with the specified element(s) as its
source. |
static <T> Stream<T> |
stream(Iterator<T> self)
Returns a sequential
Stream with the specified element(s) as its
source. |
static Stream<Long> |
stream(long[] self)
Returns a sequential
Stream with the specified array as its
source. |
static <T> Stream<T> |
stream(NullObject self)
Returns an empty sequential
Stream . |
static <T> Stream<T> |
stream(Optional<T> self)
|
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. |
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. |
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. |
static Stream<Short> |
stream(short[] self)
Returns a sequential
Stream with the specified array as its
source. |
static <T> Stream<T> |
stream(Spliterator<T> self)
Returns a sequential
Stream with the specified element(s) as its
source. |
static <T> Stream<T> |
stream(T self)
Returns a sequential
Stream containing a single element. |
static <T> Stream<T> |
stream(T[] self)
Returns a sequential
Stream with the specified array as its
source. |
static <T> List<T> |
toList(BaseStream<T,? extends BaseStream> self)
Accumulates the elements of stream into a new List.
|
static <T> List<T> |
toList(Stream<T> self)
Accumulates the elements of stream into a new List.
|
static <T> Set<T> |
toSet(BaseStream<T,? extends BaseStream> self)
Accumulates the elements of stream into a new Set.
|
static <T> Set<T> |
toSet(Stream<T> self)
Accumulates the elements of stream into a new Set.
|
cloneSimilarCollection, cloneSimilarMap, closeQuietly, closeWithWarning, createSimilarArray, createSimilarCollection, createSimilarCollection, createSimilarCollection, createSimilarList, createSimilarMap, createSimilarOrDefaultCollection, createSimilarQueue, createSimilarSet, normaliseIndex, sameType, subListBorders, subListBorders, writeUTF16BomIfRequired, writeUTF16BomIfRequired, writeUTF16BomIfRequired, writeUTF16BomIfRequired
public static boolean asBoolean(Optional<?> optional)
Optional
instance to a boolean
value.
assert !Optional.empty().asBoolean() assert Optional.of(1234).asBoolean()
optional
- the Optionaltrue
if a value is present, otherwise false
public static int get(OptionalInt self)
OptionalInt
, returns the value,
otherwise throws NoSuchElementException
.
assert OptionalInt.of(1234).get() == 1234
public static long get(OptionalLong self)
OptionalLong
, returns the value,
otherwise throws NoSuchElementException
.
assert OptionalLong.of(1234L).get() == 1234L
public static double get(OptionalDouble self)
OptionalDouble
, returns the value,
otherwise throws NoSuchElementException
.
assert OptionalDouble.of(Math.PI).get() == Math.PI
public static <T> Optional<T> filter(Optional<?> self, Class<T> type)
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)
public static OptionalInt filter(OptionalInt self, IntPredicate test)
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
public static OptionalLong filter(OptionalLong self, LongPredicate test)
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
public static OptionalDouble filter(OptionalDouble self, DoublePredicate test)
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
public static <T> Optional<T> mapToObj(OptionalInt self, IntFunction<? extends T> mapper)
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'
public static <T> Optional<T> mapToObj(OptionalLong self, LongFunction<? extends T> mapper)
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'
public static <T> Optional<T> mapToObj(OptionalDouble self, DoubleFunction<? extends T> mapper)
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')
public static <T> OptionalInt mapToInt(Optional<T> self, ToIntFunction<? super T> mapper)
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
public static <T> OptionalLong mapToLong(Optional<T> self, ToLongFunction<? super T> mapper)
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
public static <T> OptionalDouble mapToDouble(Optional<T> self, ToDoubleFunction<? super T> mapper)
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
public static <S,T> Optional<T> collect(Optional<S> self, Closure<T> transform)
transform
closure
or otherwise an empty optional.
assert Optional.of("foobar").collect{ it.size() }.get() == 6 assert !Optional.empty().collect{ it.size() }.isPresent()
self
- an Optionaltransform
- the closure used to transform the optional value if presentpublic static <S,T> Future<T> collect(Future<S> self, Closure<T> transform)
import java.util.concurrent.* def executor = Executors.newSingleThreadExecutor() Futurefoobar = executor.submit{ "foobar" } Future foobarSize = foobar.collect{ it.size() } assert foobarSize.get() == 6 executor.shutdown()
self
- a Futuretransform
- the closure used to transform the Future valuepublic static Object next(Enum self)
self
- an Enumpublic static Object previous(Enum self)
self
- an Enumpublic static int size(StringBuilder builder)
builder
- a StringBuilderpublic static StringBuilder leftShift(StringBuilder self, Object value)
self
- a StringBuildervalue
- a value to appendpublic static void putAt(StringBuilder self, IntRange range, Object value)
self
- a StringBuilderrange
- a Rangevalue
- the object that's toString() will be insertedpublic static void putAt(StringBuilder self, EmptyRange range, Object value)
self
- a StringBuilderrange
- a Rangevalue
- the object that's toString() will be insertedpublic static String plus(StringBuilder self, String value)
self
- a StringBuildervalue
- a Stringpublic static <T> List<T> toList(Stream<T> self)
T
- the type of elementself
- the Streamjava.util.List
instancepublic static <T> Set<T> toSet(Stream<T> self)
T
- the type of elementself
- the Streamjava.util.Set
instancepublic static <T> List<T> toList(BaseStream<T,? extends BaseStream> self)
T
- the type of elementself
- the java.util.stream.BaseStream
java.util.List
instancepublic static <T> Set<T> toSet(BaseStream<T,? extends BaseStream> self)
T
- the type of elementself
- the java.util.stream.BaseStream
java.util.Set
instancepublic static <T> Stream<T> stream(NullObject self)
Stream
.
def item = null assert item.stream().toList() == [] assert !item.stream().findFirst().isPresent()
public static <T> Stream<T> stream(T self)
Stream
containing a single element.
def item = 'string' assert item.stream().toList() == ['string'] assert item.stream().findFirst().isPresent()
public static <T> Stream<T> stream(T[] self)
Stream
with the specified array as its
source.T
- The type of the array elementsself
- The array, assumed to be unmodified during useStream
for the arraypublic static Stream<Integer> stream(int[] self)
Stream
with the specified array as its
source.self
- The array, assumed to be unmodified during useStream
for the arraypublic static Stream<Long> stream(long[] self)
Stream
with the specified array as its
source.self
- The array, assumed to be unmodified during useStream
for the arraypublic static Stream<Double> stream(double[] self)
Stream
with the specified array as its
source.self
- The array, assumed to be unmodified during useStream
for the arraypublic static Stream<Character> stream(char[] self)
Stream
with the specified array as its
source.self
- The array, assumed to be unmodified during useStream
for the arraypublic static Stream<Byte> stream(byte[] self)
Stream
with the specified array as its
source.self
- The array, assumed to be unmodified during useStream
for the arraypublic static Stream<Short> stream(short[] self)
Stream
with the specified array as its
source.self
- The array, assumed to be unmodified during useStream
for the arraypublic static Stream<Boolean> stream(boolean[] self)
Stream
with the specified array as its
source.self
- The array, assumed to be unmodified during useStream
for the arraypublic static Stream<Float> stream(float[] self)
Stream
with the specified array as its
source.self
- The array, assumed to be unmodified during useStream
for the arraypublic static <T> Stream<T> stream(Enumeration<T> self)
Stream
with the specified element(s) as its
source.
def tokens = new StringTokenizer('one two') assert tokens.stream().toList() == ['one', 'two']
public static <T> Stream<T> stream(Iterable<T> self)
Stream
with 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']
public static <T> Stream<T> stream(Iterator<T> self)
Stream
with the specified element(s) as its
source.
[].iterator().stream().toList().isEmpty() ['one', 'two'].iterator().stream().toList() == ['one', 'two']
public static <T> Stream<T> stream(Spliterator<T> self)
Stream
with the specified element(s) as its
source.
[].spliterator().stream().toList().isEmpty() ['one', 'two'].spliterator().stream().toList() == ['one', 'two']
public static <T> Stream<T> stream(Optional<T> self)
Optional
, returns a Stream
with the value as its source or else an empty stream.public static IntStream stream(OptionalInt self)
OptionalInt
, returns an IntStream
with the value as its source or else an empty stream.public static LongStream stream(OptionalLong self)
OptionalLong
, returns a LongStream
with the value as its source or else an empty stream.public static DoubleStream stream(OptionalDouble self)
OptionalDouble
, returns a DoubleStream
with the value as its source or else an empty stream.