FileDocCategorySizeDatePackage
Observable.javaAPI DocAndroid 1.5 API2676Wed May 06 22:41:54 BST 2009android.database

Observable

public abstract class Observable extends Object
Provides methods for (un)registering arbitrary observers in an ArrayList.

Fields Summary
protected final ArrayList
mObservers
The list of observers. An observer can be in the list at most once and will never be null.
Constructors Summary
Methods Summary
public voidregisterObserver(T observer)
Adds an observer to the list. The observer cannot be null and it must not already be registered.

param
observer the observer to register
throws
IllegalArgumentException the observer is null
throws
IllegalStateException the observer is already registered


                                              
        
        if (observer == null) {
            throw new IllegalArgumentException("The observer is null.");
        }
        synchronized(mObservers) {
            if (mObservers.contains(observer)) {
                throw new IllegalStateException("Observer " + observer + " is already registered.");
            }
            mObservers.add(observer);
        }
    
public voidunregisterAll()
Remove all registered observer

        synchronized(mObservers) {
            mObservers.clear();
        }        
    
public voidunregisterObserver(T observer)
Removes a previously registered observer. The observer must not be null and it must already have been registered.

param
observer the observer to unregister
throws
IllegalArgumentException the observer is null
throws
IllegalStateException the observer is not yet registered

        if (observer == null) {
            throw new IllegalArgumentException("The observer is null.");
        }
        synchronized(mObservers) {
            int index = mObservers.indexOf(observer);
            if (index == -1) {
                throw new IllegalStateException("Observer " + observer + " was not registered.");
            }
            mObservers.remove(index);
        }