I'm trying to refactoring this code 

```
private void validate(Customer customer) {

    List<String> errors = new ArrayList<>();

    if (customer == null) {
        errors.add("Customer must not be null");
    }

    if (customer != null && customer.getName() == null) {
        errors.add("Name must not be null");
    }

    if (customer != null && customer.getName().isEmpty()) {
        errors.add("Name must not be empty");
    }

    if (customer != null) {
        Customer customerFromDb = customerRepository.findByName(customer.getName());
        if (customerFromDb != null) {
            errors.add("Customer already present on db");
        }
    }

    if (!errors.isEmpty()) {
        throw new ValidationException(errors);
    }
}

```

I read this post [Business logic validation patterns & advices](https://stackoverflow.com/questions/38184481/business-logic-validation-patterns-advices)

I'd like to build a generic validator for my entities and fields of the entity, I wrote this

```
private void validate(Customer customer) {

    List<ValidationRule> validationRules = new ArrayList<>();

    validationRules.add(new NotNullValidationRule(customer));
    validationRules.add(new NotNullValidationRule(customer, Customer::getName));
    validationRules.add(new NotEmptyValidationRule(customer, Customer::getName));
    validationRules.add(new NotExistValidationRule(customer -> customerRepository.findByName(customer.getName())));

    Validator.validate(validationRules);
}

```

and the Validator class

```
public class Validator {

    public static void validate(List<ValidationRule> validationRules) {
        final List<String> errors = new ArrayList<>();
        for (final ValidationRule rule : validationRules) {
            final Optional<String> error = rule.validate();
            if (error.isPresent()) {
                errors.add(error.get());
            }
        }

        if (!errors.isEmpty()) {
            throw new ValidationException(errors);
        }
    }
}

```

but I don't know how to implement the interface ValidationRule and other classes (NotNullValidationRule, NotEmptyValidationRule, NotExistValidationRule)