Facebook Embed

14 August 2016

Java 8 Streams

This code is certainly more terse from using Java 8 streams but is it more readable than it would be otherwise?
public synchronized void unregister(AsciiString uri, ChannelHandler handler) {
  Optional
      .ofNullable(_handlerMap.get(uri))
      .flatMap(l -> Optional.ofNullable(
          l.stream().filter(p -> p.second == handler)
           .filter(l::remove).findAny().isPresent() ? l : null))
      .filter(List::isEmpty)
      .ifPresent(l -> _handlerMap.remove(uri, l));}

No comments: