Skip to content

Commit

Permalink
#143 [fix] preferRegion 값 Validation 함수 작성
Browse files Browse the repository at this point in the history
  • Loading branch information
hellozo0 committed Jan 16, 2024
1 parent 301a6e0 commit c4546e3
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;

import java.util.HashSet;
import java.util.List;

public class PreferRegionsValidator implements ConstraintValidator<ValidPreferRegions, List<Long>> {
Expand All @@ -14,9 +15,11 @@ public void initialize(ValidPreferRegions constraintAnnotation) {
@Override
public boolean isValid(List<Long> preferRegions, ConstraintValidatorContext context) {

if(preferRegions.size() > 3) return false;
if(preferRegions.stream().filter(p -> p == 0).count() > 1) return false;
if(!preferRegions.stream().allMatch(p -> p >= 0 && p <= 25)) return false;
if (preferRegions.size() != new HashSet<>(preferRegions).size()) return false;
if (preferRegions.stream().filter(p -> p == 0).count() <= 1 && preferRegions.stream().anyMatch(p -> p != 0)) return false;
if (!preferRegions.stream().allMatch(p -> p >= 0 && p <= 25)) return false;
if (preferRegions.size() > 3 ) return false;

return true;

}
Expand Down

0 comments on commit c4546e3

Please sign in to comment.