Skip to content

Tidy Validation Adapter #278

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ protected AbstractConstraintAdapter(AdapterCreateRequest request) {
}

/**
* Execute Constraint validations for the given object.
* Execute constraint validations for the given object.
*
* @param value the object to validate
* @return false if a violation error should be added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
*
* return isValid;
* }
*
*}
* }</pre>
*/
@Target(TYPE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ public boolean validate(T value, ValidationRequest req, String propertyName) {
if (initalAdapter.validate(value, req, propertyName)) {
validateAll((Iterable<Object>) value, req, propertyName);
}

return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ default boolean validate(T value, ValidationRequest req) {
return validate(value, req, null);
}

/** Return a primitive adapter. Supports int, long with Range, Min, Max, Positive. */
/** Return primitive-handling version of this adapter. */
default Primitive primitive() {
throw new UnsupportedOperationException();
}
Expand Down Expand Up @@ -93,12 +93,7 @@ default ContainerAdapter<T> optional() {
*/
default ValidationAdapter<T> andThen(ValidationAdapter<? super T> after) {
Objects.requireNonNull(after, "after cannot be null");
return (value, req, propertyName) -> {
if (validate(value, req, propertyName)) {
return after.validate(value, req, propertyName);
}
return false;
};
return (value, req, propertyName) -> validate(value, req, propertyName) && after.validate(value, req, propertyName);
}

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

/** Validation adapter that supports and uses the primitive type. */
/** Validation adapter that supports and uses the primitive types. */
interface Primitive {

/** Validate using primitive boolean. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,7 @@ <T> ValidationAdapter<T> annotationAdapter(

/**
* Build given type and annotations.
*
* @param groups
*/
// TODO understand that lookup chain stuff
@SuppressWarnings("unchecked")
<T> ValidationAdapter<T> buildAnnotation(
Class<? extends Annotation> cls,
Expand Down Expand Up @@ -155,7 +152,6 @@ public <T> T attribute(String key) {
public Request withValue(long value) {
Map<String, Object> newAttributes = new HashMap<>(attributes);
newAttributes.put("value", value);
//newAttributes.put("_type", "Long");
return new Request(ctx, annotationType, groups, newAttributes);
}

Expand Down