Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

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());
    }
 
}
Source by dolszewski.com #
 
PREVIOUS NEXT
Tagged: #toSet
ADD COMMENT
Topic
Name
6+5 =