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 @@ -23,15 +23,14 @@
import java.util.Objects;

/**
* The {@link Base64Util} class provides static methods to encode and decode
* strings with Base64 encoding. It utilizes the {@link Base64} class from the
* Java standard library for performing the encoding and decoding operations.
* This utility class offers convenient methods to encode and decode strings
* with different character sets.
* The {@link Base64Util} class provides static methods to encode and decode strings with Base64
* encoding. It utilizes the {@link Base64} class from the Java standard library for performing the
* encoding and decoding operations. This utility class offers convenient methods to encode and
* decode strings with different character sets.
* <p>
* This class is designed as a final class with a private constructor to
* prevent instantiation. All methods in this class are static, allowing easy
* access to the Base64 encoding and decoding functionality.
* This class is designed as a final class with a private constructor to prevent instantiation.
* All methods in this class are static, allowing easy access to the Base64 encoding and
* decoding functionality.
* <p>
* Example usage:
* <pre>
Expand All @@ -46,9 +45,9 @@
* System.out.println("Decoded string: " + decoded);
* </pre>
* <p>
* <b>Note:</b> This utility class uses the default charset (UTF-8) if no
* specific charset is provided. It is recommended to specify the charset
* explicitly to ensure consistent encoding and decoding.
* <b>Note:</b> This utility class uses the default charset (UTF-8) if no specific charset is
* provided. It is recommended to specify the charset explicitly to ensure consistent
* encoding and decoding.
*
* @author Zihlu Wang
* @version 1.1.0
Expand Down
100 changes: 43 additions & 57 deletions devkit-utils/src/main/java/com/onixbyte/devkit/utils/BranchUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,13 @@
import java.util.function.Supplier;

/**
* The {@link BranchUtil} class provides static methods to simplify conditional
* logic in Java development by leveraging lambda expressions. It offers
* convenient methods to replace verbose {@code if...else} statements with more
* concise and expressive functional constructs.
* The {@link BranchUtil} class provides static methods to simplify conditional logic in Java
* development by leveraging lambda expressions. It offers convenient methods to replace verbose
* {@code if...else} statements with more concise and expressive functional constructs.
* <p>
* Developers can use methods in this utility class to streamline their code,
* enhance readability, and promote a more functional style of programming when
* dealing with branching logic and conditional statements.
* Developers can use methods in this utility class to streamline their code, enhance readability,
* and promote a more functional style of programming when dealing with branching logic and
* conditional statements.
* <p>
* <b>Example:</b>
* <pre>
Expand Down Expand Up @@ -64,11 +63,11 @@
* </pre>
* <p>
* <b>Note:</b>
* The {@link #and(Boolean...)} and {@link #or(Boolean...)} methods accept any
* number of boolean expressions.
* The {@link #and(Boolean...)} and {@link #or(Boolean...)} methods accept any number of boolean
* expressions.
*
* @param <T> the type of the result to be handled by the methods
* @author Zihlu Wang
* @author zihluwang
* @version 1.1.0
* @see java.util.function.Supplier
* @see java.util.function.BooleanSupplier
Expand All @@ -87,13 +86,12 @@ private BranchUtil(boolean result) {
}

/**
* Creates a {@code BranchUtil} instance to evaluate a logical OR operation
* on the provided boolean expressions.
* Creates a {@code BranchUtil} instance to evaluate a logical OR operation on the provided
* boolean expressions.
*
* @param booleans the boolean expressions to be evaluated
* @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) {
var result = Arrays.stream(booleans)
Expand All @@ -103,13 +101,12 @@ public static <T> BranchUtil<T> or(Boolean... booleans) {
}

/**
* Creates a {@code BranchUtil} instance to evaluate a logical AND
* operation on the provided boolean expressions.
* Creates a {@code BranchUtil} instance to evaluate a logical AND operation on the provided
* boolean expressions.
*
* @param booleans the boolean expressions to be evaluated
* @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) {
var result = Arrays.stream(booleans)
Expand All @@ -119,12 +116,11 @@ public static <T> BranchUtil<T> and(Boolean... booleans) {
}

/**
* Creates a {@code BranchUtil} instance to evaluate a logical OR operation
* on the provided boolean suppliers.
* Creates a {@code BranchUtil} instance to evaluate a logical OR operation on the provided
* boolean suppliers.
*
* @param booleanSuppliers 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
* logical OR operation
*/
Expand All @@ -136,12 +132,11 @@ public static <T> BranchUtil<T> or(BooleanSupplier... booleanSuppliers) {
}

