Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.validation.ConstraintValidator;
- import javax.validation.ConstraintValidatorContext;
- import java.util.List;
- import java.util.Objects;
- public class CapacityValidator implements ConstraintValidator<Capacity, List<Integer>> {
- private int min;
- // private int max;
- @Override
- public void initialize(Capacity constraintAnnotation) {
- this.min = constraintAnnotation.min();
- System.out.println("Init");
- // this.max = constraintAnnotation.max();
- }
- @Override
- public boolean isValid(List<Integer> list, ConstraintValidatorContext constraintValidatorContext) {
- if(list.size() != this.min){
- return false;
- }
- if(list.stream().noneMatch(Objects::nonNull)){
- return false;
- }
- if(list.size() == this.min && list.stream().allMatch(Objects::nonNull)){
- return true;
- }
- return false;
- }
- }
Add Comment
Please, Sign In to add comment