@Test public void shouldPublishGeneratedValuesToConsumersList() { Generator<Integer> generator = new BroadcastingGenerator<>(Generators.positiveInts, asList(firstConsumer, secondConsumer)); Integer integer = generator.next(); verify(firstConsumer).consume(integer); verify(secondConsumer).consume(integer); Integer integer2 = generator.next(); verify(firstConsumer).consume(integer2); verify(secondConsumer).consume(integer2); }
@Override public T next() { T generated = delegate.next(); for (Consumer<T> consumer : consumers) { consumer.consume(generated); } return generated; }
BroadcastingGenerator implements Generator<T> { @Override public T next() { T generated = delegate.next(); for (Consumer<T> consumer : consumers) { consumer.consume(generated); } return generated; } }
BroadcastingGenerator implements Generator<T> { @Override public T next() { T generated = delegate.next(); for (Consumer<T> consumer : consumers) { consumer.consume(generated); } return generated; } BroadcastingGenerator(@Nonnull Generator<T> delegate, List<Consumer<T>> consumers); @SafeVarargs  BroadcastingGenerator(@Nonnull Generator<T> delegate, @Nonnull Consumer<T> first, @Nonnull Consumer<T>... others); }
BroadcastingGenerator implements Generator<T> { @Override public T next() { T generated = delegate.next(); for (Consumer<T> consumer : consumers) { consumer.consume(generated); } return generated; } BroadcastingGenerator(@Nonnull Generator<T> delegate, List<Consumer<T>> consumers); @SafeVarargs  BroadcastingGenerator(@Nonnull Generator<T> delegate, @Nonnull Consumer<T> first, @Nonnull Consumer<T>... others); @Override T next(); }
BroadcastingGenerator implements Generator<T> { @Override public T next() { T generated = delegate.next(); for (Consumer<T> consumer : consumers) { consumer.consume(generated); } return generated; } BroadcastingGenerator(@Nonnull Generator<T> delegate, List<Consumer<T>> consumers); @SafeVarargs  BroadcastingGenerator(@Nonnull Generator<T> delegate, @Nonnull Consumer<T> first, @Nonnull Consumer<T>... others); @Override T next();  }