argos/dmp-backend/core/src/main/java/eu/eudat/commons/validation/specification/PropertySpecificationBuilde...

63 lines
1.3 KiB
Java

package eu.eudat.commons.validation.specification;
import java.util.function.Supplier;
public class PropertySpecificationBuilder implements PropertySpecification{
private Supplier<Boolean> precondition;
private Supplier<Boolean> specification;
private String errorKey;
private String errorMessage;
private String errorCode = "validationerror";
public PropertySpecificationBuilder iff(Supplier<Boolean> value){
this.precondition = value;
return this;
}
public PropertySpecificationBuilder must(Supplier<Boolean> value){
this.specification = value;
return this;
}
public PropertySpecificationBuilder failOn(String value){
this.errorKey = value;
return this;
}
public PropertySpecificationBuilder failWith(String value){
this.errorMessage = value;
return this;
}
public PropertySpecificationBuilder failWithCode(String value){
this.errorCode = value;
return this;
}
@Override
public Supplier<Boolean> getPrecondition() {
return precondition;
}
@Override
public Supplier<Boolean> getSpecification() {
return specification;
}
@Override
public String getErrorKey() {
return errorKey;
}
@Override
public String getErrorMessage() {
return errorMessage;
}
@Override
public String getErrorCode() {
return errorCode;
}
}