org.solidcoding.validation.api.AbstractLoggingValidator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of solidcoding-validation Show documentation
Show all versions of solidcoding-validation Show documentation
A small package that enables validation of (business) rules through a fluent API.
package org.solidcoding.validation.api;
import org.slf4j.Logger;
public abstract class AbstractLoggingValidator implements LoggingValidator {
protected final ContinuingValidator validator;
protected AbstractLoggingValidator(ContinuingValidator validator) {
this.validator = validator;
}
@Override
public void orElseLogInfo(Logger logger) {
var isValid = validator.validate();
if (!isValid) {
logger.info(validator.getMessage());
}
}
@Override
public void orElseLogWarn(Logger logger) {
var isValid = validator.validate();
if (!isValid) {
logger.warn(validator.getMessage());
}
}
@Override
public void orElseLogError(Logger logger) {
var isValid = validator.validate();
if (!isValid) {
logger.error(validator.getMessage());
}
}
}