I have a predicate which accepts Optional<LocalDateTime>
and I want to check if it is present and the LocalDateTime
is before current date.
I can write it with if statements which would look like this:
@Override
public boolean test(Optional<ResetPassword> resetPassword) {
if (resetPassword.isPresent()) {
if (!resetPassword.get().getValidUntil().isBefore(LocalDateTime.now())) {
throw new CustomException("Incorrect date");
}
return true;
}
return false;
}
How could I rewrite this using the Optional.map
and Optional.filter
functions?