From 66d0e811f71bdf997c6ee79f0345e5566fcf87a4 Mon Sep 17 00:00:00 2001 From: ZhouXY108 Date: Mon, 21 Oct 2024 01:54:34 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=85=81=E8=AE=B8=E6=8A=9B?= =?UTF-8?q?=E5=87=BA=E5=BC=82=E5=B8=B8=E7=9A=84=20Executable=E3=80=81Throw?= =?UTF-8?q?ingConsumer=E3=80=81ThrowingSupplier=20=E5=92=8C=20ThrowingPred?= =?UTF-8?q?icate?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plusone/commons/function/Executable.java | 24 +++++++++++++++ .../commons/function/ThrowingConsumer.java | 29 +++++++++++++++++++ .../commons/function/ThrowingPredicate.java | 29 +++++++++++++++++++ .../commons/function/ThrowingSupplier.java | 29 +++++++++++++++++++ 4 files changed, 111 insertions(+) create mode 100644 src/main/java/xyz/zhouxy/plusone/commons/function/Executable.java create mode 100644 src/main/java/xyz/zhouxy/plusone/commons/function/ThrowingConsumer.java create mode 100644 src/main/java/xyz/zhouxy/plusone/commons/function/ThrowingPredicate.java create mode 100644 src/main/java/xyz/zhouxy/plusone/commons/function/ThrowingSupplier.java diff --git a/src/main/java/xyz/zhouxy/plusone/commons/function/Executable.java b/src/main/java/xyz/zhouxy/plusone/commons/function/Executable.java new file mode 100644 index 0000000..a8677ec --- /dev/null +++ b/src/main/java/xyz/zhouxy/plusone/commons/function/Executable.java @@ -0,0 +1,24 @@ +/* + * Copyright 2024 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * 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 xyz.zhouxy.plusone.commons.function; + +@FunctionalInterface +public interface Executable { + + void execute() throws E; + +} diff --git a/src/main/java/xyz/zhouxy/plusone/commons/function/ThrowingConsumer.java b/src/main/java/xyz/zhouxy/plusone/commons/function/ThrowingConsumer.java new file mode 100644 index 0000000..51d3984 --- /dev/null +++ b/src/main/java/xyz/zhouxy/plusone/commons/function/ThrowingConsumer.java @@ -0,0 +1,29 @@ +/* + * Copyright 2024 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * 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 xyz.zhouxy.plusone.commons.function; + +@FunctionalInterface +public interface ThrowingConsumer { + + /** + * Consume the supplied argument, potentially throwing an exception. + * + * @param t the argument to consume + */ + void accept(T t) throws E; + +} diff --git a/src/main/java/xyz/zhouxy/plusone/commons/function/ThrowingPredicate.java b/src/main/java/xyz/zhouxy/plusone/commons/function/ThrowingPredicate.java new file mode 100644 index 0000000..1d1f9d7 --- /dev/null +++ b/src/main/java/xyz/zhouxy/plusone/commons/function/ThrowingPredicate.java @@ -0,0 +1,29 @@ +/* + * Copyright 2024 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * 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 xyz.zhouxy.plusone.commons.function; + +public interface ThrowingPredicate { + + /** + * Evaluates this predicate on the given argument. + * + * @param t the input argument + * @return {@code true} if the input argument matches the predicate, + * otherwise {@code false} + */ + boolean test(T t) throws E; +} diff --git a/src/main/java/xyz/zhouxy/plusone/commons/function/ThrowingSupplier.java b/src/main/java/xyz/zhouxy/plusone/commons/function/ThrowingSupplier.java new file mode 100644 index 0000000..8fb335c --- /dev/null +++ b/src/main/java/xyz/zhouxy/plusone/commons/function/ThrowingSupplier.java @@ -0,0 +1,29 @@ +/* + * Copyright 2024 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * 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 xyz.zhouxy.plusone.commons.function; + +@FunctionalInterface +public interface ThrowingSupplier { + + /** + * Get a result, potentially throwing an exception. + * + * @return a result + */ + T get() throws E; + +}