|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectandroid.databinding.CallbackRegistry<C,T,A>
C
- The callback type.T
- The notification sender type. Typically this is the containing class.A
- Opaque argument used to pass additional data beyond an int.public class CallbackRegistry<C,T,A>
A utility for storing and notifying callbacks. This class supports reentrant modification of the callbacks during notification without adversely disrupting notifications. A common pattern for callbacks is to receive a notification and then remove themselves. This class handles this behavior with constant memory under most circumstances.
A subclass of CallbackRegistry.NotifierCallback
must be passed to
the constructor to define how notifications should be called. That implementation
does the actual notification on the listener. It is typically a static instance
that can be reused for all similar CallbackRegistries.
This class supports only callbacks with at most three parameters.
Typically, these are the notification originator and a parameter, with another to
indicate which method to call, but these may be used as required. If more than
three parameters are required or primitive types other than the single int provided
must be used, A
should be some kind of containing structure that
the subclass may reuse between notifications.
Nested Class Summary | |
---|---|
static class |
CallbackRegistry.NotifierCallback<C,T,A>
Class used to notify events from CallbackRegistry. |
Constructor Summary | |
---|---|
CallbackRegistry(CallbackRegistry.NotifierCallback<C,T,A> notifier)
Creates an EventRegistry that notifies the event with notifier. |
Method Summary | |
---|---|
void |
add(C callback)
Add a callback to be notified. |
void |
clear()
Removes all callbacks from the list. |
CallbackRegistry<C,T,A> |
clone()
|
java.util.ArrayList<C> |
copyCallbacks()
Makes a copy of the registered callbacks and returns it. |
void |
copyCallbacks(java.util.List<C> callbacks)
Modifies callbacks to contain all callbacks in the CallbackRegistry. |
boolean |
isEmpty()
Returns true if there are no registered callbacks or false otherwise. |
void |
notifyCallbacks(T sender,
int arg,
A arg2)
Notify all callbacks. |
void |
remove(C callback)
Remove a callback. |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public CallbackRegistry(CallbackRegistry.NotifierCallback<C,T,A> notifier)
notifier
- The class to use to notify events.Method Detail |
---|
public void notifyCallbacks(T sender, int arg, A arg2)
sender
- The originator. This is an opaque parameter passed to
CallbackRegistry.NotifierCallback.onNotifyCallback(Object, Object, int, Object)
arg
- An opaque parameter passed to
CallbackRegistry.NotifierCallback.onNotifyCallback(Object, Object, int, Object)
arg2
- An opaque parameter passed to
CallbackRegistry.NotifierCallback.onNotifyCallback(Object, Object, int, Object)
public void add(C callback)
callback
- The callback to add.public void remove(C callback)
callback
- The callback to remove.public java.util.ArrayList<C> copyCallbacks()
public void copyCallbacks(java.util.List<C> callbacks)
callbacks
to contain all callbacks in the CallbackRegistry.
callbacks
- modified to contain all callbacks registered to receive events.public boolean isEmpty()
public void clear()
public CallbackRegistry<C,T,A> clone()
clone
in class java.lang.Object
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |