I'm a relatively novice Stream user and I feel like there should be a cleaner way to accomplish what I have below. Is it possible to accomplish what the code below does all within a single Stream (eliminating the if/else at the bottom)?
Thanks!
Optional<SomeMapping> mapping = allMappings.stream()
.filter(m -> category.toUpperCase().trim().equalsIgnoreCase(m.getCategory().toUpperCase().trim()))
.findAny();
if (mapping.isPresent()) {
return mapping.get();
} else {
throw new SomeException("No mapping found for category \"" + category + "\.");
}