@@ -0,0 +1,1191 @@
+/**%0A * @license%0A * Copyright 2020 The FOAM Authors. All Rights Reserved.%0A * http://www.apache.org/licenses/LICENSE-2.0%0A */%0A%0Apackage foam.nanos.boot;%0A%0Aimport foam.core.X;%0Aimport foam.core.XFactory;%0Aimport foam.mlang.predicate.Predicate;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.List;%0A%0Apublic class AltFactory implements XFactory %7B%0A  private final String key_;%0A  private final List%3CAltDelegate%3E altDelegates_ = new ArrayList%3C%3E();%0A%0A  public AltFactory(String serviceKey) %7B%0A    key_ = serviceKey;%0A  %7D%0A%0A  public void addDelegate(Predicate predicate, String serviceKey) %7B%0A    altDelegates_.add(new AltDelegate(predicate, serviceKey));%0A  %7D%0A%0A  @Override%0A  public Object create(X x) %7B%0A    for ( var delegate : altDelegates_ ) %7B%0A      if ( delegate.f(x) ) %7B%0A        return delegate.get(x);%0A      %7D%0A    %7D%0A    return x.get(key_);%0A  %7D%0A%0A  protected class AltDelegate %7B%0A    private final Predicate predicate_;%0A    private final String key_;%0A%0A    public AltDelegate(Predicate predicate, String serviceKey) %7B%0A      predicate_ = predicate;%0A      key_ = serviceKey;%0A    %7D%0A%0A    public boolean f(X x) %7B%0A      return predicate_.f(x);%0A    %7D%0A%0A    public Object get(X x) %7B%0A      return x.get(key_);%0A    %7D%0A  %7D%0A%7D%0A

Implement AltFactory to support composing service with multiple nspec keys and predicates