toset

1
2
3
4
5
6
7
8
9
10
11
12
13
public class DaysOfWeekValidator implements ConstraintValidator<DaysOfWeek, LocalDate> {
 
    private Set<DayOfWeek> validDays;
 
    public void initialize(DaysOfWeek constraint) {
        validDays = Arrays.stream(constraint.days()).collect(Collectors.toSet());
    }
 
    public boolean isValid(LocalDate localDate, ConstraintValidatorContext context) {
        return localDate != null && validDays.contains(localDate.getDayOfWeek());
    }
 
}
Viking