Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package org.jmmo.observable;
 
 
 import java.util.Set;

User: Tomas Date: 16.02.13 Time: 18:28
public abstract class ObservableImmContainerBase<E extends Observableextends ObservableBase {
    protected Set<ObservableListenerallListeners;
    @Override
    protected void addChildListeners(ObservableListener listener) {
        final ObservableListener childListener = createChildListener(listener);
        if ( == null) {
             = createListenersSet();
        }
        if (.contains(childListener)) {
            throw new IllegalArgumentException("Observable listener " + childListener + " already exists in " + this);
        }
        .add(childListener);
        //subscribe children
        for (Observable child : getChildObservables()) {
            child.addObservableListener(childListener);
        }
    }
    @Override
    protected void removeChildListeners(ObservableListener listener) {
        if ( != null) {
            final ObservableListener childListener = createChildListener(listener);
            .remove(childListener);
            if (.isEmpty()) {
                 = null;
            }
            //unsubscribe children
            for (Observable child : getChildObservables()) {
                child.removeObservableListener(childListener);
            }
        }
    }
        return new ObservableListenerWrapper(listenergetOwner());
    }
    protected abstract Collection<E> getChildObservables();
New to GrepCode? Check out our FAQ X