@@ -0,0 +1,1988 @@
+package com.github.radium.maven;%0A%0Aimport java.lang.reflect.InvocationTargetException;%0Aimport java.lang.reflect.Method;%0Aimport java.util.Arrays;%0Aimport java.util.Set;%0A%0Aimport org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;%0A%0Aimport com.google.common.base.Function;%0Aimport com.google.common.collect.Lists;%0Aimport com.google.common.collect.Sets;%0A%0Apublic class ListenerList%3CT%3E %7B%0A%09%0A%09final private static Logger LOGGER = LoggerFactory.getLogger(ListenerList.class);%0A%09%0A%09private Set%3CT%3E listeners = Sets.newHashSet();%0A%09private Class%3CT%3E listenerClass;%0A%09%0A%09private ListenerList(Class%3CT%3E listenerClass) %7B%0A%09%09super();%0A%09%09%0A%09%09this.listenerClass = listenerClass;%0A%09%7D%0A%09%0A%09public static %3CT%3E ListenerList%3CT%3E of(Class%3CT%3E listenerClass) %7B%0A%09%09return new ListenerList%3CT%3E(listenerClass);%0A%09%7D%0A%09%0A%09public boolean add(T listener) %7B%0A%09%09return listeners.add(listener);%0A%09%7D%0A%09%0A%09public boolean remove(T listener) %7B%0A%09%09return listeners.remove(listener);%0A%09%7D%0A%09%0A%09public boolean contains(T listener) %7B%0A%09%09return listeners.contains(listener);%0A%09%7D%0A%09%0A%09public void fire(String methodName, Object... parameters) %7B%0A%09%09for (T listener : listeners) %7B%0A%09%09%09try %7B%0A%09%09%09%09Class%3C?%3E%5B%5D parameterTypes = Lists.transform(Arrays.asList(parameters), new Function%3CObject, Class%3C?%3E%3E() %7B%0A%0A%09%09%09%09%09@Override%0A%09%09%09%09%09public Class%3C?%3E apply(Object parameter) %7B%0A%09%09%09%09%09%09Class%3C?%3E type = parameter.getClass();%0A%09%09%09%09%09%09return type;%0A%09%09%09%09%09%7D%0A%09%09%09%09%09%0A%09%09%09%09%7D).toArray(new Class%3C?%3E%5B0%5D);%0A%09%09%09%09Method method = listenerClass.getMethod(methodName, parameterTypes);%0A%09%09%09%09method.invoke(listener, parameters);%0A%09%09%09%7D catch (IllegalAccessException e) %7B%0A%09%09%09%09LOGGER.warn(%22Unable to invoke %7B%7D%22, methodName, e);%0A%09%09%09%7D catch (SecurityException e) %7B%0A%09%09%09%09LOGGER.warn(%22Unable to invoke %7B%7D%22, methodName, e);%0A%09%09%09%7D catch (NoSuchMethodException e) %7B%0A%09%09%09%09LOGGER.warn(%22Unable to invoke %7B%7D%22, methodName, e);%0A%09%09%09%7D catch (IllegalArgumentException e) %7B%0A%09%09%09%09LOGGER.warn(%22Unable to invoke %7B%7D%22, methodName, e);%0A%09%09%09%7D catch (InvocationTargetException e) %7B%0A%09%09%09%09LOGGER.warn(%22Unable to invoke %7B%7D%22, methodName, e);%0A%09%09%09%7D%0A%09%09%7D%0A%09%7D%0A%09%0A%7D%0A

Create ListenerList.java