Skip to content

Commit a882715

Browse files
authored
Tidy Validation Adapter (#278)
* Tidy Validation Adapter * Update ConstraintAdapter.java * doc
1 parent 9d353b8 commit a882715

File tree

5 files changed

+5
-15
lines changed

5 files changed

+5
-15
lines changed

validator/src/main/java/io/avaje/validation/adapter/AbstractConstraintAdapter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ protected AbstractConstraintAdapter(AdapterCreateRequest request) {
2020
}
2121

2222
/**
23-
* Execute Constraint validations for the given object.
23+
* Execute constraint validations for the given object.
2424
*
2525
* @param value the object to validate
2626
* @return false if a violation error should be added

validator/src/main/java/io/avaje/validation/adapter/ConstraintAdapter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
*
3939
* return isValid;
4040
* }
41-
*
41+
*}
4242
* }</pre>
4343
*/
4444
@Target(TYPE)

validator/src/main/java/io/avaje/validation/adapter/IterableValidationAdapter.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ public boolean validate(T value, ValidationRequest req, String propertyName) {
1212
if (initalAdapter.validate(value, req, propertyName)) {
1313
validateAll((Iterable<Object>) value, req, propertyName);
1414
}
15-
1615
return true;
1716
}
1817
}

validator/src/main/java/io/avaje/validation/adapter/ValidationAdapter.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ default boolean validate(T value, ValidationRequest req) {
3434
return validate(value, req, null);
3535
}
3636

37-
/** Return a primitive adapter. Supports int, long with Range, Min, Max, Positive. */
37+
/** Return primitive-handling version of this adapter. */
3838
default Primitive primitive() {
3939
throw new UnsupportedOperationException();
4040
}
@@ -93,12 +93,7 @@ default ContainerAdapter<T> optional() {
9393
*/
9494
default ValidationAdapter<T> andThen(ValidationAdapter<? super T> after) {
9595
Objects.requireNonNull(after, "after cannot be null");
96-
return (value, req, propertyName) -> {
97-
if (validate(value, req, propertyName)) {
98-
return after.validate(value, req, propertyName);
99-
}
100-
return false;
101-
};
96+
return (value, req, propertyName) -> validate(value, req, propertyName) && after.validate(value, req, propertyName);
10297
}
10398

10499
/**
@@ -119,7 +114,7 @@ default boolean checkGroups(Set<Class<?>> adapterGroups, ValidationRequest reque
119114
return false;
120115
}
121116

122-
/** Validation adapter that supports and uses the primitive type. */
117+
/** Validation adapter that supports and uses the primitive types. */
123118
interface Primitive {
124119

125120
/** Validate using primitive boolean. */

validator/src/main/java/io/avaje/validation/core/CoreAdapterBuilder.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,7 @@ <T> ValidationAdapter<T> annotationAdapter(
8282

8383
/**
8484
* Build given type and annotations.
85-
*
86-
* @param groups
8785
*/
88-
// TODO understand that lookup chain stuff
8986
@SuppressWarnings("unchecked")
9087
<T> ValidationAdapter<T> buildAnnotation(
9188
Class<? extends Annotation> cls,
@@ -155,7 +152,6 @@ public <T> T attribute(String key) {
155152
public Request withValue(long value) {
156153
Map<String, Object> newAttributes = new HashMap<>(attributes);
157154
newAttributes.put("value", value);
158-
//newAttributes.put("_type", "Long");
159155
return new Request(ctx, annotationType, groups, newAttributes);
160156
}
161157

0 commit comments

Comments
 (0)