Code example for CopyOnWriteArrayList

Methods: add, contains

0
public class Model { 
    protected CopyOnWriteArrayList<IModelChangedObserver> mModelChangedObservers =
            new CopyOnWriteArrayList<IModelChangedObserver>();
 
    public void registerModelChangedObserver(IModelChangedObserver observer) {
        if (!mModelChangedObservers.contains(observer)) {
            mModelChangedObservers.add(observer);
            registerModelChangedObserverInDescendants(observer);
        } 
    } 
 
    public void unregisterModelChangedObserver(IModelChangedObserver observer) {
        mModelChangedObservers.remove(observer);
        unregisterModelChangedObserverInDescendants(observer);
    } 
 
    public void unregisterAllModelChangedObservers() { 
        unregisterAllModelChangedObserversInDescendants(); 
        mModelChangedObservers.clear();
    }