mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-05-14 10:58:42 +00:00
refactoring: Improve monad methods (#2300)
This commit is contained in:
@@ -78,7 +78,7 @@ public class Validator<T> {
|
||||
* @param message error message when object is invalid
|
||||
* @return this
|
||||
*/
|
||||
public Validator<T> validate(Predicate<T> validation, String message) {
|
||||
public Validator<T> validate(Predicate<? super T> validation, String message) {
|
||||
if (!validation.test(obj)) {
|
||||
exceptions.add(new IllegalStateException(message));
|
||||
}
|
||||
@@ -97,8 +97,8 @@ public class Validator<T> {
|
||||
* @return this
|
||||
*/
|
||||
public <U> Validator<T> validate(
|
||||
Function<T, U> projection,
|
||||
Predicate<U> validation,
|
||||
Function<? super T, ? extends U> projection,
|
||||
Predicate<? super U> validation,
|
||||
String message
|
||||
) {
|
||||
return validate(projection.andThen(validation::test)::apply, message);
|
||||
|
||||
Reference in New Issue
Block a user