@Test public void testRegisterConsumer() { EventProcessor<Number> eventProcessor = new EventProcessor<>(); EventConsumer<Integer> eventConsumer = event -> logger.info(event.toString()); eventProcessor.registerConsumer(Integer.class.getSimpleName(), eventConsumer); eventProcessor.registerConsumer(Integer.class.getSimpleName(), eventConsumer); assertThat(eventProcessor.eventConsumerMap).hasSize(1); assertThat(eventProcessor.eventConsumerMap.get(Integer.class.getSimpleName())).hasSize(2); boolean consumed = eventProcessor.processEvent(1); then(logger).should(times(2)).info("1"); assertThat(consumed).isEqualTo(true); }
@SuppressWarnings("unchecked") public synchronized void registerConsumer(String className, EventConsumer<? extends T> eventConsumer) { this.eventConsumerMap.compute(className, (k, consumers) -> { if (consumers == null) { consumers = new CopyOnWriteArrayList<>(); consumers.add((EventConsumer<T>) eventConsumer); return consumers; } else { consumers.add((EventConsumer<T>) eventConsumer); return consumers; } }); this.consumerRegistered = true; }
EventProcessor implements EventPublisher<T> { @SuppressWarnings("unchecked") public synchronized void registerConsumer(String className, EventConsumer<? extends T> eventConsumer) { this.eventConsumerMap.compute(className, (k, consumers) -> { if (consumers == null) { consumers = new CopyOnWriteArrayList<>(); consumers.add((EventConsumer<T>) eventConsumer); return consumers; } else { consumers.add((EventConsumer<T>) eventConsumer); return consumers; } }); this.consumerRegistered = true; } }
EventProcessor implements EventPublisher<T> { @SuppressWarnings("unchecked") public synchronized void registerConsumer(String className, EventConsumer<? extends T> eventConsumer) { this.eventConsumerMap.compute(className, (k, consumers) -> { if (consumers == null) { consumers = new CopyOnWriteArrayList<>(); consumers.add((EventConsumer<T>) eventConsumer); return consumers; } else { consumers.add((EventConsumer<T>) eventConsumer); return consumers; } }); this.consumerRegistered = true; }  }
EventProcessor implements EventPublisher<T> { @SuppressWarnings("unchecked") public synchronized void registerConsumer(String className, EventConsumer<? extends T> eventConsumer) { this.eventConsumerMap.compute(className, (k, consumers) -> { if (consumers == null) { consumers = new CopyOnWriteArrayList<>(); consumers.add((EventConsumer<T>) eventConsumer); return consumers; } else { consumers.add((EventConsumer<T>) eventConsumer); return consumers; } }); this.consumerRegistered = true; }  boolean hasConsumers(); @SuppressWarnings("unchecked") synchronized void registerConsumer(String className,
        EventConsumer<? extends T> eventConsumer); boolean processEvent(E event); @Override synchronized void onEvent(@Nullable EventConsumer<T> onEventConsumer); }
EventProcessor implements EventPublisher<T> { @SuppressWarnings("unchecked") public synchronized void registerConsumer(String className, EventConsumer<? extends T> eventConsumer) { this.eventConsumerMap.compute(className, (k, consumers) -> { if (consumers == null) { consumers = new CopyOnWriteArrayList<>(); consumers.add((EventConsumer<T>) eventConsumer); return consumers; } else { consumers.add((EventConsumer<T>) eventConsumer); return consumers; } }); this.consumerRegistered = true; }  boolean hasConsumers(); @SuppressWarnings("unchecked") synchronized void registerConsumer(String className,
        EventConsumer<? extends T> eventConsumer); boolean processEvent(E event); @Override synchronized void onEvent(@Nullable EventConsumer<T> onEventConsumer);  }