Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package org.jmmo.component8;
 
User: Tomas Date: 30.05.13 Time: 21:13
 
public abstract class DependentComponentBase extends ComponentBase {
    protected boolean wasAvailable;
    @Override
    public boolean isAvailable() {
        return .map(container -> require().allMatch(container::isInterfaceAvailable)).orElse(false);
    }
    @Override
    protected void onContainerAvailable() {
        if (isAvailable()) {
            onBecomeAvailable();
        }
    }
    @Override
    public <I> void interfaceAvailable(Class<I> interfaceClass) {
        if (! && .isPresent() && require().filter(interfaceClass::equals).findAny().isPresent() && isAvailable()) {
            onBecomeAvailable();
        }
    }
    @Override
    public <I> void interfaceRevoked(Class<I> interfaceClass) {
        if ( && .isPresent() && require().filter(interfaceClass::equals).findAny().isPresent()) {
            onBecomeRevoked();
        }
    }
    @Override
    protected void onBecomeAvailable() {
         = true;
        super.onBecomeAvailable();
    }
    @Override
    protected void onBecomeRevoked() {
         = false;
        super.onBecomeRevoked();
    }
    protected abstract Stream<Class<?>> require();
New to GrepCode? Check out our FAQ X