From cc2d625d5d28f4ef054443b8ead867a1624dbaf4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A6=82=E6=A2=A6=E6=8A=80=E6=9C=AF?= <596392912@qq.com> Date: Sat, 27 Jul 2024 11:29:42 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20=E6=B7=BB=E5=8A=A0=20Unchecked?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/tool/function/CheckedCallable.java | 39 ++++ .../core/tool/function/CheckedComparator.java | 39 ++++ .../core/tool/function/CheckedConsumer.java | 39 ++++ .../core/tool/function/CheckedFunction.java | 41 +++++ .../core/tool/function/CheckedPredicate.java | 39 ++++ .../core/tool/function/CheckedRunnable.java | 36 ++++ .../core/tool/function/CheckedSupplier.java | 40 +++++ .../core/tool/utils/Unchecked.java | 167 ++++++++++++++++++ 8 files changed, 440 insertions(+) create mode 100644 blade-core-tool/src/main/java/org/springblade/core/tool/function/CheckedCallable.java create mode 100644 blade-core-tool/src/main/java/org/springblade/core/tool/function/CheckedComparator.java create mode 100644 blade-core-tool/src/main/java/org/springblade/core/tool/function/CheckedConsumer.java create mode 100644 blade-core-tool/src/main/java/org/springblade/core/tool/function/CheckedFunction.java create mode 100644 blade-core-tool/src/main/java/org/springblade/core/tool/function/CheckedPredicate.java create mode 100644 blade-core-tool/src/main/java/org/springblade/core/tool/function/CheckedRunnable.java create mode 100644 blade-core-tool/src/main/java/org/springblade/core/tool/function/CheckedSupplier.java create mode 100644 blade-core-tool/src/main/java/org/springblade/core/tool/utils/Unchecked.java diff --git a/blade-core-tool/src/main/java/org/springblade/core/tool/function/CheckedCallable.java b/blade-core-tool/src/main/java/org/springblade/core/tool/function/CheckedCallable.java new file mode 100644 index 0000000..12828c6 --- /dev/null +++ b/blade-core-tool/src/main/java/org/springblade/core/tool/function/CheckedCallable.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2019-2029, Dreamlu 卢春梦 (596392912@qq.com & www.dreamlu.net). + *
+ * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *
+ * http://www.gnu.org/licenses/lgpl.html + *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springblade.core.tool.function;
+
+import org.springframework.lang.Nullable;
+
+import java.io.Serializable;
+
+/**
+ * 受检的 Callable
+ *
+ * @author L.cm
+ */
+@FunctionalInterface
+public interface CheckedCallable
+ * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.gnu.org/licenses/lgpl.html
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springblade.core.tool.function;
+
+import java.io.Serializable;
+
+/**
+ * 受检的 Comparator
+ *
+ * @author L.cm
+ */
+@FunctionalInterface
+public interface CheckedComparator
+ * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.gnu.org/licenses/lgpl.html
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springblade.core.tool.function;
+
+import org.springframework.lang.Nullable;
+
+import java.io.Serializable;
+
+/**
+ * 受检的 Consumer
+ *
+ * @author L.cm
+ */
+@FunctionalInterface
+public interface CheckedConsumer
+ * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.gnu.org/licenses/lgpl.html
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springblade.core.tool.function;
+
+import org.springframework.lang.Nullable;
+
+import java.io.Serializable;
+
+/**
+ * 受检的 function
+ *
+ * @author L.cm
+ */
+@FunctionalInterface
+public interface CheckedFunction
+ * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.gnu.org/licenses/lgpl.html
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springblade.core.tool.function;
+
+import java.io.Serializable;
+
+/**
+ * 受检的 Predicate
+ *
+ * @author L.cm
+ */
+@FunctionalInterface
+public interface CheckedPredicate
+ * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.gnu.org/licenses/lgpl.html
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springblade.core.tool.function;
+
+import java.io.Serializable;
+
+/**
+ * 受检的 runnable
+ *
+ * @author L.cm
+ */
+@FunctionalInterface
+public interface CheckedRunnable extends Serializable {
+
+ /**
+ * Run this runnable.
+ *
+ * @throws Throwable CheckedException
+ */
+ void run() throws Throwable;
+
+}
diff --git a/blade-core-tool/src/main/java/org/springblade/core/tool/function/CheckedSupplier.java b/blade-core-tool/src/main/java/org/springblade/core/tool/function/CheckedSupplier.java
new file mode 100644
index 0000000..dbdae1e
--- /dev/null
+++ b/blade-core-tool/src/main/java/org/springblade/core/tool/function/CheckedSupplier.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2019-2029, Dreamlu 卢春梦 (596392912@qq.com & www.dreamlu.net).
+ *
+ * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.gnu.org/licenses/lgpl.html
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springblade.core.tool.function;
+
+import org.springframework.lang.Nullable;
+
+import java.io.Serializable;
+
+/**
+ * 受检的 Supplier
+ *
+ * @author L.cm
+ */
+@FunctionalInterface
+public interface CheckedSupplier
+ * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.gnu.org/licenses/lgpl.html
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springblade.core.tool.utils;
+
+
+import org.springblade.core.tool.function.*;
+
+import java.util.Comparator;
+import java.util.Objects;
+import java.util.concurrent.Callable;
+import java.util.function.Consumer;
+import java.util.function.Function;
+import java.util.function.Predicate;
+import java.util.function.Supplier;
+
+/**
+ * Lambda 受检异常处理
+ *
+ *
+ * https://segmentfault.com/a/1190000007832130
+ * https://github.com/jOOQ/jOOL
+ *