de.fhg.igd.util
Class Notifier

java.lang.Object
  extended by de.fhg.igd.util.Notifier

public class Notifier
extends Object

Acts on trigger objects such as events or messages. The strategy is to index listeners according to the objects they want to be triggered by. For each trigger object an entry in the hashtable index is made which serves as the key for the set of listeners wanting to be notified when this trigger object is detected by the notifier.

Version:
"$Id"
Author:
Volker Roth
See Also:
Listener

Field Summary
static int DEFAULT_CAPACITY
           
static float DEFAULT_LOADFACTOR
           
protected  HashMap index_
          For efficient notification this instance keeps a hashtable which uses the trigger objects as keys.
 
Constructor Summary
Notifier()
          The default constructor creates a simple instance of this class.
Notifier(int capacity, float loadfactor)
          Creates a notifier instance with the given default parameters which are passed to the HashMap which backs this class.
 
Method Summary
 void addListener(Listener listener, Object trigger)
          Adds a listener to the list of listener.
 void addListener(Listener listener, Object[] trigger)
          Adds an listener to the list of listeners.
 int countListeners()
          Returns the number of listener.
 void deleteListener(Listener listener)
          Removes the given listener from the list of listeners.
 void deleteListeners()
          Deletes the listeners.
 void notifyListeners(Object o)
          Notifies those listeners which requested to be triggered by the given object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_CAPACITY

public static final int DEFAULT_CAPACITY
See Also:
Constant Field Values

DEFAULT_LOADFACTOR

public static final float DEFAULT_LOADFACTOR
See Also:
Constant Field Values

index_

protected HashMap index_
For efficient notification this instance keeps a hashtable which uses the trigger objects as keys.

Constructor Detail

Notifier

public Notifier()
The default constructor creates a simple instance of this class.


Notifier

public Notifier(int capacity,
                float loadfactor)
         throws IllegalArgumentException
Creates a notifier instance with the given default parameters which are passed to the HashMap which backs this class.

Parameters:
capacity - The initial capacity of the HashMap.
loadfactor - The initial loadfactor of the HashMap.
Throws:
IllegalArgumentException - if a parameter is wrong.
Method Detail

addListener

public void addListener(Listener listener,
                        Object trigger)
Adds a listener to the list of listener. This listener will be notified if the trigger object is sent to this notifier.

Parameters:
listener - The listener to add.
trigger - The object which triggers the notification of the listener.

addListener

public void addListener(Listener listener,
                        Object[] trigger)
Adds an listener to the list of listeners. This listener will be notified if one of the trigger objects is sent to this notifier.

Parameters:
listener - The listener to add.
trigger - The objects which trigger the notification of the listener.

deleteListener

public void deleteListener(Listener listener)
Removes the given listener from the list of listeners. If the set of listeners for a trigger key becomes empty the mapping is removed also.

Parameters:
listener - The listener which should be removed.

notifyListeners

public void notifyListeners(Object o)
Notifies those listeners which requested to be triggered by the given object. Comparison is based on the object's equals method. Subclasses may implement other strategies such as testing for implication of trigger objects by the given one.

Parameters:
o - The object which is triggered.

deleteListeners

public void deleteListeners()
Deletes the listeners. The index is cleared of all subsets which store the listeners indexed by the trigger objects.


countListeners

public int countListeners()
Returns the number of listener. Iterates through all the sets and creates the unified set of which the size is returned.

Returns:
The number of listeners.


Copyright © Fraunhofer Gesellschaft. All Rights Reserved.