summaryrefslogtreecommitdiffstats
path: root/mock/jrummikub/util/MockEvent2.java
blob: 5c25ca4625e93b4e21554410e670a6d20a262759 (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
36
37
38
39
40
41
42
43
44
45
46
package jrummikub.util;

import java.util.HashSet;

/**
 * Mock class for Event2s
 * 
 * @param <T1>
 *          first event type
 * @param <T2>
 *          second event type
 */
public class MockEvent2<T1, T2> implements IEvent2<T1, T2> {
	/** */
	public HashSet<IListener2<T1, T2>> listeners = new HashSet<IListener2<T1, T2>>();

	@Override
	public Connection add(final IListener2<T1, T2> listener) {
		listeners.add(listener);
		return new Connection() {

			@Override
			public void remove() {
				MockEvent2.this.remove(listener);
			}
		};
	}

	@Override
	public void remove(IListener2<T1, T2> listener) {
		listeners.remove(listener);
	}

	/**
	 * @param value1
	 *          the first event parameter
	 * @param value2
	 *          the second event parameter
	 */
	public void emit(T1 value1, T2 value2) {
		for (IListener2<T1, T2> listener : new HashSet<IListener2<T1, T2>>(
				listeners)) {
			listener.handle(value1, value2);
		}
	}
}