All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.viber.bot.event.EventEmitter Maven / Gradle / Ivy

Go to download

Use this library to communicate with the Viber API to develop a bot for https://developers.viber.com/.

The newest version!
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);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy