org.deduced
Class ListenTargetTracker<K,V>

java.lang.Object
  extended by org.deduced.ListenTargetTracker<K,V>
Type Parameters:
K - key of the listener
V - value of the listener

public class ListenTargetTracker<K,V>
extends java.lang.Object

Listen Target Tracker allows a listener to listen to multiple property collections multiple times.

Author:
Steve McDuff

Field Summary
private  PropertyListener<K,V> listener
          listener
private  java.util.Map<PropertyCollection<? extends K,? extends V>,java.lang.Integer> listenTargetMap
          map of all the targets to listen to and the number of times we hooked a listener on them
 
Constructor Summary
ListenTargetTracker(PropertyListener<K,V> setListener)
          ListenTargetTracker Constructor
 
Method Summary
 void add(PropertyCollection<? extends K,? extends V> target)
          add a collection to listen to
 void clear()
          clear will remove the listener to all the collections that are tracked.
 PropertyListener<K,V> getListener()
          get Listener
 boolean isListeningTo(PropertyCollection<? extends K,? extends V> target)
          test if this tracker is listening to a target
 boolean remove(PropertyCollection<? extends K,? extends V> target)
          remove a collection that we don't want to listen to anymore.
 boolean removeAll(PropertyCollection<? extends K,? extends V> target)
          remove a collection that we don't want to listen to anymore.
private  void removeListener(PropertyCollection<? extends K,? extends V> target)
          remove a listener
 void setListener(PropertyListener<K,V> setListener)
          set Listener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

listener

private PropertyListener<K,V> listener
listener


listenTargetMap

private java.util.Map<PropertyCollection<? extends K,? extends V>,java.lang.Integer> listenTargetMap
map of all the targets to listen to and the number of times we hooked a listener on them

Constructor Detail

ListenTargetTracker

public ListenTargetTracker(PropertyListener<K,V> setListener)
ListenTargetTracker Constructor

Parameters:
setListener - the listener to use
Method Detail

setListener

public void setListener(PropertyListener<K,V> setListener)
set Listener

Parameters:
setListener - the new listener

add

public void add(PropertyCollection<? extends K,? extends V> target)
add a collection to listen to

Parameters:
target - a collection to listen to

removeAll

public boolean removeAll(PropertyCollection<? extends K,? extends V> target)
remove a collection that we don't want to listen to anymore.

Parameters:
target - a collection that we don't want to listen to anymore.
Returns:
true if the remove was successful.

removeListener

private void removeListener(PropertyCollection<? extends K,? extends V> target)
remove a listener

Parameters:
target - the listener to remove

getListener

public PropertyListener<K,V> getListener()
get Listener

Returns:
the listener

isListeningTo

public boolean isListeningTo(PropertyCollection<? extends K,? extends V> target)
test if this tracker is listening to a target

Parameters:
target - the target to verify
Returns:
true if the tracker is listening to the target

remove

public boolean remove(PropertyCollection<? extends K,? extends V> target)
remove a collection that we don't want to listen to anymore. The listener will be disconnected from this collection only when the number of times we listen to the target goes to zero.

Parameters:
target - a collection that we don't want to listen to anymore.
Returns:
true if the remove was successful. It doesn't necessarily mean that the listener was removed from the target if there was more than 1 times we were listening to it.

clear

public void clear()
clear will remove the listener to all the collections that are tracked.