com.viber.bot.event.EventEmitter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of viber-bot Show documentation
Show all versions of viber-bot Show documentation
Use this library to communicate with the Viber API to develop a bot for https://developers.viber.com/.
package com.viber.bot.event;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Lists;
import com.google.common.collect.Multimap;
import javax.annotation.Nonnull;
import java.util.Collection;
import java.util.concurrent.Future;
import static com.google.common.base.Preconditions.checkNotNull;
public class EventEmitter {
private final Multimap listeners = ArrayListMultimap.create();
public void on(final @Nonnull Event event, final @Nonnull EmittableEvent listener) {
listeners.put(checkNotNull(event), checkNotNull(listener));
}
public Collection> emit(final @Nonnull Event event, final Object... args) {
final Collection> futures = Lists.newArrayList();
listeners.get(event).forEach(listener -> futures.add(listener.emit(args)));
return futures;
}
public interface EmittableEvent {
Future emit(Object... args);
}
}