Skip to content

Commit

Permalink
Simplify gh-236 (#242)
Browse files Browse the repository at this point in the history
  • Loading branch information
making authored May 2, 2022
1 parent c82807c commit 7368659
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions src/main/java/am/ik/yavi/core/Validator.java
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,8 @@ private ConstraintViolations validate(T target, String collectionName, int index
}
else {
final String name = this.indexedName("", nestedName, i++);
final ConstraintViolations v = this.nullSupplierValidator(name)
.validate(() -> null, locale, constraintContext);
violations.addAll(v);
final ConstraintViolation v = notNullViolation(name, locale);
violations.add(v);
}
if (!violations.isEmpty() && this.failFast) {
return violations;
Expand Down Expand Up @@ -259,16 +258,10 @@ private ConstraintViolations validate(T target, String collectionName, int index
return violations;
}

private Validator<Supplier<Object>> nullSupplierValidator(String name) {
final Deque<ConstraintPredicate<Object>> notNull = new LinkedList<>();
notNull.add(ConstraintPredicate.of(Objects::nonNull, OBJECT_NOT_NULL,
() -> new Object[] {}, NullAs.INVALID));
final ConstraintPredicates<Supplier<Object>, Object> constraintPredicates = new ConstraintPredicates<>(
Supplier::get, name, notNull);
return new Validator<>(this.messageKeySeparator,
Collections.singletonList(constraintPredicates), Collections.emptyList(),
Collections.emptyList(), this.messageFormatter, this.failFast,
this.prefix);
private ConstraintViolation notNullViolation(String name, Locale locale) {
return new ConstraintViolation(name, OBJECT_NOT_NULL.messageKey(),
OBJECT_NOT_NULL.defaultMessageFormat(),
pad(name, new Object[] {}, new ViolatedValue(null)),
this.messageFormatter, locale);
}

}

0 comments on commit 7368659

Please sign in to comment.