Created
October 24, 2018 13:30
-
-
Save kirillsulim/b7802a709cea1648ffd303474ea0acbd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static <T> Validator<T extends Comparable<T>> positiveValidator(T zeroValue) { | |
return value -> { | |
if (zeroValue.compareTo(value) < 0) { | |
return Optional.empty() | |
} | |
else { | |
rerurn Optional.of(String.format("Value must be positive but was '%s'", value)); | |
}; | |
} | |
public static Validator<Integer> positiveValidator() { | |
return positiveValidator(0); | |
} | |
public static Validator<Long> positiveValidator() { | |
return positiveValidator(0L); | |
} | |
// VS | |
public static Validator<Long> positive() { | |
return value -> { | |
if (value > 0) { | |
return Optional.empty(); | |
} | |
return Optional.of("Value should be positive but was " + value); | |
}; | |
} | |
public static Validator<Integer> positive() { | |
return value -> { | |
if (value > 0) { | |
return Optional.empty(); | |
} | |
return Optional.of("Value should be positive but was " + value); | |
}; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment