/* * Hunt - A data validation for DLang based on hunt library. * * Copyright (C) 2015-2019, HuntLabs * * Website: https://www.huntlabs.net * * Licensed under the Apache-2.0 License. * */ module hunt.validation.ConstraintValidator; import hunt.validation.ConstraintValidatorContext; interface ConstraintValidator(A , T) { /** * Initializes the validator in preparation for * {@link #isValid(Object, ConstraintValidatorContext)} calls. * The constraint annotation for a given constraint declaration * is passed. * <p> * This method is guaranteed to be called before any use of this instance for * validation. * <p> * The default implementation is a no-op. * * @param constraintAnnotation annotation instance for a given constraint declaration */ void initialize(A constraintAnnotation); /** * Implements the validation logic. * The state of {@code value} must not be altered. * <p> * This method can be accessed concurrently, thread-safety must be ensured * by the implementation. * * @param value object to validate * @param context context in which the constraint is evaluated * * @return {@code false} if {@code value} does not pass the constraint */ bool isValid(T value, ConstraintValidatorContext context); }