textbender.g.util
Class CollectionRelayer<E>

java.lang.Object
  extended by CollectionRelayer<E>
All Implemented Interfaces:
EventListener, CollectionListener<E>
Direct Known Subclasses:
CollectionRelayerLL

@ThreadSafe
public class CollectionRelayer<E>
extends Object
implements CollectionListener<E>

Relayer of collection events to listeners. Thread-safe if the provided collection of listeners, and the listeners themselves are thread-safe.


Nested Class Summary
 
Nested classes/interfaces inherited from interface CollectionListener
CollectionListener.Registry<E>
 
Constructor Summary
CollectionRelayer(Collection<CollectionListener<E>> listeners)
          Creates a CollectionRelayer.
 
Method Summary
 void elementAdded(CollectionEvent.ElementAdded<E> e)
          Relays the event to the listeners.
 void elementRemoved(CollectionEvent.ElementRemoved<E> e)
          Relays the event to the listeners.
protected  Collection<CollectionListener<E>> listenersCopy()
          Returns a copy of the listener collection.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CollectionRelayer

public CollectionRelayer(Collection<CollectionListener<E>> listeners)
Creates a CollectionRelayer.

Parameters:
listeners - to whom events are relayed
Method Detail

elementAdded

public final void elementAdded(CollectionEvent.ElementAdded<E> e)
Relays the event to the listeners.

Specified by:
elementAdded in interface CollectionListener<E>

elementRemoved

public final void elementRemoved(CollectionEvent.ElementRemoved<E> e)
Relays the event to the listeners.

Specified by:
elementRemoved in interface CollectionListener<E>

listenersCopy

protected Collection<CollectionListener<E>> listenersCopy()
Returns a copy of the listener collection. A copy is used to guard against collection modification during relay, e.g. by the listeners themselves, which would cause relay iteration to fail.