io.proximax.utils.ParameterValidationUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of java-chain-xipfs-sdk Show documentation
Show all versions of java-chain-xipfs-sdk Show documentation
Official ProximaX P2P Storage SDK Library in Java.
The newest version!
package io.proximax.utils;
import java.util.function.Supplier;
/**
* The utility class to verify method parameters
*/
public class ParameterValidationUtils {
private ParameterValidationUtils() {
}
/**
* Validates a given parameter by accepting a resolved condition.
*
*
* This throws an IllegalArgumentException with the provided message if condition not valid.
* @param isValid a resolved validation result for a given parameter
* @param invalidMessage the exception message to use when throwing exception
*/
public static void checkParameter(boolean isValid, String invalidMessage) {
if (!isValid) throw new IllegalArgumentException(invalidMessage);
}
/**
* Validates a given parameter by accepting a non-resolved condition.
*
*
* This throws an IllegalArgumentException with the provided message if condition is not valid and has exception
* @param isValidSupplier a resolved validation result for a given parameter
* @param invalidMessage the exception message to use when throwing exception
*/
public static void checkParameter(Supplier isValidSupplier, String invalidMessage) {
try {
if (!isValidSupplier.get()) {
throw new IllegalArgumentException(invalidMessage);
}
} catch (Exception ex) {
throw new IllegalArgumentException(invalidMessage, ex);
}
}
}