summaryrefslogtreecommitdiffstats
path: root/src/jrummikub/util/Event2.java
blob: 764004f716626a2c08cabd008710633900cf24ed (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
package jrummikub.util;

import java.util.HashSet;

/**
 * Simple single parameter event generator
 * 
 * @param <T1>
 *            type of the first event parameter
 * @param <T2>
 *            type of the second event parameter
 */
public class Event2<T1, T2> implements IEvent2<T1, T2> {
	private HashSet<IListener2<T1, T2>> listeners = new HashSet<IListener2<T1, T2>>();

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

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

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