package jrummikub.util;

import java.util.HashSet;
/**
 * Mock class for Events
 */
public class MockEvent implements IEvent {
	/** */
	public HashSet<IListener> listeners = new HashSet<IListener>();

	@Override
	public Connection add(final IListener listener) {
		listeners.add(listener);
	    return new Connection() {
			
			@Override
			public void remove() {
				MockEvent.this.remove(listener);
			}
		};
	}

	@Override
	public void remove(IListener listener) {
		listeners.remove(listener);
	}
	
	/** */
	public void emit() {
		for (IListener listener : listeners) {
			listener.handle();
		}
	}
}
