@Test void addListenerShouldReturnFirstListenerWhenNoPreviouslyRegisteredListeners() { MailboxListener listener = event -> { }; assertThat(testee.addListener(KEY_1, listener).isFirstListener()).isTrue(); }
LocalRegistration addListener(RegistrationKey registrationKey, MailboxListener.ReactiveMailboxListener listener) { AtomicBoolean firstListener = new AtomicBoolean(false); listenersByKey.compute(registrationKey, (key, listeners) -> Optional.ofNullable(listeners) .map(set -> ImmutableSet.<MailboxListener.ReactiveMailboxListener>builder().addAll(set).add(listener).build()) .orElseGet(() -> { firstListener.set(true); return ImmutableSet.of(listener); }) ); return new LocalRegistration(firstListener.get(), () -> removeListener(registrationKey, listener)); }
LocalListenerRegistry { LocalRegistration addListener(RegistrationKey registrationKey, MailboxListener.ReactiveMailboxListener listener) { AtomicBoolean firstListener = new AtomicBoolean(false); listenersByKey.compute(registrationKey, (key, listeners) -> Optional.ofNullable(listeners) .map(set -> ImmutableSet.<MailboxListener.ReactiveMailboxListener>builder().addAll(set).add(listener).build()) .orElseGet(() -> { firstListener.set(true); return ImmutableSet.of(listener); }) ); return new LocalRegistration(firstListener.get(), () -> removeListener(registrationKey, listener)); } }
LocalListenerRegistry { LocalRegistration addListener(RegistrationKey registrationKey, MailboxListener.ReactiveMailboxListener listener) { AtomicBoolean firstListener = new AtomicBoolean(false); listenersByKey.compute(registrationKey, (key, listeners) -> Optional.ofNullable(listeners) .map(set -> ImmutableSet.<MailboxListener.ReactiveMailboxListener>builder().addAll(set).add(listener).build()) .orElseGet(() -> { firstListener.set(true); return ImmutableSet.of(listener); }) ); return new LocalRegistration(firstListener.get(), () -> removeListener(registrationKey, listener)); } LocalListenerRegistry(); }
LocalListenerRegistry { LocalRegistration addListener(RegistrationKey registrationKey, MailboxListener.ReactiveMailboxListener listener) { AtomicBoolean firstListener = new AtomicBoolean(false); listenersByKey.compute(registrationKey, (key, listeners) -> Optional.ofNullable(listeners) .map(set -> ImmutableSet.<MailboxListener.ReactiveMailboxListener>builder().addAll(set).add(listener).build()) .orElseGet(() -> { firstListener.set(true); return ImmutableSet.of(listener); }) ); return new LocalRegistration(firstListener.get(), () -> removeListener(registrationKey, listener)); } LocalListenerRegistry();  }
LocalListenerRegistry { LocalRegistration addListener(RegistrationKey registrationKey, MailboxListener.ReactiveMailboxListener listener) { AtomicBoolean firstListener = new AtomicBoolean(false); listenersByKey.compute(registrationKey, (key, listeners) -> Optional.ofNullable(listeners) .map(set -> ImmutableSet.<MailboxListener.ReactiveMailboxListener>builder().addAll(set).add(listener).build()) .orElseGet(() -> { firstListener.set(true); return ImmutableSet.of(listener); }) ); return new LocalRegistration(firstListener.get(), () -> removeListener(registrationKey, listener)); } LocalListenerRegistry();   }