/**
* Creates a {@code BranchUtil} instance to evaluate a logical AND
* operation on the provided boolean suppliers.
* Creates a {@code BranchUtil} instance to evaluate a logical AND operation on the provided
* boolean suppliers.
*
* @param booleanSuppliers 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
* logical AND operation
*/
Expand All @@ -153,22 +148,18 @@ public static <T> BranchUtil<T> and(BooleanSupplier... booleanSuppliers) {
}

/**
* Handles the result of the boolean expressions by executing the
* appropriate handler based on the result.
* Handles the result of the boolean expressions by executing the appropriate handler based
* on the result.
* <p>
* If the result is {@code true}, the {@code ifHandler} is executed. If the
* result is {@code false} and an {@code elseHandler} is provided, it is
* executed.
* If the result is {@code true}, the {@code ifHandler} is executed. If the result is
* {@code false} and an {@code elseHandler} is provided, it is executed.
* <p>
* Returns the result of the executed handler.
*
* @param ifHandler the handler to be executed if the result is
* {@code true}
* @param elseHandler the handler to be executed if the result is
* {@code false} (optional)
* @return the result of the executed handler, or {@code null} if no
* {@code elseHandler} is provided and the result of the evaluation is
* {@code false}
* @param ifHandler the handler to be executed if the result is {@code true}
* @param elseHandler the handler to be executed if the result is {@code false} (optional)
* @return the result of the executed handler, or {@code null} if no {@code elseHandler} is
* provided and the result of the evaluation is {@code false}
*/
public T handle(Supplier<T> ifHandler, Supplier<T> elseHandler) {
if (this.result && Objects.nonNull(ifHandler)) {
Expand All @@ -183,32 +174,28 @@ public T handle(Supplier<T> ifHandler, Supplier<T> elseHandler) {
}

/**
* Handles the result of the boolean expressions by executing the provided
* handler if the result is {@code true}.
* Handles the result of the boolean expressions by executing the provided handler if the
* result is {@code true}.
* <p>
* Returns the result of the executed handler.
*
* @param ifHandler the handler to be executed if the result is
* {@code true}
* @return the result of the executed handler, or {@code null} if result of
* evaluation is {@code false}
* @param ifHandler the handler to be executed if the result is {@code true}
* @return the result of the executed handler, or {@code null} if result of evaluation is
* {@code false}
*/
public T handle(Supplier<T> ifHandler) {
return handle(ifHandler, null);
}

/**
* Handles the result of the boolean expressions by executing the
* appropriate handler based on the result.
* Handles the result of the boolean expressions by executing the appropriate handler based
* on the result.
* <p>
* If the result is {@code true}, the {@code ifHandler} is executed. If the
* result is {@code false} and an {@code elseHandler} is provided, it is
* executed.
* If the result is {@code true}, the {@code ifHandler} is executed. If the result is
* {@code false} and an {@code elseHandler} is provided, it is executed.
*
* @param ifHandler the handler to be executed if the result is
* {@code true}
* @param elseHandler the handler to be executed if the result is
* {@code false} (optional)
* @param ifHandler the handler to be executed if the result is {@code true}
* @param elseHandler the handler to be executed if the result is {@code false} (optional)
*/
public void handle(Runnable ifHandler, Runnable elseHandler) {
if (this.result && Objects.nonNull(ifHandler)) {
Expand All @@ -224,11 +211,10 @@ public void handle(Runnable ifHandler, Runnable elseHandler) {
}

/**
* Handles the result of the boolean expressions by executing the provided
* handler if the result is {@code true}.
* Handles the result of the boolean expressions by executing the provided handler if the
* result is {@code true}.
*
* @param ifHandler the handler to be executed if the result is
* {@code true}
* @param ifHandler the handler to be executed if the result is {@code true}
*/
public void handle(Runnable ifHandler) {
handle(ifHandler, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,11 @@
import java.util.function.Function;

/**
* The {@code ChainedCalcUtil} class provides a convenient way to perform
* chained high-precision calculations using {@link BigDecimal}. It allows
* users to perform mathematical operations such as addition, subtraction,
* multiplication, and division with customisable precision and scale. By using
* this utility class, developers can achieve accurate results and avoid
* precision loss in their calculations.
* The {@code ChainedCalcUtil} class provides a convenient way to perform chained high-precision
* calculations using {@link BigDecimal}. It allows users to perform mathematical operations such
* as addition, subtraction, multiplication, and division with customisable precision and scale.
* By using this utility class, developers can achieve accurate results and avoid precision loss
* in their calculations.
* <p>
* <b>Usage:</b>
* <pre>
Expand Down Expand Up @@ -82,10 +81,9 @@
* {@code ChainedCalcUtil} class.
* <p>
* <b>Note:</b>
* The {@code ChainedCalcUtil} class internally uses {@link BigDecimal} to
* handle high-precision calculations. It is important to note that {@link
* BigDecimal} operations can be memory-intensive and may have performance
* implications for extremely large numbers or complex calculations.
* The {@code ChainedCalcUtil} class internally uses {@link BigDecimal} to handle high-precision
* calculations. It is important to note that {@link BigDecimal} operations can be memory-intensive
* and may have performance implications for extremely large numbers or complex calculations.
*
* @author sunzsh
* @version 1.1.0
Expand All @@ -96,8 +94,7 @@
public final class ChainedCalcUtil {

/**
* Creates a {@code ChainedCalcUtil} instance with the specified initial
* value.
* Creates a {@code ChainedCalcUtil} instance with the specified initial value.
*
* @param value the initial value for the calculation
*/
Expand Down Expand Up @@ -126,8 +123,7 @@ public ChainedCalcUtil add(Number other) {
}

/**
* Adds the specified value to the current value with a specified scale
* before the operation.
* Adds the specified value to the current value with a specified scale before the operation.
*
* @param other the value to be added
* @param beforeOperateScale the scale to be applied before the operation
Expand All @@ -148,8 +144,8 @@ public ChainedCalcUtil subtract(Number other) {
}

/**
* Subtracts the specified value from the current value with a specified
* scale before the operation.
* Subtracts the specified value from the current value with a specified scale before
* the operation.
*
* @param other the value to be subtracted
* @param beforeOperateScale the scale to be applied before the operation
Expand All @@ -170,8 +166,8 @@ public ChainedCalcUtil multiply(Number other) {
}

/**
* Multiplies the current value by the specified value with a specified
* scale before the operation.
* Multiplies the current value by the specified value with a specified scale before
* the operation.
*
* @param other the value to be multiplied by
* @param beforeOperateScale the scale to be applied before the operation
Expand All @@ -192,8 +188,7 @@ public ChainedCalcUtil divide(Number other) {
}

/**
* Divides the current value by the specified value with a specified scale
* before the operation.
* Divides the current value by the specified value with a specified scale before the operation.
*
* @param other the value to divide by
* @param beforeOperateScale the scale to be applied before the operation
Expand All @@ -216,16 +211,18 @@ public ChainedCalcUtil divideWithScale(Number other, Integer scale) {
}

/**
* Divides the current value by the specified value with a specified scale
* and a scale applied before the operation.
* Divides the current value by the specified value with a specified scale and a scale applied
* before the operation.
*
* @param other the value to divide by
* @param scale the scale for the result
* @param beforeOperateScale the scale to be applied before the operation
* @return a {@code ChainedCalcUtil} instance with the updated value
*/
public ChainedCalcUtil divideWithScale(Number other, Integer scale, Integer beforeOperateScale) {
return baseOperator(otherValue -> this.value.divide(otherValue, scale, RoundingMode.HALF_UP), other, beforeOperateScale);
return baseOperator((otherValue) ->
this.value.divide(otherValue, scale, RoundingMode.HALF_UP),
other, beforeOperateScale);
}

/**
Expand Down Expand Up @@ -276,8 +273,7 @@ public Integer getInteger() {
}

/**
* Applies the specified operator function to the current value and another
* value.
* Applies the specified operator function to the current value and another value.
*
* @param operator the operator function to apply
* @param otherValue the value to apply the operator with
Expand All @@ -288,8 +284,8 @@ private ChainedCalcUtil operator(BiFunction<BigDecimal, BigDecimal, BigDecimal>
}

/**
* Applies the specified operator function to the current value and another
* value with a specified scale before the operation.
* Applies the specified operator function to the current value and another value with a
* specified scale before the operation.
*
* @param operator the operator function to apply
* @param other the value to apply the operator with
Expand All @@ -298,7 +294,10 @@ private ChainedCalcUtil operator(BiFunction<BigDecimal, BigDecimal, BigDecimal>
* @return a ChainedCalcUtil instance with the updated value
*/
private ChainedCalcUtil operator(BiFunction<BigDecimal, BigDecimal, BigDecimal> operator, Object other, Integer beforeOperateScale) {
return baseOperator((otherValue) -> operator.apply(this.value, otherValue), other, beforeOperateScale);
return baseOperator((otherValue) ->
operator.apply(this.value, otherValue),
other,
beforeOperateScale);
}

/**
Expand Down Expand Up @@ -328,8 +327,7 @@ private synchronized ChainedCalcUtil baseOperator(Function<BigDecimal, BigDecima
* Converts the specified value to a {@link BigDecimal}.
*
* @param value the value to convert
* @param scale the scale to apply to the resulting BigDecimal, or null if
* not applicable
* @param scale the scale to apply to the resulting BigDecimal, or null if not applicable
* @return the converted BigDecimal value
*/
private BigDecimal convertBigDecimal(Object value, Integer scale) {
Expand Down
Loading