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

org.xbib.net.security.ssl.util.ValidationUtils Maven / Gradle / Ivy

The newest version!
package org.xbib.net.security.ssl.util;

import java.util.List;
import java.util.function.Supplier;
import java.util.function.UnaryOperator;

public final class ValidationUtils {

    public static final UnaryOperator GENERIC_EXCEPTION_MESSAGE = objectType -> String.format("No valid %s has been provided. %s must be present, but was absent.", objectType, objectType);

    private ValidationUtils() {
    }

    public static  T requireNotNull(T maybeNull, String message) {
        return requireNotNull(maybeNull, () -> new IllegalArgumentException(message));
    }

    public static  T requireNotNull(T maybeNull, Supplier exceptionSupplier) {
        if (maybeNull == null) {
            throw exceptionSupplier.get();
        }
        return maybeNull;
    }

    public static  List requireNotEmpty(List maybeNull, String message) {
        return requireNotEmpty(maybeNull, () -> new IllegalArgumentException(message));
    }

    public static  List requireNotEmpty(List maybeNull, Supplier exceptionSupplier) {
        if (maybeNull == null || maybeNull.isEmpty()) {
            throw exceptionSupplier.get();
        }
        return maybeNull;
    }

    public static String requireNotBlank(String maybeNull, String message) {
        return requireNotBlank(maybeNull, () -> new IllegalArgumentException(message));
    }

    public static String requireNotBlank(String maybeNull, Supplier exceptionSupplier) {
        if (StringUtils.isBlank(maybeNull)) {
            throw exceptionSupplier.get();
        }
        return maybeNull;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy