Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.jmmo.component8;
  
  
  import java.util.HashMap;
 import java.util.Map;
 import java.util.Set;
 
     protected final InterfacesContainerBase interfacesContainer = new InterfacesContainerBase() {
         @Override
         public Set<Class<?>> getInterfaces() {
             return .keySet();
         }
 
         @SuppressWarnings("unchecked")
         @Override
         protected <I> Stream<I> implementationsFor(Class<I> interfaceClass) {
             return .getOrDefault(interfaceClass, Collections.emptySet()).stream().map(component -> (I) component);
         }
     };
 
     @Override
     public Set<Class<?>> getInterfaces() {
         return Collections.unmodifiableSet(.getInterfaces());
     }
 
     @Override
     public <I> boolean isInterfaceAvailable(Class<I> interfaceClass) {
         return .isInterfaceAvailable(interfaceClass);
     }
 
     @Override
     public <I> void forInterface(Class<I> interfaceClassConsumer<? super I> consumer) {
         .forInterface(interfaceClassconsumer);
     }
 
     @Override
     public <I> void forInterfaces(Class<I> interfaceClassConsumer<? super I> consumer) {
         .forInterfaces(interfaceClassconsumer);
     }
 
     @SuppressWarnings("unchecked")
     @Override
     public <I, R> R fromInterface(Class<I> interfaceClassFunction<? super I, R> function) {
         return .fromInterface(interfaceClassfunction);
     }
 
     @Override
     public <I, R> Stream<R> fromInterfaces(Class<I> interfaceClassFunction<? super I, R> function) {
         return .fromInterfaces(interfaceClassfunction);
     }
 
     protected final Set<Componentcomponents = new HashSet<>();
     protected final Map<Class<?>, Set<Object>> availableInterfaces = new HashMap<>();
 
     @Override
     public Stream<ComponentgetComponents() {
         return .stream();
     }
 
     @Override
     public void addComponent(Component component) {
         if (.contains(component)) {
             throw new IllegalArgumentException("Can't add " + component + " because there is the same one in " + this);
         }
 
         .keySet().forEach(component::interfaceAvailable);
 
         .add(component);
         component.containerAvailable(this);
 
         if (component instanceof Observable) {
             addChildObservable((Observablecomponent);
         }
     }
 
     @Override
     public void removeComponent(Component component) {
         if (!.contains(component)) {
            throw new IllegalArgumentException(component + " is not found in " + this);
        }
        component.containerRevoked(this);
        .remove(component);
        .keySet().forEach(component::interfaceRevoked);
        if (component instanceof Observable) {
            removeChildObservable((Observablecomponent);
        }
    }
    @Override
    public void becomeAvailable(Class<?> availableInterfaceStream<?> implementations) {
        boolean wasAvailable = isInterfaceAvailable(availableInterface);
        final Set<ObjectimplementationsSet = implementations.collect(Collectors.toCollection(HashSet<Object>::new));
        .merge(availableInterfaceimplementationsSet, (components1components2) -> {
            if (!Collections.disjoint(components1components2)) {
                throw new IllegalArgumentException("Reimplementing of " + availableInterface + " in " + this + " by " + implementationsSet);
            }
            components1.addAll(components2);
            return components1;
        });
        if (!wasAvailable && isInterfaceAvailable(availableInterface)) {
            .forEach(component -> component.interfaceAvailable(availableInterface));
            fireObservableEvent(new InterfaceAvailableEvent(thisavailableInterface));
        }
    }
    @Override
    public void becomeRevoked(Class<?> revokedInterfaceStream<?> implementations) {
        boolean wasAvailable = isInterfaceAvailable(revokedInterface);
        .compute(revokedInterface, (aClasscomponents) -> {
            if (components == null || components.size() < 2) {
                return null;
            }
            components.removeAll(implementations.collect(Collectors.toCollection(HashSet<Object>::new)));
            return components;
        });
        if (wasAvailable && !isInterfaceAvailable(revokedInterface)) {
            .forEach(component -> component.interfaceRevoked(revokedInterface));
            fireObservableEvent(new InterfaceRevokedEvent(thisrevokedInterface));
        }
    }
    @Override
    protected void doFireAddedObservableEvent(Observable sourceObservable involved) {
        //not fire this event
    }
    @Override
    protected void doFireRemovedObservableEvent(Observable sourceObservable involved) {
        //not fire this event
    }
New to GrepCode? Check out our FAQ X