@Override public Result<T> convertToModel(T value, ValueContext context) { ValidationResult validationResult = validator.apply(value, context); return new ValidationResultWrap<>(value, validationResult); }
/** * Validates the {@code bean} using validators added using * {@link #withValidator(Validator)} and returns the result of the * validation as a list of validation results. * <p> * * @see #withValidator(Validator) * * @param bean * the bean to validate * @return a list of validation errors or an empty list if validation * succeeded */ private List<ValidationResult> validateBean(BEAN bean) { Objects.requireNonNull(bean, "bean cannot be null"); List<ValidationResult> results = Collections.unmodifiableList(validators .stream() .map(validator -> validator.apply(bean, new ValueContext())) .collect(Collectors.toList())); return results; }
@Override public void validate(T value) throws ValidationException { ValidationResult result = validator.apply(value, getValueContext()); if (result.isError()) { throw new ValidationException(result.getErrorMessage()); } }