mvallim / java-fluent-validator

Java Fluent Validator is inspired by Fluent Interface and .Net FluentValidation which defined an inner-DSL within Java language for programmers to use. A fluent interface implies that its primary goal is to make it easy to SPEAK and UNDERSTAND.
https://mvallim.github.io/java-fluent-validator/
Apache License 2.0
160 stars 17 forks source link

Suggestion: between() should be inclusive of min, max #49

Closed bakatz closed 4 years ago

bakatz commented 5 years ago

I believe the most user-friendly implementation would be (below is Kotlin code, may not convert entirely cleanly to java):

fun <E, T : Comparable<E>?> betweenInclusive(min: E, max: E): Predicate<T>? =
    PredicateBuilder.from<T>(LogicalPredicate.not(ObjectPredicate.nullValue()))
            .and(ComparablePredicate.lessThanOrEqual(max).and(ComparablePredicate.greaterThanOrEqual(min)))

Which relies on *OrEqual functions.

Otherwise this can be implemented as a separate method from between, or as a parameter (Boolean inclusive)

mvallim commented 5 years ago

Hi Ben

Thanks for the suggestion, I added this new predicate betweenInclusive.

https://github.com/mvallim/java-fluent-validator/blob/dcc399d19364117d853ded8099b1d69d9ee1d427/src/main/java/br/com/fluentvalidator/predicate/ComparablePredicate.java#L49-L51

https://github.com/mvallim/java-fluent-validator/blob/dcc399d19364117d853ded8099b1d69d9ee1d427/src/main/java/br/com/fluentvalidator/predicate/ComparablePredicate.java#L62-L64

In the next release will be available.

Regards,

bakatz commented 5 years ago

Amazing, thanks for the quick response.

mvallim commented 4 years ago

Thanks @bakatz.

Available in release 1.7.6

https://github.com/mvallim/java-fluent-validator/blob/master/documentation/6-predicate-methods.md#64-comparable