style: reduce redundant codes

This commit is contained in:
zihluwang
2024-08-22 21:38:06 +08:00
parent 578d77d5d3
commit 21aa2e2221
@@ -89,62 +89,50 @@ public final class BranchUtil<T> {
* Creates a {@code BranchUtil} instance to evaluate a logical OR operation on the provided * Creates a {@code BranchUtil} instance to evaluate a logical OR operation on the provided
* boolean expressions. * boolean expressions.
* *
* @param booleans the boolean expressions to be evaluated * @param values the boolean expressions to be evaluated
* @param <T> the type of the result to be handled by the methods * @param <T> the type of the result to be handled by the methods
* @return a {@code BranchUtil} instance representing the result of the logical OR operation * @return a {@code BranchUtil} instance representing the result of the logical OR operation
*/ */
public static <T> BranchUtil<T> or(Boolean... booleans) { public static <T> BranchUtil<T> or(Boolean... values) {
var result = Arrays.stream(booleans) return new BranchUtil<>(BoolUtil.or(values));
.filter(Objects::nonNull)
.anyMatch(Boolean::booleanValue);
return new BranchUtil<>(result);
} }
/** /**
* Creates a {@code BranchUtil} instance to evaluate a logical AND operation on the provided * Creates a {@code BranchUtil} instance to evaluate a logical AND operation on the provided
* boolean expressions. * boolean expressions.
* *
* @param booleans the boolean expressions to be evaluated * @param values the boolean expressions to be evaluated
* @param <T> the type of the result to be handled by the methods * @param <T> the type of the result to be handled by the methods
* @return a {@code BranchUtil} instance representing the result of the logical AND operation * @return a {@code BranchUtil} instance representing the result of the logical AND operation
*/ */
public static <T> BranchUtil<T> and(Boolean... booleans) { public static <T> BranchUtil<T> and(Boolean... values) {
var result = Arrays.stream(booleans) return new BranchUtil<>(BoolUtil.and(values));
.filter(Objects::nonNull)
.allMatch(Boolean::booleanValue);
return new BranchUtil<>(result);
} }
/** /**
* Creates a {@code BranchUtil} instance to evaluate a logical OR operation on the provided * Creates a {@code BranchUtil} instance to evaluate a logical OR operation on the provided
* boolean suppliers. * boolean suppliers.
* *
* @param booleanSuppliers the boolean suppliers to be evaluated * @param valueSuppliers the boolean suppliers to be evaluated
* @param <T> the type of the result to be handled by the methods * @param <T> the type of the result to be handled by the methods
* @return a {@code BranchUtil} instance representing the result of the * @return a {@code BranchUtil} instance representing the result of the
* logical OR operation * logical OR operation
*/ */
public static <T> BranchUtil<T> or(BooleanSupplier... booleanSuppliers) { public static <T> BranchUtil<T> or(BooleanSupplier... valueSuppliers) {
var result = Arrays.stream(booleanSuppliers) return new BranchUtil<>(BoolUtil.or(valueSuppliers));
.filter(Objects::nonNull)
.anyMatch(BooleanSupplier::getAsBoolean);
return new BranchUtil<>(result);
} }
/** /**
* Creates a {@code BranchUtil} instance to evaluate a logical AND operation on the provided * Creates a {@code BranchUtil} instance to evaluate a logical AND operation on the provided
* boolean suppliers. * boolean suppliers.
* *
* @param booleanSuppliers the boolean suppliers to be evaluated * @param valueSuppliers the boolean suppliers to be evaluated
* @param <T> the type of the result to be handled by the methods * @param <T> the type of the result to be handled by the methods
* @return a {@code BranchUtil} instance representing the result of the * @return a {@code BranchUtil} instance representing the result of the
* logical AND operation * logical AND operation
*/ */
public static <T> BranchUtil<T> and(BooleanSupplier... booleanSuppliers) { public static <T> BranchUtil<T> and(BooleanSupplier... valueSuppliers) {
var result = Arrays.stream(booleanSuppliers) return new BranchUtil<>(BoolUtil.and(valueSuppliers));
.filter(Objects::nonNull)
.allMatch(BooleanSupplier::getAsBoolean);
return new BranchUtil<>(result);
} }
/** /**