class SingleOutputValidator implements ConstraintValidator<ValidSingleOutput, SingleOutputTaskParameters> {

    @Override
    public boolean isValid(SingleOutputTaskParameters value, ConstraintValidatorContext context) {
        if (nonNull(value)) {
            if (isNull(value.getOutput())) {
                return false;
            }
            if (isNull(value.getOutput().getDestination()) || (value.getOutput().getDestination().exists()
                    && (value.getExistingOutputPolicy() == ExistingOutputPolicy.FAIL
                            || value.getExistingOutputPolicy() == ExistingOutputPolicy.SKIP))) {
                context.disableDefaultConstraintViolation();
                context.buildConstraintViolationWithTemplate(
                        String.format("File destination already exists: %s.", value.getOutput().getDestination()))
                        .addConstraintViolation();
                return false;
            }
        }
        return true;
    }

}