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

com.parzivail.util.generics.SingleConsumerEventBus Maven / Gradle / Ivy

package com.parzivail.util.generics;

import java.util.HashMap;
import java.util.function.Consumer;

public class SingleConsumerEventBus
{
	private final HashMap EVENT_HANDLERS = new HashMap<>();

	public void subscribe(TE event, TC handler)
	{
		EVENT_HANDLERS.put(event, handler);
	}

	public void unsubscribe(TE event)
	{
		EVENT_HANDLERS.remove(event);
	}

	public void publish(TE event, Consumer contextConsumer)
	{
		var subscriber = EVENT_HANDLERS.get(event);
		if (subscriber == null)
			return;

		contextConsumer.accept(subscriber);
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy