Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package org.jmmo.component8;
 
 
 public abstract class InterfacesContainerBase implements InterfacesContainer {
 
     @Override
    public <I> boolean isInterfaceAvailable(Class<I> interfaceClass) {
        return getInterfaces().contains(interfaceClass);
    }
    @SuppressWarnings("unchecked")
    @Override
    public <I> void forInterface(Class<I> interfaceClassConsumer<? super I> consumer) {
        consumer.accept(implementationsFor(interfaceClass).reduce((aClassaClass2) -> {
            throw new IllegalStateException("There are too many implementations of " + interfaceClass);
        }).orElseThrow(() -> new IllegalArgumentException("There is no implementation of " + interfaceClass)));
    }
    @Override
    public <I> void forInterfaces(Class<I> interfaceClassConsumer<? super I> consumer) {
        implementationsFor(interfaceClass).forEach(consumer::accept);
    }
    @Override
    public <I, R> R fromInterface(Class<I> interfaceClassFunction<? super I, R> function) {
        return implementationsFor(interfaceClass).reduce((aClassaClass2) -> {
            throw new IllegalStateException("There are too many implementations of " + interfaceClass);
        }).map(function::apply).orElseThrow(() -> new IllegalArgumentException("There is no implementation of " + interfaceClass));
    }
    @Override
    public <I, R> Stream<R> fromInterfaces(Class<I> interfaceClassFunction<? super I, R> function) {
        return implementationsFor(interfaceClass).map(function::apply);
    }
    abstract protected <I> Stream<? extends I> implementationsFor(Class<I> interfaceClass);
New to GrepCode? Check out our FAQ X