All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.proximax.utils.ParameterValidationUtils Maven / Gradle / Ivy

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); } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy