
org.vudroid.core.events.SafeEvent Maven / Gradle / Ivy
package org.vudroid.core.events;
import java.lang.reflect.Method;
public abstract class SafeEvent implements Event
{
private final Class> listenerType;
protected SafeEvent()
{
listenerType = getListenerType();
}
private Class> getListenerType()
{
for (Method method : getClass().getMethods())
{
if ("dispatchSafely".equals(method.getName()) && !method.isSynthetic())
{
return method.getParameterTypes()[0];
}
}
throw new RuntimeException("Couldn't find dispatchSafely method");
}
@SuppressWarnings({"unchecked"})
public final void dispatchOn(Object listener)
{
if (listenerType.isAssignableFrom(listener.getClass()))
{
dispatchSafely((T) listener);
}
}
public abstract void dispatchSafely(T listener);
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy