This repository has been archived on 2025-03-02. You can view files and clone it, but cannot push or open issues or pull requests.
JRummikub/mock/jrummikub/util/MockEvent1.java

41 lines
703 B
Java
Raw Normal View History

package jrummikub.util;
import java.util.HashSet;
/**
* Mock class for Event1s
*
* @param <T>
* event type
*/
public class MockEvent1<T> implements IEvent1<T> {
/** */
public HashSet<IListener1<T>> listeners = new HashSet<IListener1<T>>();
@Override
public Connection add(final IListener1<T> listener) {
listeners.add(listener);
return new Connection() {
@Override
public void remove() {
MockEvent1.this.remove(listener);
}
};
}
@Override
public void remove(IListener1<T> listener) {
listeners.remove(listener);
}
/**
* @param value
*/
public void emit(T value) {
for (IListener1<T> listener : listeners) {
listener.handle(value);
}
}
}