unary.ObjToShort Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of functions-unary-all Show documentation
Show all versions of functions-unary-all Show documentation
Provides functional interfaces for all two-argument functions
package net.mintern.functions.unary;
/**
* An operation of type {@code (T) -> short}.
*
* @param the type of the argument
*/
@FunctionalInterface
public interface ObjToShort extends
net.mintern.functions.unary.checked.ObjToShortE {
/**
* Returns a wrapped version of {@code f} that uses {@code toRuntime} to convert any checked
* {@code Exception} to a {@code RuntimeException}.
*
* @param the type of argument 1
* @param the {@code Exception} type that the operation may throw
* @param toRuntime if a checked exception is thrown from
* {@link net.mintern.functions.unary.checked.ObjToShortE#call}, then this function
* is called in in order to convert it to a {@code RuntimeException}
* @param f the operation to wrap
* @return a wrapped version of {@code f} that does not throw checked exceptions
*/
@SuppressWarnings("unchecked")
static ObjToShort unchecked(
java.util.function.Function super E, RuntimeException> toRuntime,
net.mintern.functions.unary.checked.ObjToShortE f) {
return (t) -> {
try {
return f.call(t);
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw toRuntime.apply((E) e);
}
};
}
/**
* Returns a wrapped version of {@code f} that wraps any checked {@code Exception} with a
* {@code RuntimeException}.
*
* @param the type of argument 1
* @param the {@code Exception} type that the operation may throw
* @param f the operation to wrap
* @return a wrapped version of {@code f} that does not throw checked exceptions
*/
static ObjToShort unchecked(
net.mintern.functions.unary.checked.ObjToShortE f) {
return unchecked(RuntimeException::new, f);
}
/**
* Returns a wrapped version of {@code f} that wraps any {@code IOException} with an
* {@link java.io.UncheckedIOException}.
*
* @param the type of argument 1
* @param the {@code Exception} type that the operation may throw
* @param f the operation to wrap
* @return a wrapped version of {@code f} that throws {@code UncheckedIOException} instead of
* {@code IOException}
*/
static ObjToShort uncheckedIO(
net.mintern.functions.unary.checked.ObjToShortE f) {
return unchecked(java.io.UncheckedIOException::new, f);
}
/**
* Binds {@code (t)} to {@code f}, returning a new function
* of type {@code () -> short}.
*
* @param the type of the argument
* @param f the unbound function
* @param t the argument
* @return a new function {@code () -> short} that calls
* {@code f.call(t)} and returns the result.
*/
static net.mintern.functions.nullary.NilToShort
bind(ObjToShort f, T t) {
return () -> f.call(t);
}
/**
* Binds {@code (t)} to {@code this}, returning a new function
* of type {@code () -> short}.
*
* @param t the argument
* @return a new function {@code () -> short} that calls
* {@code this.call(t)} and returns the result.
*/
@Override
default net.mintern.functions.nullary.NilToShort bind(T t) {
return ObjToShort.bind(this, t);
}
}