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; + +}