buckelieg.jdbc.fn.TryRunnable Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jdbc-fn Show documentation
Show all versions of jdbc-fn Show documentation
Functional style programming with plain JDBC
The newest version!
/*
* Copyright 2024- Anatoly Kutyakov
*
* 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
*
* http://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 buckelieg.jdbc.fn;
import javax.annotation.Nonnull;
import static java.util.Objects.requireNonNull;
/**
* No-argument function which return no result that might throw an exception
*
This is a functional interface whose functional method is {@link #run()}
*
* @param exception type
*/
@FunctionalInterface
public interface TryRunnable {
/**
* A NO OPeration constant
*/
TryRunnable extends Throwable> NOOP = () -> {};
/**
* A type-checked NO OPeration
*
* @param the type of the exception thrown
* @return a type-checked {@linkplain #NOOP} constant
*/
@Nonnull
@SuppressWarnings("unchecked")
static TryRunnable NOOP() {
return (TryRunnable) NOOP;
}
/**
* Performs an action with possible exceptional result
*
* @throws E an exception
*/
void run() throws E;
/**
* Returns reference of lambda expression
*
* @param tryRunnable an action function
* @return {@link TryRunnable} reference
* @throws NullPointerException if tryAction is null
*/
static TryRunnable of(TryRunnable tryRunnable) {
return requireNonNull(tryRunnable);
}
}