From 7000da409a4927de0a2a9c2ae81ee9b439311803 Mon Sep 17 00:00:00 2001 From: Darin Kelkhoff Date: Wed, 18 Jan 2023 12:04:28 -0600 Subject: [PATCH] moving standard lambdas to common package --- .../actions/async/AsyncRecordPipeLoop.java | 34 ++-------- .../qqq/backend/core/logging/LogPair.java | 66 ++++++++++++++++++- .../core/utils/lambdas/UnsafeConsumer.java | 35 ++++++++++ .../core/utils/lambdas/UnsafeFunction.java | 35 ++++++++++ .../core/utils/lambdas/UnsafeSupplier.java | 35 ++++++++++ 5 files changed, 174 insertions(+), 31 deletions(-) create mode 100644 qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/utils/lambdas/UnsafeConsumer.java create mode 100644 qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/utils/lambdas/UnsafeFunction.java create mode 100644 qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/utils/lambdas/UnsafeSupplier.java diff --git a/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/actions/async/AsyncRecordPipeLoop.java b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/actions/async/AsyncRecordPipeLoop.java index aba09f0f..3817ad2d 100644 --- a/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/actions/async/AsyncRecordPipeLoop.java +++ b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/actions/async/AsyncRecordPipeLoop.java @@ -27,8 +27,10 @@ import java.util.Optional; import java.util.concurrent.TimeUnit; import com.kingsrook.qqq.backend.core.actions.reporting.RecordPipe; import com.kingsrook.qqq.backend.core.exceptions.QException; -import com.kingsrook.qqq.backend.core.utils.QLogger; +import com.kingsrook.qqq.backend.core.logging.QLogger; import com.kingsrook.qqq.backend.core.utils.SleepUtils; +import com.kingsrook.qqq.backend.core.utils.lambdas.UnsafeFunction; +import com.kingsrook.qqq.backend.core.utils.lambdas.UnsafeSupplier; /******************************************************************************* @@ -61,7 +63,7 @@ public class AsyncRecordPipeLoop ** @param consumer lambda that consumes records from the pipe * e.g., a transform/load step. *******************************************************************************/ - public int run(String jobName, Integer recordLimit, RecordPipe recordPipe, UnsafeFunction supplier, UnsafeSupplier consumer) throws QException + public int run(String jobName, Integer recordLimit, RecordPipe recordPipe, UnsafeFunction supplier, UnsafeSupplier consumer) throws QException { /////////////////////////////////////////////////// // start the extraction function as an async job // @@ -174,32 +176,4 @@ public class AsyncRecordPipeLoop return (recordCount); } - - - /******************************************************************************* - ** - *******************************************************************************/ - @FunctionalInterface - public interface UnsafeFunction - { - /******************************************************************************* - ** - *******************************************************************************/ - R apply(T t) throws QException; - } - - - - /******************************************************************************* - ** - *******************************************************************************/ - @FunctionalInterface - public interface UnsafeSupplier - { - /******************************************************************************* - ** - *******************************************************************************/ - T get() throws QException; - } - } diff --git a/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/logging/LogPair.java b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/logging/LogPair.java index f819217c..fd654a0f 100644 --- a/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/logging/LogPair.java +++ b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/logging/LogPair.java @@ -25,6 +25,7 @@ package com.kingsrook.qqq.backend.core.logging; import java.util.Arrays; import java.util.Objects; import java.util.stream.Collectors; +import com.kingsrook.qqq.backend.core.utils.lambdas.UnsafeSupplier; /******************************************************************************* @@ -81,7 +82,7 @@ public class LogPair String subLogPairsString = Arrays.stream(subLogPairs).map(LogPair::toString).collect(Collectors.joining(",")); valueString = '{' + subLogPairsString + '}'; } - else if(value instanceof LogUtils.UnsafeSupplier us) + else if(value instanceof UnsafeSupplier us) { try { @@ -103,4 +104,67 @@ public class LogPair } return valueString; } + + + + /******************************************************************************* + ** Getter for key + *******************************************************************************/ + public String getKey() + { + return (this.key); + } + + + + /******************************************************************************* + ** Setter for key + *******************************************************************************/ + public void setKey(String key) + { + this.key = key; + } + + + + /******************************************************************************* + ** Fluent setter for key + *******************************************************************************/ + public LogPair withKey(String key) + { + this.key = key; + return (this); + } + + + + /******************************************************************************* + ** Getter for value + *******************************************************************************/ + public Object getValue() + { + return (this.value); + } + + + + /******************************************************************************* + ** Setter for value + *******************************************************************************/ + public void setValue(Object value) + { + this.value = value; + } + + + + /******************************************************************************* + ** Fluent setter for value + *******************************************************************************/ + public LogPair withValue(Object value) + { + this.value = value; + return (this); + } + } diff --git a/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/utils/lambdas/UnsafeConsumer.java b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/utils/lambdas/UnsafeConsumer.java new file mode 100644 index 00000000..baf57bb9 --- /dev/null +++ b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/utils/lambdas/UnsafeConsumer.java @@ -0,0 +1,35 @@ +/* + * QQQ - Low-code Application Framework for Engineers. + * Copyright (C) 2021-2023. Kingsrook, LLC + * 651 N Broad St Ste 205 # 6917 | Middletown DE 19709 | United States + * contact@kingsrook.com + * https://github.com/Kingsrook/ + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package com.kingsrook.qqq.backend.core.utils.lambdas; + + +/******************************************************************************* + ** + *******************************************************************************/ +@FunctionalInterface +public interface UnsafeConsumer +{ + /******************************************************************************* + ** + *******************************************************************************/ + void run(T t) throws E; +} diff --git a/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/utils/lambdas/UnsafeFunction.java b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/utils/lambdas/UnsafeFunction.java new file mode 100644 index 00000000..9594c089 --- /dev/null +++ b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/utils/lambdas/UnsafeFunction.java @@ -0,0 +1,35 @@ +/* + * QQQ - Low-code Application Framework for Engineers. + * Copyright (C) 2021-2023. Kingsrook, LLC + * 651 N Broad St Ste 205 # 6917 | Middletown DE 19709 | United States + * contact@kingsrook.com + * https://github.com/Kingsrook/ + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package com.kingsrook.qqq.backend.core.utils.lambdas; + + +/******************************************************************************* + ** + *******************************************************************************/ +@FunctionalInterface +public interface UnsafeFunction +{ + /******************************************************************************* + ** + *******************************************************************************/ + R apply(T t) throws E; +} diff --git a/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/utils/lambdas/UnsafeSupplier.java b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/utils/lambdas/UnsafeSupplier.java new file mode 100644 index 00000000..3a674146 --- /dev/null +++ b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/utils/lambdas/UnsafeSupplier.java @@ -0,0 +1,35 @@ +/* + * QQQ - Low-code Application Framework for Engineers. + * Copyright (C) 2021-2023. Kingsrook, LLC + * 651 N Broad St Ste 205 # 6917 | Middletown DE 19709 | United States + * contact@kingsrook.com + * https://github.com/Kingsrook/ + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package com.kingsrook.qqq.backend.core.utils.lambdas; + + +/******************************************************************************* + ** + *******************************************************************************/ +@FunctionalInterface +public interface UnsafeSupplier +{ + /******************************************************************************* + ** + *******************************************************************************/ + T get() throws E; +}