From 389bdbc8c86b014a05eafb21d1b8f7edf7a5109c Mon Sep 17 00:00:00 2001 From: Andrej Fink Date: Tue, 18 Oct 2022 20:06:25 +0300 Subject: [PATCH] [jOOQ/jOOL#391] Add Predicate> Tuple.predicate(Predicate[N]) In order to beautify stream processing like that: Seq.of(tuple("marco", 24), tuple("luigi", 16), tuple("maria", 18)) .filter(Tuple.predicate((name, age) -> age > 17)) .map(Tuple.function((name, age) -> tuple("Sir / Madame " + name, age))) .forEach(Tuple.consumer((name, age) -> process(options, name, age))); --- .../java/org/jooq/lambda/tuple/Tuple.java | 167 ++++++++++++++---- .../java/org/jooq/lambda/tuple/Tuple.java | 167 ++++++++++++++---- 2 files changed, 258 insertions(+), 76 deletions(-) diff --git a/jOOL-java-8/src/main/java/org/jooq/lambda/tuple/Tuple.java b/jOOL-java-8/src/main/java/org/jooq/lambda/tuple/Tuple.java index 01c1d6b5..73378d20 100644 --- a/jOOL-java-8/src/main/java/org/jooq/lambda/tuple/Tuple.java +++ b/jOOL-java-8/src/main/java/org/jooq/lambda/tuple/Tuple.java @@ -15,50 +15,20 @@ */ package org.jooq.lambda.tuple; +import org.jooq.lambda.Seq; +import org.jooq.lambda.function.*; + import java.util.List; import java.util.Map; -import java.util.stream.Collector; import java.util.function.BiConsumer; import java.util.function.BiFunction; +import java.util.function.BiPredicate; +import java.util.function.BooleanSupplier; import java.util.function.Consumer; import java.util.function.Function; +import java.util.function.Predicate; import java.util.function.Supplier; - -import org.jooq.lambda.Seq; -import org.jooq.lambda.function.Consumer0; -import org.jooq.lambda.function.Consumer1; -import org.jooq.lambda.function.Consumer2; -import org.jooq.lambda.function.Consumer3; -import org.jooq.lambda.function.Consumer4; -import org.jooq.lambda.function.Consumer5; -import org.jooq.lambda.function.Consumer6; -import org.jooq.lambda.function.Consumer7; -import org.jooq.lambda.function.Consumer8; -import org.jooq.lambda.function.Consumer9; -import org.jooq.lambda.function.Consumer10; -import org.jooq.lambda.function.Consumer11; -import org.jooq.lambda.function.Consumer12; -import org.jooq.lambda.function.Consumer13; -import org.jooq.lambda.function.Consumer14; -import org.jooq.lambda.function.Consumer15; -import org.jooq.lambda.function.Consumer16; -import org.jooq.lambda.function.Function0; -import org.jooq.lambda.function.Function1; -import org.jooq.lambda.function.Function2; -import org.jooq.lambda.function.Function3; -import org.jooq.lambda.function.Function4; -import org.jooq.lambda.function.Function5; -import org.jooq.lambda.function.Function6; -import org.jooq.lambda.function.Function7; -import org.jooq.lambda.function.Function8; -import org.jooq.lambda.function.Function9; -import org.jooq.lambda.function.Function10; -import org.jooq.lambda.function.Function11; -import org.jooq.lambda.function.Function12; -import org.jooq.lambda.function.Function13; -import org.jooq.lambda.function.Function14; -import org.jooq.lambda.function.Function15; -import org.jooq.lambda.function.Function16; +import java.util.stream.Collector; /** * A tuple. @@ -424,6 +394,127 @@ static C return t -> consumer.accept(t.v1, t.v2, t.v3, t.v4, t.v5, t.v6, t.v7, t.v8, t.v9, t.v10, t.v11, t.v12, t.v13, t.v14, t.v15, t.v16); } + + /** + * Construct a tuple predicate of degree 0. + */ + static Predicate1 predicate(BooleanSupplier predicate) { + return t -> predicate.getAsBoolean(); + } + + /** + * Construct a tuple predicate of degree 1. + */ + static Predicate1> predicate(Predicate predicate) { + return t -> predicate.test(t.v1); + } + + /** + * Construct a tuple predicate of degree 2. + */ + static Predicate1> predicate(BiPredicate predicate) { + return t -> predicate.test(t.v1, t.v2); + } + + /** + * Construct a tuple predicate of degree 3. + */ + static Predicate1> predicate(Predicate3 predicate) { + return t -> predicate.test(t.v1, t.v2, t.v3); + } + + /** + * Construct a tuple predicate of degree 4. + */ + static Predicate1> predicate(Predicate4 predicate) { + return t -> predicate.test(t.v1, t.v2, t.v3, t.v4); + } + + /** + * Construct a tuple predicate of degree 5. + */ + static Predicate1> predicate(Predicate5 predicate) { + return t -> predicate.test(t.v1, t.v2, t.v3, t.v4, t.v5); + } + + /** + * Construct a tuple predicate of degree 6. + */ + static Predicate1> predicate(Predicate6 predicate) { + return t -> predicate.test(t.v1, t.v2, t.v3, t.v4, t.v5, t.v6); + } + + /** + * Construct a tuple predicate of degree 7. + */ + static Predicate1> predicate(Predicate7 predicate) { + return t -> predicate.test(t.v1, t.v2, t.v3, t.v4, t.v5, t.v6, t.v7); + } + + /** + * Construct a tuple predicate of degree 8. + */ + static Predicate1> predicate(Predicate8 predicate) { + return t -> predicate.test(t.v1, t.v2, t.v3, t.v4, t.v5, t.v6, t.v7, t.v8); + } + + /** + * Construct a tuple predicate of degree 9. + */ + static Predicate1> predicate(Predicate9 predicate) { + return t -> predicate.test(t.v1, t.v2, t.v3, t.v4, t.v5, t.v6, t.v7, t.v8, t.v9); + } + + /** + * Construct a tuple predicate of degree 10. + */ + static Predicate1> predicate(Predicate10 predicate) { + return t -> predicate.test(t.v1, t.v2, t.v3, t.v4, t.v5, t.v6, t.v7, t.v8, t.v9, t.v10); + } + + /** + * Construct a tuple predicate of degree 11. + */ + static Predicate1> predicate(Predicate11 predicate) { + return t -> predicate.test(t.v1, t.v2, t.v3, t.v4, t.v5, t.v6, t.v7, t.v8, t.v9, t.v10, t.v11); + } + + /** + * Construct a tuple predicate of degree 12. + */ + static Predicate1> predicate(Predicate12 predicate) { + return t -> predicate.test(t.v1, t.v2, t.v3, t.v4, t.v5, t.v6, t.v7, t.v8, t.v9, t.v10, t.v11, t.v12); + } + + /** + * Construct a tuple predicate of degree 13. + */ + static Predicate1> predicate(Predicate13 predicate) { + return t -> predicate.test(t.v1, t.v2, t.v3, t.v4, t.v5, t.v6, t.v7, t.v8, t.v9, t.v10, t.v11, t.v12, t.v13); + } + + /** + * Construct a tuple predicate of degree 14. + */ + static Predicate1> predicate(Predicate14 predicate) { + return t -> predicate.test(t.v1, t.v2, t.v3, t.v4, t.v5, t.v6, t.v7, t.v8, t.v9, t.v10, t.v11, t.v12, t.v13, t.v14); + } + + /** + * Construct a tuple predicate of degree 15. + */ + static Predicate1> predicate(Predicate15 predicate) { + return t -> predicate.test(t.v1, t.v2, t.v3, t.v4, t.v5, t.v6, t.v7, t.v8, t.v9, t.v10, t.v11, t.v12, t.v13, t.v14, t.v15); + } + + /** + * Construct a tuple predicate of degree 16. + */ + static Predicate1> predicate(Predicate16 predicate) { + return t -> predicate.test(t.v1, t.v2, t.v3, t.v4, t.v5, t.v6, t.v7, t.v8, t.v9, t.v10, t.v11, t.v12, t.v13, t.v14, t.v15, t.v16); + } + + /** * Construct a tuple collector of degree 1. */ @@ -1428,4 +1519,4 @@ static > Range range(T lowerInclusive, T upperInclusi * The degree of this tuple. */ int degree(); -} +} \ No newline at end of file diff --git a/jOOL/src/main/java/org/jooq/lambda/tuple/Tuple.java b/jOOL/src/main/java/org/jooq/lambda/tuple/Tuple.java index 01c1d6b5..73378d20 100644 --- a/jOOL/src/main/java/org/jooq/lambda/tuple/Tuple.java +++ b/jOOL/src/main/java/org/jooq/lambda/tuple/Tuple.java @@ -15,50 +15,20 @@ */ package org.jooq.lambda.tuple; +import org.jooq.lambda.Seq; +import org.jooq.lambda.function.*; + import java.util.List; import java.util.Map; -import java.util.stream.Collector; import java.util.function.BiConsumer; import java.util.function.BiFunction; +import java.util.function.BiPredicate; +import java.util.function.BooleanSupplier; import java.util.function.Consumer; import java.util.function.Function; +import java.util.function.Predicate; import java.util.function.Supplier; - -import org.jooq.lambda.Seq; -import org.jooq.lambda.function.Consumer0; -import org.jooq.lambda.function.Consumer1; -import org.jooq.lambda.function.Consumer2; -import org.jooq.lambda.function.Consumer3; -import org.jooq.lambda.function.Consumer4; -import org.jooq.lambda.function.Consumer5; -import org.jooq.lambda.function.Consumer6; -import org.jooq.lambda.function.Consumer7; -import org.jooq.lambda.function.Consumer8; -import org.jooq.lambda.function.Consumer9; -import org.jooq.lambda.function.Consumer10; -import org.jooq.lambda.function.Consumer11; -import org.jooq.lambda.function.Consumer12; -import org.jooq.lambda.function.Consumer13; -import org.jooq.lambda.function.Consumer14; -import org.jooq.lambda.function.Consumer15; -import org.jooq.lambda.function.Consumer16; -import org.jooq.lambda.function.Function0; -import org.jooq.lambda.function.Function1; -import org.jooq.lambda.function.Function2; -import org.jooq.lambda.function.Function3; -import org.jooq.lambda.function.Function4; -import org.jooq.lambda.function.Function5; -import org.jooq.lambda.function.Function6; -import org.jooq.lambda.function.Function7; -import org.jooq.lambda.function.Function8; -import org.jooq.lambda.function.Function9; -import org.jooq.lambda.function.Function10; -import org.jooq.lambda.function.Function11; -import org.jooq.lambda.function.Function12; -import org.jooq.lambda.function.Function13; -import org.jooq.lambda.function.Function14; -import org.jooq.lambda.function.Function15; -import org.jooq.lambda.function.Function16; +import java.util.stream.Collector; /** * A tuple. @@ -424,6 +394,127 @@ static C return t -> consumer.accept(t.v1, t.v2, t.v3, t.v4, t.v5, t.v6, t.v7, t.v8, t.v9, t.v10, t.v11, t.v12, t.v13, t.v14, t.v15, t.v16); } + + /** + * Construct a tuple predicate of degree 0. + */ + static Predicate1 predicate(BooleanSupplier predicate) { + return t -> predicate.getAsBoolean(); + } + + /** + * Construct a tuple predicate of degree 1. + */ + static Predicate1> predicate(Predicate predicate) { + return t -> predicate.test(t.v1); + } + + /** + * Construct a tuple predicate of degree 2. + */ + static Predicate1> predicate(BiPredicate predicate) { + return t -> predicate.test(t.v1, t.v2); + } + + /** + * Construct a tuple predicate of degree 3. + */ + static Predicate1> predicate(Predicate3 predicate) { + return t -> predicate.test(t.v1, t.v2, t.v3); + } + + /** + * Construct a tuple predicate of degree 4. + */ + static Predicate1> predicate(Predicate4 predicate) { + return t -> predicate.test(t.v1, t.v2, t.v3, t.v4); + } + + /** + * Construct a tuple predicate of degree 5. + */ + static Predicate1> predicate(Predicate5 predicate) { + return t -> predicate.test(t.v1, t.v2, t.v3, t.v4, t.v5); + } + + /** + * Construct a tuple predicate of degree 6. + */ + static Predicate1> predicate(Predicate6 predicate) { + return t -> predicate.test(t.v1, t.v2, t.v3, t.v4, t.v5, t.v6); + } + + /** + * Construct a tuple predicate of degree 7. + */ + static Predicate1> predicate(Predicate7 predicate) { + return t -> predicate.test(t.v1, t.v2, t.v3, t.v4, t.v5, t.v6, t.v7); + } + + /** + * Construct a tuple predicate of degree 8. + */ + static Predicate1> predicate(Predicate8 predicate) { + return t -> predicate.test(t.v1, t.v2, t.v3, t.v4, t.v5, t.v6, t.v7, t.v8); + } + + /** + * Construct a tuple predicate of degree 9. + */ + static Predicate1> predicate(Predicate9 predicate) { + return t -> predicate.test(t.v1, t.v2, t.v3, t.v4, t.v5, t.v6, t.v7, t.v8, t.v9); + } + + /** + * Construct a tuple predicate of degree 10. + */ + static Predicate1> predicate(Predicate10 predicate) { + return t -> predicate.test(t.v1, t.v2, t.v3, t.v4, t.v5, t.v6, t.v7, t.v8, t.v9, t.v10); + } + + /** + * Construct a tuple predicate of degree 11. + */ + static Predicate1> predicate(Predicate11 predicate) { + return t -> predicate.test(t.v1, t.v2, t.v3, t.v4, t.v5, t.v6, t.v7, t.v8, t.v9, t.v10, t.v11); + } + + /** + * Construct a tuple predicate of degree 12. + */ + static Predicate1> predicate(Predicate12 predicate) { + return t -> predicate.test(t.v1, t.v2, t.v3, t.v4, t.v5, t.v6, t.v7, t.v8, t.v9, t.v10, t.v11, t.v12); + } + + /** + * Construct a tuple predicate of degree 13. + */ + static Predicate1> predicate(Predicate13 predicate) { + return t -> predicate.test(t.v1, t.v2, t.v3, t.v4, t.v5, t.v6, t.v7, t.v8, t.v9, t.v10, t.v11, t.v12, t.v13); + } + + /** + * Construct a tuple predicate of degree 14. + */ + static Predicate1> predicate(Predicate14 predicate) { + return t -> predicate.test(t.v1, t.v2, t.v3, t.v4, t.v5, t.v6, t.v7, t.v8, t.v9, t.v10, t.v11, t.v12, t.v13, t.v14); + } + + /** + * Construct a tuple predicate of degree 15. + */ + static Predicate1> predicate(Predicate15 predicate) { + return t -> predicate.test(t.v1, t.v2, t.v3, t.v4, t.v5, t.v6, t.v7, t.v8, t.v9, t.v10, t.v11, t.v12, t.v13, t.v14, t.v15); + } + + /** + * Construct a tuple predicate of degree 16. + */ + static Predicate1> predicate(Predicate16 predicate) { + return t -> predicate.test(t.v1, t.v2, t.v3, t.v4, t.v5, t.v6, t.v7, t.v8, t.v9, t.v10, t.v11, t.v12, t.v13, t.v14, t.v15, t.v16); + } + + /** * Construct a tuple collector of degree 1. */ @@ -1428,4 +1519,4 @@ static > Range range(T lowerInclusive, T upperInclusi * The degree of this tuple. */ int degree(); -} +} \ No newline at end of file