package ru.kirillius.cooler.controller.EventSystem;

import java.util.Queue;
import java.util.concurrent.LinkedBlockingQueue;

public class EventHandler<T extends EventListener<D>, D> {
    private final Queue<T> listeners = new LinkedBlockingQueue<>();

    public void addListener(T listener) {
        if (listener == null) return;
        listeners.add(listener);
    }

    public void removeListener(T listener) {
        if (listener == null) return;
        listeners.remove(listener);
    }

    public void removeAllListeners() {
        listeners.clear();
    }

    public void invoke(D data) {
        for (T listener : listeners) {
            listener.invoke(data);
        }
    }
}
