Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
package com.github.markozajc.ef;
import static com.github.markozajc.ef.Utilities.asUnchecked;
import java.util.concurrent.Callable;
import java.util.function.*;
import javax.annotation.Nonnull;
import com.github.markozajc.ef.biconsumer.*;
import com.github.markozajc.ef.biconsumer.except.*;
import com.github.markozajc.ef.bifunction.*;
import com.github.markozajc.ef.bifunction.except.*;
import com.github.markozajc.ef.bipredicate.*;
import com.github.markozajc.ef.bipredicate.except.*;
import com.github.markozajc.ef.consumer.*;
import com.github.markozajc.ef.consumer.execpt.*;
import com.github.markozajc.ef.function.*;
import com.github.markozajc.ef.function.except.*;
import com.github.markozajc.ef.predicate.*;
import com.github.markozajc.ef.predicate.except.*;
import com.github.markozajc.ef.runnable.except.ERunnable;
import com.github.markozajc.ef.supplier.*;
import com.github.markozajc.ef.supplier.except.*;
import com.github.markozajc.ef.triconsumer.*;
import com.github.markozajc.ef.trifunction.*;
import com.github.markozajc.ef.tripredicate.*;
/**
* A class containing various helper utilities for exceptionable (E*) functions and
* {@link Callable} ({@link ESupplier}).
*
* @author Marko Zajc
*/
public class EHandle {
/*
* ================== Consumers ==================
*/
/**
* Handles a generic exception type that may occur in the handled consumer with a
* provided handler.
*
* @param
* The handled function's exception type
* @param handled
* The function that may throw an exception
* @param handler
* The function handling exceptions
*
* @return An exception-proofed consumer
*/
@Nonnull
public static Consumer handle(@Nonnull EConsumer handled,
@Nonnull BiConsumer handler) {
return t -> {
try {
handled.acceptChecked(t);
} catch (Throwable e) { // NOSONAR can't catch generic exceptions
handler.accept(e, t);
}
};
}
/**
* Handles a generic exception type that may occur in the handled consumer by
* throwing a different exception.
*
* @param
* The handled function's exception type
* @param
* The exception type to throw
* @param handled
* The function that may throw an exception
* @param handler
* The function handling exceptions
*
* @return An exception-proofed consumer
*
* @throws X
* The exception returned by the handler
*/
@Nonnull
@SuppressWarnings({ "null", "unused" })
public static Consumer handleThrowing(@Nonnull EConsumer handled,
@Nonnull Function handler) throws X {
return t -> {
try {
handled.acceptChecked(t);
} catch (Throwable e) { // NOSONAR can't catch generic exceptions
throw asUnchecked(handler.apply(e));
}
};
}
/**
* Handles a generic exception type that may occur in the handled consumer by
* throwing it explicitly.
*
* @param
* The handled function's exception type
* @param handled
* The function that may throw an exception
*
* @return An exception-proofed consumer
*
* @throws E
* The checked exception
*/
@Nonnull
@SuppressWarnings("unused")
public static Consumer handleThrowing(@Nonnull EConsumer handled) throws E {
return t -> {
try {
handled.acceptChecked(t);
} catch (Throwable e) { // NOSONAR can't catch generic exceptions
throw asUnchecked(e);
}
};
}
/**
* Handles a generic exception type that may occur in the handled consumer by
* throwing a different exception.
*
* @param
* The handled function's exception type
* @param handled
* The function that may throw an exception
* @param handler
* The function handling exceptions
*
* @return An exception-proofed consumer
*/
@Nonnull
public static BooleanConsumer handle(@Nonnull EBooleanConsumer handled,
@Nonnull ObjBooleanConsumer handler) {
return p -> {
try {
handled.acceptChecked(p);
} catch (Throwable e) { // NOSONAR can't catch generic exceptions
handler.accept(e, p);
}
};
}
/**
* Handles a generic exception type that may occur in the handled consumer by
* throwing a different exception.
*
* @param
* The handled function's exception type
* @param
* The exception type to throw
* @param handled
* The function that may throw an exception
* @param handler
* The function handling exceptions
*
* @return An exception-proofed consumer
*
* @throws X
* The exception returned by the handler
*/
@Nonnull
@SuppressWarnings({ "null", "unused" })
public static BooleanConsumer handleThrowing(@Nonnull EBooleanConsumer handled,
@Nonnull Function handler) throws X {
return p -> {
try {
handled.acceptChecked(p);
} catch (Throwable e) { // NOSONAR can't catch generic exceptions
throw asUnchecked(handler.apply(e));
}
};
}
/**
* Handles a generic exception type that may occur in the handled consumer by
* throwing it explicitly.
*
* @param
* The handled function's exception type
* @param handled
* The function that may throw an exception
*
* @return An exception-proofed consumer
*
* @throws E
* The checked exception
*/
@Nonnull
@SuppressWarnings("unused")
public static BooleanConsumer handleThrowing(@Nonnull EBooleanConsumer handled) throws E {
return p -> {
try {
handled.acceptChecked(p);
} catch (Throwable e) { // NOSONAR can't catch generic exceptions
throw asUnchecked(e);
}
};
}
/**
* Handles a generic exception type that may occur in the handled consumer with a
* provided handler.
*
* @param
* The handled function's exception type
* @param handled
* The function that may throw an exception
* @param handler
* The function handling exceptions
*
* @return An exception-proofed consumer
*/
@Nonnull
public static ByteConsumer handle(@Nonnull EByteConsumer handled,
@Nonnull ObjByteConsumer handler) {
return p -> {
try {
handled.acceptChecked(p);
} catch (Throwable e) { // NOSONAR can't catch generic exceptions
handler.accept(e, p);
}
};
}
/**
* Handles a generic exception type that may occur in the handled consumer by
* throwing a different exception.
*
* @param
* The handled function's exception type
* @param
* The exception type to throw
* @param handled
* The function that may throw an exception
* @param handler
* The function handling exceptions
*
* @return An exception-proofed consumer
*
* @throws X
* The exception returned by the handler
*/
@Nonnull
@SuppressWarnings({ "null", "unused" })
public static ByteConsumer handleThrowing(@Nonnull EByteConsumer handled,
@Nonnull Function handler) throws X {
return p -> {
try {
handled.acceptChecked(p);
} catch (Throwable e) { // NOSONAR can't catch generic exceptions
throw asUnchecked(handler.apply(e));
}
};
}
/**
* Handles a generic exception type that may occur in the handled consumer by
* throwing it explicitly.
*
* @param
* The handled function's exception type
* @param handled
* The function that may throw an exception
*
* @return An exception-proofed consumer
*
* @throws E
* The checked exception
*/
@Nonnull
@SuppressWarnings("unused")
public static ByteConsumer handleThrowing(@Nonnull EByteConsumer handled) throws E {
return p -> {
try {
handled.acceptChecked(p);
} catch (Throwable e) { // NOSONAR can't catch generic exceptions
throw asUnchecked(e);
}
};
}
/**
* Handles a generic exception type that may occur in the handled consumer with a
* provided handler.
*
* @param
* The handled function's exception type
* @param handled
* The function that may throw an exception
* @param handler
* The function handling exceptions
*
* @return An exception-proofed consumer
*/
@Nonnull
public static IntConsumer handle(@Nonnull EIntConsumer handled,
@Nonnull ObjIntConsumer handler) {
return p -> {
try {
handled.acceptChecked(p);
} catch (Throwable e) { // NOSONAR can't catch generic exceptions
handler.accept(e, p);
}
};
}
/**
* Handles a generic exception type that may occur in the handled consumer by
* throwing a different exception.
*
* @param
* The handled function's exception type
* @param
* The exception type to throw
* @param handled
* The function that may throw an exception
* @param handler
* The function handling exceptions
*
* @return An exception-proofed consumer
*
* @throws X
* The exception returned by the handler
*/
@Nonnull
@SuppressWarnings({ "null", "unused" })
public static IntConsumer handleThrowing(@Nonnull EIntConsumer handled,
@Nonnull Function handler) throws X {
return p -> {
try {
handled.acceptChecked(p);
} catch (Throwable e) { // NOSONAR can't catch generic exceptions
throw asUnchecked(handler.apply(e));
}
};
}
/**
* Handles a generic exception type that may occur in the handled consumer by
* throwing it explicitly.
*
* @param
* The handled function's exception type
* @param handled
* The function that may throw an exception
*
* @return An exception-proofed consumer
*
* @throws E
* The checked exception
*/
@Nonnull
@SuppressWarnings("unused")
public static IntConsumer handleThrowing(@Nonnull EIntConsumer handled) throws E {
return p -> {
try {
handled.acceptChecked(p);
} catch (Throwable e) { // NOSONAR can't catch generic exceptions
throw asUnchecked(e);
}
};
}
/**
* Handles a generic exception type that may occur in the handled consumer with a
* provided handler.
*
* @param
* The handled function's exception type
* @param handled
* The function that may throw an exception
* @param handler
* The function handling exceptions
*
* @return An exception-proofed consumer
*/
@Nonnull
public static LongConsumer handle(@Nonnull ELongConsumer handled,
@Nonnull ObjLongConsumer handler) {
return p -> {
try {
handled.acceptChecked(p);
} catch (Throwable e) { // NOSONAR can't catch generic exceptions
handler.accept(e, p);
}
};
}
/**
* Handles a generic exception type that may occur in the handled consumer by
* throwing a different exception.
*
* @param
* The handled function's exception type
* @param
* The exception type to throw
* @param handled
* The function that may throw an exception
* @param handler
* The function handling exceptions
*
* @return An exception-proofed consumer
*
* @throws X
* The exception returned by the handler
*/
@Nonnull
@SuppressWarnings({ "null", "unused" })
public static LongConsumer handleThrowing(@Nonnull ELongConsumer handled,
@Nonnull Function handler) throws X {
return p -> {
try {
handled.acceptChecked(p);
} catch (Throwable e) { // NOSONAR can't catch generic exceptions
throw asUnchecked(handler.apply(e));
}
};
}
/**
* Handles a generic exception type that may occur in the handled consumer by
* throwing it explicitly.
*
* @param
* The handled function's exception type
* @param handled
* The function that may throw an exception
*
* @return An exception-proofed consumer
*
* @throws E
* The checked exception
*/
@Nonnull
@SuppressWarnings("unused")
public static LongConsumer handleThrowing(@Nonnull ELongConsumer handled) throws E {
return p -> {
try {
handled.acceptChecked(p);
} catch (Throwable e) { // NOSONAR can't catch generic exceptions
throw asUnchecked(e);
}
};
}
/**
* Handles a generic exception type that may occur in the handled consumer with a
* provided handler.
*
* @param
* The handled function's exception type
* @param handled
* The function that may throw an exception
* @param handler
* The function handling exceptions
*
* @return An exception-proofed consumer
*/
@Nonnull
public static ShortConsumer handle(@Nonnull EShortConsumer handled,
@Nonnull ObjShortConsumer handler) {
return p -> {
try {
handled.acceptChecked(p);
} catch (Throwable e) { // NOSONAR can't catch generic exceptions
handler.accept(e, p);
}
};
}
/**
* Handles a generic exception type that may occur in the handled consumer by
* throwing a different exception.
*
* @param
* The handled function's exception type
* @param
* The exception type to throw
* @param handled
* The function that may throw an exception
* @param handler
* The function handling exceptions
*
* @return An exception-proofed consumer
*
* @throws X
* The exception returned by the handler
*/
@Nonnull
@SuppressWarnings({ "null", "unused" })
public static ShortConsumer handleThrowing(@Nonnull EShortConsumer handled,
@Nonnull Function handler) throws X {
return p -> {
try {
handled.acceptChecked(p);
} catch (Throwable e) { // NOSONAR can't catch generic exceptions
throw asUnchecked(handler.apply(e));
}
};
}
/**
* Handles a generic exception type that may occur in the handled consumer by
* throwing it explicitly.
*
* @param
* The handled function's exception type
* @param handled
* The function that may throw an exception
*
* @return An exception-proofed consumer
*
* @throws E
* The checked exception
*/
@Nonnull
@SuppressWarnings("unused")
public static ShortConsumer handleThrowing(@Nonnull EShortConsumer handled) throws E {
return p -> {
try {
handled.acceptChecked(p);
} catch (Throwable e) { // NOSONAR can't catch generic exceptions
throw asUnchecked(e);
}
};
}
/*
* ================== BiConsumers ==================
*/
/**
* Handles a generic exception type that may occur in the handled consumer with a
* provided handler.
*
* @param
* The handled function's exception type
* @param handled
* The function that may throw an exception
* @param handler
* The function handling exceptions
*
* @return An exception-proofed consumer
*/
@Nonnull
public static BiConsumer handle(@Nonnull EBiConsumer handled,
@Nonnull TriConsumer handler) {
return (t, u) -> {
try {
handled.acceptChecked(t, u);
} catch (Throwable e) { // NOSONAR can't catch generic exceptions
handler.accept(e, t, u);
}
};
}
/**
* Handles a generic exception type that may occur in the handled consumer by
* throwing a different exception.
*
* @param
* The handled function's exception type
* @param
* The exception type to throw
* @param handled
* The function that may throw an exception
* @param handler
* The function handling exceptions
*
* @return An exception-proofed consumer
*
* @throws X
* The exception returned by the handler
*/
@Nonnull
@SuppressWarnings({ "null", "unused" })
public static BiConsumer handleThrowing(@Nonnull EBiConsumer handled,
@Nonnull Function handler) throws X {
return (t, u) -> {
try {
handled.acceptChecked(t, u);
} catch (Throwable e) { // NOSONAR can't catch generic exceptions
throw asUnchecked(handler.apply(e));
}
};
}
/**
* Handles a generic exception type that may occur in the handled consumer by
* throwing it explicitly.
*
* @param
* The handled function's exception type
* @param handled
* The function that may throw an exception
*
* @return An exception-proofed consumer
*
* @throws E
* The checked exception
*/
@Nonnull
@SuppressWarnings("unused")
public static BiConsumer handleThrowing(@Nonnull EBiConsumer handled) throws E {
return (t, u) -> {
try {
handled.acceptChecked(t, u);
} catch (Throwable e) { // NOSONAR can't catch generic exceptions
throw asUnchecked(e);
}
};
}
/**
* Handles a generic exception type that may occur in the handled consumer with a
* provided handler.
*
* @param
* The handled function's exception type
* @param handled
* The function that may throw an exception
* @param handler
* The function handling exceptions
*
* @return An exception-proofed consumer
*/
@Nonnull
public static ObjBooleanConsumer handle(@Nonnull EObjBooleanConsumer handled,
@Nonnull ObjObjBooleanConsumer handler) {
return (t, p) -> {
try {
handled.acceptChecked(t, p);
} catch (Throwable e) { // NOSONAR can't catch generic exceptions
handler.accept(e, t, p);
}
};
}
/**
* Handles a generic exception type that may occur in the handled consumer by
* throwing a different exception.
*
* @param
* The handled function's exception type
* @param
* The exception type to throw
* @param handled
* The function that may throw an exception
* @param handler
* The function handling exceptions
*
* @return An exception-proofed consumer
*
* @throws X
* The exception returned by the handler
*/
@Nonnull
@SuppressWarnings({ "null", "unused" })
public static ObjBooleanConsumer handleThrowing(@Nonnull EObjBooleanConsumer handled,
@Nonnull Function handler) throws X {
return (t, p) -> {
try {
handled.acceptChecked(t, p);
} catch (Throwable e) { // NOSONAR can't catch generic exceptions
throw asUnchecked(handler.apply(e));
}
};
}
/**
* Handles a generic exception type that may occur in the handled consumer by
* throwing it explicitly.
*
* @param
* The handled function's exception type
* @param handled
* The function that may throw an exception
*
* @return An exception-proofed consumer
*
* @throws E
* The checked exception
*/
@Nonnull
@SuppressWarnings("unused")
public static ObjBooleanConsumer handleThrowing(@Nonnull EObjBooleanConsumer handled) throws E {
return (t, p) -> {
try {
handled.acceptChecked(t, p);
} catch (Throwable e) { // NOSONAR can't catch generic exceptions
throw asUnchecked(e);
}
};
}
/**
* Handles a generic exception type that may occur in the handled consumer with a
* provided handler.
*
* @param
* The handled function's exception type
* @param handled
* The function that may throw an exception
* @param handler
* The function handling exceptions
*
* @return An exception-proofed consumer
*/
@Nonnull
public static ObjByteConsumer handle(@Nonnull EObjByteConsumer handled,
@Nonnull ObjObjByteConsumer handler) {
return (t, p) -> {
try {
handled.acceptChecked(t, p);
} catch (Throwable e) { // NOSONAR can't catch generic exceptions
handler.accept(e, t, p);
}
};
}
/**
* Handles a generic exception type that may occur in the handled consumer by
* throwing a different exception.
*
* @param
* The handled function's exception type
* @param
* The exception type to throw
* @param handled
* The function that may throw an exception
* @param handler
* The function handling exceptions
*
* @return An exception-proofed consumer
*
* @throws X
* The exception returned by the handler
*/
@Nonnull
@SuppressWarnings({ "null", "unused" })
public static ObjByteConsumer handleThrowing(@Nonnull EObjByteConsumer handled,
@Nonnull Function handler) throws X {
return (t, p) -> {
try {
handled.acceptChecked(t, p);
} catch (Throwable e) { // NOSONAR can't catch generic exceptions
throw asUnchecked(handler.apply(e));
}
};
}
/**
* Handles a generic exception type that may occur in the handled consumer by
* throwing it explicitly.
*
* @param
* The handled function's exception type
* @param handled
* The function that may throw an exception
*
* @return An exception-proofed consumer
*
* @throws E
* The checked exception
*/
@Nonnull
@SuppressWarnings("unused")
public static ObjByteConsumer handleThrowing(@Nonnull EObjByteConsumer handled) throws E {
return (t, p) -> {
try {
handled.acceptChecked(t, p);
} catch (Throwable e) { // NOSONAR can't catch generic exceptions
throw asUnchecked(e);
}
};
}
/**
* Handles a generic exception type that may occur in the handled consumer with a
* provided handler.
*
* @param
* The handled function's exception type
* @param handled
* The function that may throw an exception
* @param handler
* The function handling exceptions
*
* @return An exception-proofed consumer
*/
@Nonnull
public static ObjIntConsumer handle(@Nonnull EObjIntConsumer handled,
@Nonnull ObjObjIntConsumer handler) {
return (t, p) -> {
try {
handled.acceptChecked(t, p);
} catch (Throwable e) { // NOSONAR can't catch generic exceptions
handler.accept(e, t, p);
}
};
}
/**
* Handles a generic exception type that may occur in the handled consumer by
* throwing a different exception.
*
* @param
* The handled function's exception type
* @param
* The exception type to throw
* @param handled
* The function that may throw an exception
* @param handler
* The function handling exceptions
*
* @return An exception-proofed consumer
*
* @throws X
* The exception returned by the handler
*/
@Nonnull
@SuppressWarnings({ "null", "unused" })
public static ObjIntConsumer handleThrowing(@Nonnull EObjIntConsumer handled,
@Nonnull Function handler) throws X {
return (t, p) -> {
try {
handled.acceptChecked(t, p);
} catch (Throwable e) { // NOSONAR can't catch generic exceptions
throw asUnchecked(handler.apply(e));
}
};
}
/**
* Handles a generic exception type that may occur in the handled consumer by
* throwing it explicitly.
*
* @param
* The handled function's exception type
* @param handled
* The function that may throw an exception
*
* @return An exception-proofed consumer
*
* @throws E
* The checked exception
*/
@Nonnull
@SuppressWarnings("unused")
public static ObjIntConsumer handleThrowing(@Nonnull EObjIntConsumer handled) throws E {
return (t, p) -> {
try {
handled.acceptChecked(t, p);
} catch (Throwable e) { // NOSONAR can't catch generic exceptions
throw asUnchecked(e);
}
};
}
/**
* Handles a generic exception type that may occur in the handled consumer with a
* provided handler.
*
* @param
* The handled function's exception type
* @param handled
* The function that may throw an exception
* @param handler
* The function handling exceptions
*
* @return An exception-proofed consumer
*/
@Nonnull
public static ObjLongConsumer handle(@Nonnull EObjLongConsumer handled,
@Nonnull ObjObjLongConsumer handler) {
return (t, p) -> {
try {
handled.acceptChecked(t, p);
} catch (Throwable e) { // NOSONAR can't catch generic exceptions
handler.accept(e, t, p);
}
};
}
/**
* Handles a generic exception type that may occur in the handled consumer by
* throwing a different exception.
*
* @param
* The handled function's exception type
* @param
* The exception type to throw
* @param handled
* The function that may throw an exception
* @param handler
* The function handling exceptions
*
* @return An exception-proofed consumer
*
* @throws X
* The exception returned by the handler
*/
@Nonnull
@SuppressWarnings({ "null", "unused" })
public static ObjLongConsumer handleThrowing(@Nonnull EObjLongConsumer handled,
@Nonnull Function handler) throws X {
return (t, p) -> {
try {
handled.acceptChecked(t, p);
} catch (Throwable e) { // NOSONAR can't catch generic exceptions
throw asUnchecked(handler.apply(e));
}
};
}
/**
* Handles a generic exception type that may occur in the handled consumer by
* throwing it explicitly.
*
* @param
* The handled function's exception type
* @param handled
* The function that may throw an exception
*
* @return An exception-proofed consumer
*
* @throws E
* The checked exception
*/
@Nonnull
@SuppressWarnings("unused")
public static ObjLongConsumer handleThrowing(@Nonnull EObjLongConsumer handled) throws E {
return (t, p) -> {
try {
handled.acceptChecked(t, p);
} catch (Throwable e) { // NOSONAR can't catch generic exceptions
throw asUnchecked(e);
}
};
}
/**
* Handles a generic exception type that may occur in the handled consumer with a
* provided handler.
*
* @param
* The handled function's exception type
* @param handled
* The function that may throw an exception
* @param handler
* The function handling exceptions
*
* @return An exception-proofed consumer
*/
@Nonnull
public static ObjShortConsumer handle(@Nonnull EObjShortConsumer handled,
@Nonnull ObjObjShortConsumer handler) {
return (t, p) -> {
try {
handled.acceptChecked(t, p);
} catch (Throwable e) { // NOSONAR can't catch generic exceptions
handler.accept(e, t, p);
}
};
}
/**
* Handles a generic exception type that may occur in the handled consumer by
* throwing a different exception.
*
* @param
* The handled function's exception type
* @param
* The exception type to throw
* @param handled
* The function that may throw an exception
* @param handler
* The function handling exceptions
*
* @return An exception-proofed consumer
*
* @throws X
* The exception returned by the handler
*/
@Nonnull
@SuppressWarnings({ "null", "unused" })
public static ObjShortConsumer handleThrowing(@Nonnull EObjShortConsumer handled,
@Nonnull Function handler) throws X {
return (t, p) -> {
try {
handled.acceptChecked(t, p);
} catch (Throwable e) { // NOSONAR can't catch generic exceptions
throw asUnchecked(handler.apply(e));
}
};
}
/**
* Handles a generic exception type that may occur in the handled consumer by
* throwing it explicitly.
*
* @param
* The handled function's exception type
* @param handled
* The function that may throw an exception
*
* @return An exception-proofed consumer
*
* @throws E
* The checked exception
*/
@Nonnull
@SuppressWarnings("unused")
public static ObjShortConsumer handleThrowing(@Nonnull EObjShortConsumer handled) throws E {
return (t, p) -> {
try {
handled.acceptChecked(t, p);
} catch (Throwable e) { // NOSONAR can't catch generic exceptions
throw asUnchecked(e);
}
};
}
/*
* ================== Functions ==================
*/
/**
* Handles a generic exception type that may occur in the handled function with a
* provided handler.
*
* @param
* The handled function's exception type
* @param handled
* The function that may throw an exception
* @param handler
* The function handling exceptions
*
* @return An exception-proofed function
*/
@Nonnull
public static Function handle(@Nonnull EFunction handled,
@Nonnull BiFunction handler) {
return t -> {
try {
return handled.applyChecked(t);
} catch (Throwable e) { // NOSONAR can't catch generic exceptions
return handler.apply(e, t);
}
};
}
/**
* Handles a generic exception type that may occur in the handled function by
* throwing a different exception.
*
* @param
* The handled function's exception type
* @param
* The exception type to throw
* @param handled
* The function that may throw an exception
* @param handler
* The function handling exceptions
*
* @return An exception-proofed function
*
* @throws X
* The exception returned by the handler
*/
@Nonnull
@SuppressWarnings({ "null", "unused" })
public static Function handleThrowing(@Nonnull EFunction handled,
@Nonnull Function handler) throws X {
return t -> {
try {
return handled.applyChecked(t);
} catch (Throwable e) { // NOSONAR can't catch generic exceptions
throw asUnchecked(handler.apply(e));
}
};
}
/**
* Handles a generic exception type that may occur in the handled function by
* throwing it explicitly.
*
* @param
* The handled function's exception type
* @param handled
* The function that may throw an exception
*
* @return An exception-proofed function
*
* @throws E
* The checked exception
*/
@Nonnull
@SuppressWarnings("unused")
public static Function handleThrowing(@Nonnull EFunction handled) throws E {
return t -> {
try {
return handled.applyChecked(t);
} catch (Throwable e) { // NOSONAR can't catch generic exceptions
throw asUnchecked(e);
}
};
}
/**
* Handles a generic exception type that may occur in the handled function with a
* provided handler.
*
* @param
* The handled function's exception type
* @param handled
* The function that may throw an exception
* @param handler
* The function handling exceptions
*
* @return An exception-proofed function
*/
@Nonnull
public static BooleanFunction handle(@Nonnull EBooleanFunction handled,
@Nonnull ObjBooleanFunction handler) {
return p -> {
try {
return handled.applyChecked(p);
} catch (Throwable e) { // NOSONAR can't catch generic exceptions
return handler.apply(e, p);
}
};
}
/**
* Handles a generic exception type that may occur in the handled function by
* throwing a different exception.
*
* @param
* The handled function's exception type
* @param
* The exception type to throw
* @param handled
* The function that may throw an exception
* @param handler
* The function handling exceptions
*
* @return An exception-proofed function
*
* @throws X
* The exception returned by the handler
*/
@Nonnull
@SuppressWarnings({ "null", "unused" })
public static BooleanFunction handleThrowing(@Nonnull EBooleanFunction handled,
@Nonnull Function handler) throws X {
return p -> {
try {
return handled.applyChecked(p);
} catch (Throwable e) { // NOSONAR can't catch generic exceptions
throw asUnchecked(handler.apply(e));
}
};
}
/**
* Handles a generic exception type that may occur in the handled function by
* throwing it explicitly.
*
* @param
* The handled function's exception type
* @param handled
* The function that may throw an exception
*
* @return An exception-proofed function
*
* @throws E
* The checked exception
*/
@Nonnull
@SuppressWarnings("unused")
public static BooleanFunction handleThrowing(@Nonnull EBooleanFunction handled) throws E {
return p -> {
try {
return handled.applyChecked(p);
} catch (Throwable e) { // NOSONAR can't catch generic exceptions
throw asUnchecked(e);
}
};
}
/**
* Handles a generic exception type that may occur in the handled function with a
* provided handler.
*
* @param
* The handled function's exception type
* @param handled
* The function that may throw an exception
* @param handler
* The function handling exceptions
*
* @return An exception-proofed function
*/
@Nonnull
public static ByteFunction handle(@Nonnull EByteFunction handled,
@Nonnull ObjByteFunction handler) {
return p -> {
try {
return handled.applyChecked(p);
} catch (Throwable e) { // NOSONAR can't catch generic exceptions
return handler.apply(e, p);
}
};
}
/**
* Handles a generic exception type that may occur in the handled function by
* throwing a different exception.
*
* @param
* The handled function's exception type
* @param
* The exception type to throw
* @param handled
* The function that may throw an exception
* @param handler
* The function handling exceptions
*
* @return An exception-proofed function
*
* @throws X
* The exception returned by the handler
*/
@Nonnull
@SuppressWarnings({ "null", "unused" })
public static ByteFunction handleThrowing(@Nonnull EByteFunction handled,
@Nonnull Function handler) throws X {
return p -> {
try {
return handled.applyChecked(p);
} catch (Throwable e) { // NOSONAR can't catch generic exceptions
throw asUnchecked(handler.apply(e));
}
};
}
/**
* Handles a generic exception type that may occur in the handled function by
* throwing it explicitly.
*
* @param
* The handled function's exception type
* @param handled
* The function that may throw an exception
*
* @return An exception-proofed function
*
* @throws E
* The checked exception
*/
@Nonnull
@SuppressWarnings("unused")
public static ByteFunction handleThrowing(@Nonnull EByteFunction handled) throws E {
return p -> {
try {
return handled.applyChecked(p);
} catch (Throwable e) { // NOSONAR can't catch generic exceptions
throw asUnchecked(e);
}
};
}
/**
* Handles a generic exception type that may occur in the handled function with a
* provided handler.
*
* @param
* The handled function's exception type
* @param handled
* The function that may throw an exception
* @param handler
* The function handling exceptions
*
* @return An exception-proofed function
*/
@Nonnull
public static IntFunction handle(@Nonnull EIntFunction handled,
@Nonnull ObjIntFunction handler) {
return p -> {
try {
return handled.applyChecked(p);
} catch (Throwable e) { // NOSONAR can't catch generic exceptions
return handler.apply(e, p);
}
};
}
/**
* Handles a generic exception type that may occur in the handled function by
* throwing a different exception.
*
* @param
* The handled function's exception type
* @param
* The exception type to throw
* @param handled
* The function that may throw an exception
* @param handler
* The function handling exceptions
*
* @return An exception-proofed function
*
* @throws X
* The exception returned by the handler
*/
@Nonnull
@SuppressWarnings({ "null", "unused" })
public static IntFunction handleThrowing(@Nonnull EIntFunction handled,
@Nonnull Function handler) throws X {
return p -> {
try {
return handled.applyChecked(p);
} catch (Throwable e) { // NOSONAR can't catch generic exceptions
throw asUnchecked(handler.apply(e));
}
};
}
/**
* Handles a generic exception type that may occur in the handled function by
* throwing it explicitly.
*
* @param
* The handled function's exception type
* @param handled
* The function that may throw an exception
*
* @return An exception-proofed function
*
* @throws E
* The checked exception
*/
@Nonnull
@SuppressWarnings("unused")
public static IntFunction handleThrowing(@Nonnull EIntFunction handled) throws E {
return p -> {
try {
return handled.applyChecked(p);
} catch (Throwable e) { // NOSONAR can't catch generic exceptions
throw asUnchecked(e);
}
};
}
/**
* Handles a generic exception type that may occur in the handled function with a
* provided handler.
*
* @param
* The handled function's exception type
* @param handled
* The function that may throw an exception
* @param handler
* The function handling exceptions
*
* @return An exception-proofed function
*/
@Nonnull
public static LongFunction handle(@Nonnull ELongFunction handled,
@Nonnull ObjLongFunction handler) {
return p -> {
try {
return handled.applyChecked(p);
} catch (Throwable e) { // NOSONAR can't catch generic exceptions
return handler.apply(e, p);
}
};
}
/**
* Handles a generic exception type that may occur in the handled function by
* throwing a different exception.
*
* @param
* The handled function's exception type
* @param
* The exception type to throw
* @param handled
* The function that may throw an exception
* @param handler
* The function handling exceptions
*
* @return An exception-proofed function
*
* @throws X
* The exception returned by the handler
*/
@Nonnull
@SuppressWarnings({ "null", "unused" })
public static LongFunction handleThrowing(@Nonnull ELongFunction handled,
@Nonnull Function handler) throws X {
return p -> {
try {
return handled.applyChecked(p);
} catch (Throwable e) { // NOSONAR can't catch generic exceptions
throw asUnchecked(handler.apply(e));
}
};
}
/**
* Handles a generic exception type that may occur in the handled function by
* throwing it explicitly.
*
* @param
* The handled function's exception type
* @param handled
* The function that may throw an exception
*
* @return An exception-proofed function
*
* @throws E
* The checked exception
*/
@Nonnull
@SuppressWarnings("unused")
public static LongFunction handleThrowing(@Nonnull ELongFunction handled) throws E {
return p -> {
try {
return handled.applyChecked(p);
} catch (Throwable e) { // NOSONAR can't catch generic exceptions
throw asUnchecked(e);
}
};
}
/**
* Handles a generic exception type that may occur in the handled function with a
* provided handler.
*
* @param
* The handled function's exception type
* @param handled
* The function that may throw an exception
* @param handler
* The function handling exceptions
*
* @return An exception-proofed function
*/
@Nonnull
public static ShortFunction handle(@Nonnull EShortFunction handled,
@Nonnull ObjShortFunction handler) {
return p -> {
try {
return handled.applyChecked(p);
} catch (Throwable e) { // NOSONAR can't catch generic exceptions
return handler.apply(e, p);
}
};
}
/**
* Handles a generic exception type that may occur in the handled function by
* throwing a different exception.
*
* @param
* The handled function's exception type
* @param
* The exception type to throw
* @param handled
* The function that may throw an exception
* @param handler
* The function handling exceptions
*
* @return An exception-proofed function
*
* @throws X
* The exception returned by the handler
*/
@Nonnull
@SuppressWarnings({ "null", "unused" })
public static ShortFunction handleThrowing(@Nonnull EShortFunction handled,
@Nonnull Function handler) throws X {
return p -> {
try {
return handled.applyChecked(p);
} catch (Throwable e) { // NOSONAR can't catch generic exceptions
throw asUnchecked(handler.apply(e));
}
};
}
/**
* Handles a generic exception type that may occur in the handled function by
* throwing it explicitly.
*
* @param