@Override
  public Iterator<T> iterator() {
    if (m_listeners == null) {
      return Collections.emptyIterator();
    }

    final ArrayList<WeakReference<T>> listenersCopy;

    synchronized (m_listeners) {
      listenersCopy = new ArrayList<WeakReference<T>>(m_listeners);
    }

    final ArrayList<T> listeners = new ArrayList<T>();

    for (final WeakReference<T> weakT : listenersCopy) {
      final T element = weakT.get();

      if (element != null) {
        listeners.add(element);
      }
    }

    return listeners.iterator();
  }
Adds a listener to the listener provider.

@param listener The listener to add.
@throws NullPointerException Thrown if the listener object is null.
@throws IllegalStateException Thrown if the listener is already managed by the listener
    provider.
java/zylib/src/main/java/com/google/security/zynamics/zylib/general/ListenerProvider.java