Skip to content
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

Add @Nullable to methods in ValueValidator #371

Merged
merged 1 commit into from
Apr 1, 2024
Merged
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
19 changes: 11 additions & 8 deletions src/main/java/am/ik/yavi/core/ValueValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,16 @@
import java.util.function.Supplier;

import am.ik.yavi.fn.Validation;
import am.ik.yavi.jsr305.Nullable;

/**
* @since 0.8.0
*/
@FunctionalInterface
public interface ValueValidator<T, X> {

Validated<X> validate(T t, Locale locale, ConstraintContext constraintContext);
Validated<X> validate(@Nullable T t, Locale locale,
ConstraintContext constraintContext);

/**
* Return {@link ValueValidator} instance that always successes without validation.
Expand Down Expand Up @@ -65,33 +67,34 @@ default <A> ValueValidator<A, X> compose(Function<? super A, ? extends T> mapper
.validate(mapper.apply(a), locale, constraintContext);
}

default Validated<X> validate(T t) {
default Validated<X> validate(@Nullable T t) {
return this.validate(t, Locale.getDefault(), ConstraintGroup.DEFAULT);
}

default Validated<X> validate(T t, ConstraintContext constraintContext) {
default Validated<X> validate(@Nullable T t, ConstraintContext constraintContext) {
return this.validate(t, Locale.getDefault(), constraintContext);
}

default Validated<X> validate(T t, Locale locale) {
default Validated<X> validate(@Nullable T t, Locale locale) {
return this.validate(t, locale, ConstraintGroup.DEFAULT);
}

default X validated(T t) throws ConstraintViolationsException {
default X validated(@Nullable T t) throws ConstraintViolationsException {
return this.validate(t).orElseThrow(ConstraintViolationsException::new);
}

default X validated(T t, ConstraintContext constraintContext)
default X validated(@Nullable T t, ConstraintContext constraintContext)
throws ConstraintViolationsException {
return this.validate(t, constraintContext)
.orElseThrow(ConstraintViolationsException::new);
}

default X validated(T t, Locale locale) throws ConstraintViolationsException {
default X validated(@Nullable T t, Locale locale)
throws ConstraintViolationsException {
return this.validate(t, locale).orElseThrow(ConstraintViolationsException::new);
}

default X validated(T t, Locale locale, ConstraintContext constraintContext)
default X validated(@Nullable T t, Locale locale, ConstraintContext constraintContext)
throws ConstraintViolationsException {
return this.validate(t, locale, constraintContext)
.orElseThrow(ConstraintViolationsException::new);
Expand Down
Loading