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

com.github.saphyra.randwo.common.CollectionValidator Maven / Gradle / Ivy

There is a newer version: 1.1.0
Show newest version
package com.github.saphyra.randwo.common;

import static java.util.Objects.isNull;

import java.util.Collection;

import org.springframework.stereotype.Component;

import com.github.saphyra.exceptionhandling.domain.ErrorMessage;
import com.github.saphyra.exceptionhandling.exception.BadRequestException;

@Component
public class CollectionValidator {
    public  void validateDoesNotContainNull(Collection collection, ErrorCode errorCode) {
        collection.forEach(item -> validateItem(item, errorCode));
    }

    private  void validateItem(T item, ErrorCode errorCode) {
        if (isNull(item)) {
            throw new BadRequestException(new ErrorMessage(errorCode.getErrorCode()), "Collection contains null: " + errorCode);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy