Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,39 +59,13 @@ public interface BiPredicateWithException<T, U, E extends Exception>
*/
boolean test(T t, U u) throws E;

/**
* Converts this {@code BiPredicateWithException} to a {@code BiPredicate} that
* convert exception to {@code RuntimeException}.
*
* @return the unchecked predicate
* @see #unchecked(BiPredicateWithException)
* @see #unchecked(BiPredicateWithException, Function)
*/
@Override
default BiPredicate<T, U> uncheck() {
return (t, u) -> {
try {
return test(t, u);
} catch (Exception e) {
throw exceptionMapper().apply(e);
}
};

}

/**
* Converts this {@code BiPredicateWithException} to a lifted
* {@code BiPredicate} returning {@code null} in case of exception.
*
* @return the predicate that ignore error (return false in this case)
* @see #ignored(BiPredicateWithException)
*/
@Override
default BiPredicate<T, U> ignore() {
default BiPredicate<T, U> uncheckOrIgnore(boolean uncheck) {
return (t, u) -> {
try {
return test(t, u);
} catch (Exception e) {
PrimitiveReturnExceptionHandlerSupport.handleException(uncheck, e, exceptionMapper());
return false;
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,38 +50,13 @@ public interface BooleanSupplierWithException<E extends Exception>
*/
boolean getAsBoolean() throws E;

/**
* Converts this {@code BooleanSupplierWithException} to a
* {@code BooleanSupplier} that convert exception to {@code RuntimeException}.
*
* @return the unchecked supplier
* @see #unchecked(BooleanSupplierWithException)
* @see #unchecked(BooleanSupplierWithException, Function)
*/
@Override
default BooleanSupplier uncheck() {
return () -> {
try {
return getAsBoolean();
} catch (Exception e) {
throw exceptionMapper().apply(e);
}
};
}

/**
* Converts this {@code BooleanSupplierWithException} to a lifted
* {@code BooleanSupplier} returning {@code false} in case of exception.
*
* @return the supplier that ignore error
* @see #ignored(BooleanSupplierWithException)
*/
@Override
default BooleanSupplier ignore() {
default BooleanSupplier uncheckOrIgnore(boolean uncheck) {
return () -> {
try {
return getAsBoolean();
} catch (Exception e) {
PrimitiveReturnExceptionHandlerSupport.handleException(uncheck, e, exceptionMapper());
return false;
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@
import java.util.function.Supplier;

/**
* Represents a double binary operator with exception.
* Represents an operation upon two {@code double}-valued operands, may throw
* exception and producing a {@code double}-valued result. This is the primitive
* type specialization of {@link BinaryOperatorWithException} for
* {@code double}.
*
* @author borettim
* @see DoubleBinaryOperator
* @param <E>
* the type of the potential exception of the function
Expand All @@ -39,54 +41,27 @@ public interface DoubleBinaryOperatorWithException<E extends Exception>
extends PrimitiveReturnExceptionHandlerSupport<DoubleBinaryOperator> {

/**
* Applies this function to the given arguments.
* Applies this operator to the given operands.
*
* @param t
* the first function argument
* @param u
* the second function argument
* @return the function result
* @param left
* the first operand
* @param right
* the second operand
* @return the operator result
* @throws E
* any exception
* @see DoubleBinaryOperator#applyAsDouble(double, double)
*/
double applyAsDouble(double t, double u) throws E;
double applyAsDouble(double left, double right) throws E;

/**
* Converts this {@code DoubleBinaryOperatorWithException} to a
* {@code DoubleBinaryOperator} that convert exception to
* {@code RuntimeException}.
*
* @return the unchecked function
* @see #unchecked(DoubleBinaryOperatorWithException)
* @see #unchecked(DoubleBinaryOperatorWithException, Function)
*/
@Override
default DoubleBinaryOperator uncheck() {
return (t, u) -> {
try {
return applyAsDouble(t, u);
} catch (Exception e) {
throw exceptionMapper().apply(e);
}
};

}

/**
* Converts this {@code DoubleBinaryOperatorWithException} to a lifted
* {@code DoubleBinaryOperator} returning uero in case of exception.
*
* @return the function that ignore error
* @see #ignored(DoubleBinaryOperatorWithException)
*/
@Override
default DoubleBinaryOperator ignore() {
return (t, u) -> {
default DoubleBinaryOperator uncheckOrIgnore(boolean uncheck) {
return (left, right) -> {
try {
return applyAsDouble(t, u);
return applyAsDouble(left, right);
} catch (Exception e) {
return 0d;
PrimitiveReturnExceptionHandlerSupport.handleException(uncheck, e, exceptionMapper());
return 0;
}
};
}
Expand All @@ -101,7 +76,7 @@ default DoubleBinaryOperator ignore() {
* @return a function that always throw exception
*/
static <E extends Exception> DoubleBinaryOperatorWithException<E> failing(Supplier<E> exceptionBuilder) {
return (t, u) -> {
return (left, right) -> {
throw exceptionBuilder.get();
};
}
Expand Down Expand Up @@ -145,8 +120,8 @@ static <E extends Exception> DoubleBinaryOperator unchecked(DoubleBinaryOperator
return new DoubleBinaryOperatorWithException<E>() {

@Override
public double applyAsDouble(double t, double u) throws E {
return function.applyAsDouble(t, u);
public double applyAsDouble(double left, double right) throws E {
return function.applyAsDouble(left, right);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,39 +52,13 @@ public interface DoublePredicateWithException<E extends Exception>
*/
boolean test(double t) throws E;

/**
* Converts this {@code DoublePredicateWithException} to a
* {@code DoublePredicate} that convert exception to {@code RuntimeException}.
*
* @return the unchecked predicate
* @see #unchecked(DoublePredicateWithException)
* @see #unchecked(DoublePredicateWithException, Function)
*/
@Override
default DoublePredicate uncheck() {
return t -> {
try {
return test(t);
} catch (Exception e) {
throw exceptionMapper().apply(e);
}
};

}

/**
* Converts this {@code DoublePredicateWithException} to a lifted
* {@code DoublePredicate} returning {@code false} in case of exception.
*
* @return the predicate that ignore error (return false in this case)
* @see #ignored(DoublePredicateWithException)
*/
@Override
default DoublePredicate ignore() {
return t -> {
default DoublePredicate uncheckOrIgnore(boolean uncheck) {
return value -> {
try {
return test(t);
return test(value);
} catch (Exception e) {
PrimitiveReturnExceptionHandlerSupport.handleException(uncheck, e, exceptionMapper());
return false;
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,38 +50,13 @@ public interface DoubleSupplierWithException<E extends Exception>
*/
double getAsDouble() throws E;

/**
* Converts this {@code DoubleSupplierWithException} to a {@code DoubleSupplier}
* that convert exception to {@code RuntimeException}.
*
* @return the unchecked supplier
* @see #unchecked(DoubleSupplierWithException)
* @see #unchecked(DoubleSupplierWithException, Function)
*/
@Override
default DoubleSupplier uncheck() {
return () -> {
try {
return getAsDouble();
} catch (Exception e) {
throw exceptionMapper().apply(e);
}
};
}

/**
* Converts this {@code DoubleSupplierWithException} to a lifted
* {@code DoubleSupplier} returning {@code 0} in case of exception.
*
* @return the supplier that ignore error
* @see #ignored(DoubleSupplierWithException)
*/
@Override
default DoubleSupplier ignore() {
default DoubleSupplier uncheckOrIgnore(boolean uncheck) {
return () -> {
try {
return getAsDouble();
} catch (Exception e) {
PrimitiveReturnExceptionHandlerSupport.handleException(uncheck, e, exceptionMapper());
return 0;
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,40 +51,13 @@ public interface DoubleToIntFunctionWithException<E extends Exception>
*/
int applyAsInt(double t) throws E;

/**
* Converts this {@code DoubleToIntFunctionWithException} to a
* {@code DoubleToIntFunction} that convert exception to
* {@code RuntimeException}.
*
* @return the unchecked predicate
* @see #unchecked(DoubleToIntFunctionWithException)
* @see #unchecked(DoubleToIntFunctionWithException, Function)
*/
@Override
default DoubleToIntFunction uncheck() {
return t -> {
try {
return applyAsInt(t);
} catch (Exception e) {
throw exceptionMapper().apply(e);
}
};

}

/**
* Converts this {@code DoubleToIntFunctionWithException} to a lifted
* {@code DoubleToIntFunction} returning {@code null} in case of exception.
*
* @return the predicate that ignore error (return false in this case)
* @see #ignored(DoubleToIntFunctionWithException)
*/
@Override
default DoubleToIntFunction ignore() {
return t -> {
default DoubleToIntFunction uncheckOrIgnore(boolean uncheck) {
return value -> {
try {
return applyAsInt(t);
return applyAsInt(value);
} catch (Exception e) {
PrimitiveReturnExceptionHandlerSupport.handleException(uncheck, e, exceptionMapper());
return 0;
}
};
Expand Down
Loading