com.github.ldeitos.validation.Severity Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of extendedValidation-core Show documentation
Show all versions of extendedValidation-core Show documentation
Extension for BeanValidation API Core. Content interfaces, qualifiers and constraints definitions.
This version is Java 17 and JakartaEE 10 compatible.
package com.github.ldeitos.validation;
import static com.github.ldeitos.validation.ConstraintSeverity.alert;
import static com.github.ldeitos.validation.ConstraintSeverity.defaultValue;
import static com.github.ldeitos.validation.ConstraintSeverity.error;
import static com.github.ldeitos.validation.ConstraintSeverity.fatal;
import static com.github.ldeitos.validation.ConstraintSeverity.info;
import static com.github.ldeitos.validation.ConstraintSeverity.warn;
/**
* Possibles severity level to be generated by ExtendedValidation engine.
*
* @author Leandro Deitos
*
*/
public enum Severity {
/**
* Error severity.
*/
ERROR(error()),
/**
* Alert severity.
*/
ALERT(alert()),
/**
* Info severity.
*/
INFO(info()),
/**
* Warn severity.
*/
WARN(warn()),
/**
* Fatal severity.
*/
FATAL(fatal());
private Class extends ConstraintSeverity> cSeverity;
private Severity(Class extends ConstraintSeverity> constraintSeverity){
this.cSeverity = constraintSeverity;
}
Class extends ConstraintSeverity> getConstraintSeverity() {
return cSeverity;
}
/**
* @param constraintSeveritiry
* {@link ConstraintSeverity} to recover {@link Severity} equivalent.
* @return
* {@link Severity} item recovered by {@link ConstraintSeverity}.
* Case {@link ConstraintSeverity} does't have a equivalent {@link Severity}, {@link #ERROR} is a default return.
*/
public static Severity fromConstraintSeverity(Class extends ConstraintSeverity> constraintSeveritiry){
Severity retorno = null;
for(Severity value : values()){
if(value.equals(constraintSeveritiry)){
retorno = value;
break;
}
}
if(retorno == null){
retorno = fromConstraintSeverity(defaultValue());
}
return retorno;
}
}