Calling contains on a list for an optional value in Java?

Viewed 3477

In Java 8,

I currently have a lambda that looks like this:

.createSomething((acceptableStates, someProxy) -> (userId) ->   
    acceptableStates.contains(someProxy.getSomeAttributeId(userId)))

However, we have changed someProxy.getSomeAttributeId to return an Optional<String> instead of a string.

What's the cleanest / most accepted way to essentially check for if acceptableStates contains the value of someProxy.getSomeAttributeId(userId) if the attribute returned isn't empty?

(Note: acceptableStates is still a list of strings, not of Optional<String>)

4 Answers
return value.isPresent() && value.get().contains("some-text");
Related