summaryrefslogtreecommitdiffstats
path: root/mock/jrummikub/util/MockEvent.java
blob: 169e1e735ab62168d78d3baeae75d7d02afaeb31 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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 : new HashSet<IListener>(listeners)) {
			listener.handle();
		}
	}
}