Package org.apache.commons.net.util
Class ListenerList<T extends java.util.EventListener>
- java.lang.Object
-
- org.apache.commons.net.util.ListenerList<T>
-
- Type Parameters:
T- the type of elements tracked by this list.
- All Implemented Interfaces:
java.io.Serializable,java.lang.Iterable<T>
public class ListenerList<T extends java.util.EventListener> extends java.lang.Object implements java.io.Serializable, java.lang.Iterable<T>A list of event listeners.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.concurrent.CopyOnWriteArrayList<T>listenersThe thread-safe list of listeners.private static longserialVersionUID
-
Constructor Summary
Constructors Constructor Description ListenerList()Constructs a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddListener(T listener)Adds the given listener to the end of this list.intgetListenerCount()Gets the number of elements in this list.booleanisEmpty()Tests whether if this listener list is empty.java.util.Iterator<T>iterator()Return anIteratorfor theEventListenerinstances.private voidreadObject(java.io.ObjectInputStream ignored)Throws UnsupportedOperationException.voidremoveListener(T listener)Removes the first occurrence of the specified listener from this list, if it is present.private voidwriteObject(java.io.ObjectOutputStream ignored)Always throwsUnsupportedOperationException.
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
listeners
private final java.util.concurrent.CopyOnWriteArrayList<T extends java.util.EventListener> listeners
The thread-safe list of listeners.
-
-
Method Detail
-
addListener
public void addListener(T listener)
Adds the given listener to the end of this list.- Parameters:
listener- A listener.
-
getListenerCount
public int getListenerCount()
Gets the number of elements in this list.- Returns:
- the number of elements in this list
-
isEmpty
public boolean isEmpty()
Tests whether if this listener list is empty.- Returns:
- whether if this listener list is empty.
- Since:
- 3.12.0
-
iterator
public java.util.Iterator<T> iterator()
Return anIteratorfor theEventListenerinstances.- Specified by:
iteratorin interfacejava.lang.Iterable<T extends java.util.EventListener>- Returns:
- an
Iteratorfor theEventListenerinstances - Since:
- 2.0 TODO Check that this is a good defensive strategy
-
readObject
private void readObject(java.io.ObjectInputStream ignored)
Throws UnsupportedOperationException.- Parameters:
ignored- Ignore.
-
removeListener
public void removeListener(T listener)
Removes the first occurrence of the specified listener from this list, if it is present.- Parameters:
listener- listener to be removed from this list, if present.
-
writeObject
private void writeObject(java.io.ObjectOutputStream ignored)
Always throwsUnsupportedOperationException.- Parameters:
ignored- ignored.- Throws:
java.lang.UnsupportedOperationException- Always thrown.
-
-