I would like to ask the opinion for experts out there. The following code snippet was written by a colleague of mine who is very fond of functional style in Java.
public Book findBookByIsbnOrId(String isbn, String id) {
return Optional.ofNullable(isbn).map(i -> {
return bookDao.findByIsbn(i);
})
.orElseGet(() -> {
return bookDao.findById(id);
});
}
This code has been modified to be used at Stack Exchange. Essentially, finding the book has preference (ISBN) which when not present should be search via (ID).
I would argue that this code although functionally fulfils the given requirement is less readable than
if (StringUtils.isNotBlank(isbn)) {
return bookDao.findByIsbn(isbn);
} else {
return bookDao.findById(id);
}
I would like to ask the opinion of others whether they think this is just over-engineering?