polygene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nic...@apache.org
Subject [21/24] zest-java git commit: ZEST-118; Massive update of removing the Iterable<> use for type manipulation in the runtime internals and all public APIs of that.
Date Wed, 26 Aug 2015 15:45:24 GMT
http://git-wip-us.apache.org/repos/asf/zest-java/blob/bd6fbad9/core/runtime/src/main/java/org/apache/zest/runtime/composite/ConstructorsModel.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/composite/ConstructorsModel.java b/core/runtime/src/main/java/org/apache/zest/runtime/composite/ConstructorsModel.java
index 9bc075f..435a020 100644
--- a/core/runtime/src/main/java/org/apache/zest/runtime/composite/ConstructorsModel.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/composite/ConstructorsModel.java
@@ -24,7 +24,7 @@ import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.List;
-import java.util.function.Function;
+import java.util.stream.Stream;
 import org.apache.zest.api.common.ConstructionException;
 import org.apache.zest.api.composite.CompositeDescriptor;
 import org.apache.zest.api.composite.InvalidCompositeException;
@@ -35,8 +35,7 @@ import org.apache.zest.api.util.Classes;
 import org.apache.zest.bootstrap.BindingException;
 import org.apache.zest.functional.HierarchicalVisitor;
 import org.apache.zest.functional.HierarchicalVisitorAdapter;
-import org.apache.zest.functional.Iterables;
-import org.apache.zest.functional.Specifications;
+import org.apache.zest.runtime.legacy.Specifications;
 import org.apache.zest.functional.VisitableHierarchy;
 import org.apache.zest.runtime.injection.Dependencies;
 import org.apache.zest.runtime.injection.DependencyModel;
@@ -107,18 +106,24 @@ public final class ConstructorsModel
     }
 
     @Override
-    public Iterable<DependencyModel> dependencies()
+    public Stream<DependencyModel> dependencies()
     {
-        Function<ConstructorModel, Iterable<DependencyModel>> constructorDependencies = new Function<ConstructorModel, Iterable<DependencyModel>>()
+        if( boundConstructors == null )
         {
-            @Override
-            public Iterable<DependencyModel> apply( ConstructorModel constructorModel )
-            {
-                return constructorModel.dependencies();
-            }
-        };
+            return constructorModels.stream().flatMap( ConstructorModel::dependencies );
+        }
+        return boundConstructors.stream().flatMap( ConstructorModel::dependencies );
 
-        return Iterables.flattenIterables( Iterables.map( constructorDependencies, boundConstructors == null ? constructorModels : boundConstructors ) );
+//        Function<ConstructorModel, Iterable<DependencyModel>> constructorDependencies = new Function<ConstructorModel, Iterable<DependencyModel>>()
+//        {
+//            @Override
+//            public Iterable<DependencyModel> apply( ConstructorModel constructorModel )
+//            {
+//                return constructorModel.dependencies();
+//            }
+//        };
+//
+//        return Iterables.flattenIterables( Iterables.map( constructorDependencies, boundConstructors == null ? constructorModels : boundConstructors ) );
     }
 
     @SuppressWarnings( "raw" )

http://git-wip-us.apache.org/repos/asf/zest-java/blob/bd6fbad9/core/runtime/src/main/java/org/apache/zest/runtime/composite/FragmentClassLoader.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/composite/FragmentClassLoader.java b/core/runtime/src/main/java/org/apache/zest/runtime/composite/FragmentClassLoader.java
index 91a782a..d83c9f0 100644
--- a/core/runtime/src/main/java/org/apache/zest/runtime/composite/FragmentClassLoader.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/composite/FragmentClassLoader.java
@@ -19,17 +19,17 @@ import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
 import java.util.ArrayList;
 import java.util.List;
+import org.apache.zest.api.entity.Lifecycle;
+import org.apache.zest.api.mixin.Initializable;
+import org.apache.zest.api.util.Classes;
+import org.apache.zest.api.util.Methods;
 import org.objectweb.asm.ClassWriter;
 import org.objectweb.asm.Label;
 import org.objectweb.asm.MethodVisitor;
 import org.objectweb.asm.Opcodes;
 import org.objectweb.asm.Type;
-import org.apache.zest.api.entity.Lifecycle;
-import org.apache.zest.api.mixin.Initializable;
-import org.apache.zest.api.util.Classes;
-import org.apache.zest.api.util.Methods;
-import org.apache.zest.functional.Iterables;
 
+import static org.apache.zest.api.util.Classes.interfacesOf;
 import static org.objectweb.asm.Opcodes.AASTORE;
 import static org.objectweb.asm.Opcodes.ACC_PRIVATE;
 import static org.objectweb.asm.Opcodes.ACC_PUBLIC;
@@ -69,7 +69,6 @@ import static org.objectweb.asm.Opcodes.POP;
 import static org.objectweb.asm.Opcodes.PUTSTATIC;
 import static org.objectweb.asm.Opcodes.RETURN;
 import static org.objectweb.asm.Type.getInternalName;
-import static org.apache.zest.api.util.Classes.interfacesOf;
 
 /**
  * Generate subclasses of mixins/modifiers that implement all interfaces not in the class itself
@@ -87,13 +86,13 @@ public class FragmentClassLoader
         String jdkString = System.getProperty( "java.specification.version" );
         switch( jdkString )
         {
-            case "1.8":
-                JDK_VERSION = Opcodes.V1_8;
-                break;
-            case "1.7":
-            default:
-                JDK_VERSION = Opcodes.V1_7;
-                break;
+        case "1.8":
+            JDK_VERSION = Opcodes.V1_8;
+            break;
+        case "1.7":
+        default:
+            JDK_VERSION = Opcodes.V1_7;
+            break;
         }
     }
 
@@ -140,8 +139,10 @@ public class FragmentClassLoader
                 }
             }
 //  To Allow JDK classes to be composed.
-            if( name.startsWith( "java." ))
+            if( name.startsWith( "java." ) )
+            {
                 name = "zest." + name;
+            }
 
             byte[] b = generateClass( name, baseClass );
             return defineClass( name, b, 0, b.length, baseClass.getProtectionDomain() );
@@ -164,7 +165,8 @@ public class FragmentClassLoader
 
         // Composite reference
         {
-            cw.visitField( ACC_PUBLIC, "_instance", "Lorg/apache/zest/api/composite/CompositeInvoker;", null, null ).visitEnd();
+            cw.visitField( ACC_PUBLIC, "_instance", "Lorg/apache/zest/api/composite/CompositeInvoker;", null, null )
+                .visitEnd();
         }
 
         // Static Method references
@@ -173,10 +175,10 @@ public class FragmentClassLoader
             int idx = 1;
             for( Method method : baseClass.getMethods() )
             {
-                if( isOverridden(method, baseClass) )
+                if( isOverridden( method, baseClass ) )
                 {
                     cw.visitField( ACC_PRIVATE + ACC_STATIC, "m" + idx++, "Ljava/lang/reflect/Method;", null,
-                                        null ).visitEnd();
+                                   null ).visitEnd();
                     hasProxyMethods = true;
                 }
             }
@@ -190,34 +192,42 @@ public class FragmentClassLoader
                 String desc = org.objectweb.asm.commons.Method.getMethod( constructor ).getDescriptor();
                 MethodVisitor cmv = cw.visitMethod( ACC_PUBLIC, "<init>", desc, null, null );
                 cmv.visitCode();
-                cmv.visitVarInsn(ALOAD, 0);
+                cmv.visitVarInsn( ALOAD, 0 );
 
                 int idx = 1;
                 for( Class aClass : constructor.getParameterTypes() )
                 {
                     final int opcode;
-                    if (aClass.equals(Integer.TYPE)) {
+                    if( aClass.equals( Integer.TYPE ) )
+                    {
                         opcode = ILOAD;
-                    } else if (aClass.equals(Long.TYPE)) {
+                    }
+                    else if( aClass.equals( Long.TYPE ) )
+                    {
                         opcode = LLOAD;
-                    } else if (aClass.equals(Float.TYPE)) {
+                    }
+                    else if( aClass.equals( Float.TYPE ) )
+                    {
                         opcode = FLOAD;
-                    } else if (aClass.equals(Double.TYPE)) {
+                    }
+                    else if( aClass.equals( Double.TYPE ) )
+                    {
                         opcode = DLOAD;
-                    } else {
+                    }
+                    else
+                    {
                         opcode = ALOAD;
                     }
-                    cmv.visitVarInsn(opcode, idx++);
+                    cmv.visitVarInsn( opcode, idx++ );
                 }
 
-                cmv.visitMethodInsn(INVOKESPECIAL, baseClassSlash, "<init>", desc, false);
-                cmv.visitInsn(RETURN);
-                cmv.visitMaxs(idx, idx);
+                cmv.visitMethodInsn( INVOKESPECIAL, baseClassSlash, "<init>", desc, false );
+                cmv.visitInsn( RETURN );
+                cmv.visitMaxs( idx, idx );
                 cmv.visitEnd();
             }
         }
 
-
         // Overloaded and unimplemented methods
         if( hasProxyMethods )
         {
@@ -226,7 +236,7 @@ public class FragmentClassLoader
             List<Label> exceptionLabels = new ArrayList<>();
             for( Method method : methods )
             {
-                if( isOverridden(method, baseClass) )
+                if( isOverridden( method, baseClass ) )
                 {
                     idx++;
                     String methodName = method.getName();
@@ -404,7 +414,7 @@ public class FragmentClassLoader
                 int midx = 0;
                 for( Method method : methods )
                 {
-                    if( isOverridden(method, baseClass) )
+                    if( isOverridden( method, baseClass ) )
                     {
                         method.setAccessible( true );
                         Class methodClass;
@@ -466,7 +476,7 @@ public class FragmentClassLoader
         return cw.toByteArray();
     }
 
-    private static boolean isOverridden(Method method, Class baseClass)
+    private static boolean isOverridden( Method method, Class baseClass )
     {
         if( Modifier.isAbstract( method.getModifiers() ) )
         {
@@ -505,58 +515,39 @@ public class FragmentClassLoader
 
     private static boolean isDeclaredIn( Method method, Class<?> clazz, Class<?> baseClass )
     {
-        if( !clazz.isAssignableFrom( baseClass ) )
-        {
-            return false;
-        }
-
-        try
-        {
-            clazz.getMethod( method.getName(), method.getParameterTypes() );
-            return true;
-        }
-        catch( NoSuchMethodException e )
-        {
-            return false;
-        }
+        return clazz.isAssignableFrom( baseClass ) && checkForMethod( method, clazz );
     }
 
     private static Class getInterfaceMethodDeclaration( Method method, Class clazz )
         throws NoSuchMethodException
     {
-        Iterable<Class<?>> interfaces = Iterables.map( Classes.RAW_CLASS, interfacesOf( clazz ) );
-        for( Class<?> anInterface : interfaces )
-        {
-            try
-            {
-                anInterface.getMethod( method.getName(), method.getParameterTypes() );
-                return anInterface;
-            }
-            catch( NoSuchMethodException e )
-            {
-                // Try next
-            }
-        }
-
-        throw new NoSuchMethodException( method.getName() );
+        return interfacesOf( clazz )
+            .map( Classes.RAW_CLASS )
+            .filter( intface -> checkForMethod( method, intface ) )
+            .findFirst()
+            .orElseThrow( () -> new NoSuchMethodException( method.getName() ) );
     }
 
     private static boolean isInterfaceMethod( Method method, Class<?> baseClass )
     {
-        for( Class<?> aClass : Iterables.filter( Methods.HAS_METHODS, Iterables.map( Classes.RAW_CLASS, interfacesOf( baseClass ) ) ) )
+        return interfacesOf( baseClass )
+            .map( Classes.RAW_CLASS )
+            .filter( Methods.HAS_METHODS )
+            .anyMatch( intface -> checkForMethod( method, intface ));
+    }
+
+    private static boolean checkForMethod( Method method, Class<?> intface )
+    {
+        try
         {
-            try
-            {
-                Method m = aClass.getMethod( method.getName(), method.getParameterTypes() );
-                m.setAccessible( true );
-                return true;
-            }
-            catch( NoSuchMethodException e )
-            {
-                // Ignore
-            }
+            Method m = intface.getMethod( method.getName(), method.getParameterTypes() );
+            m.setAccessible( true );
+            return true;
+        }
+        catch( NoSuchMethodException e )
+        {
+            return false;
         }
-        return false;
     }
 
     private static void type( MethodVisitor mv, Class<?> aClass )

http://git-wip-us.apache.org/repos/asf/zest-java/blob/bd6fbad9/core/runtime/src/main/java/org/apache/zest/runtime/composite/FunctionStateResolver.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/composite/FunctionStateResolver.java b/core/runtime/src/main/java/org/apache/zest/runtime/composite/FunctionStateResolver.java
index a0ade3d..ea4c5e4 100644
--- a/core/runtime/src/main/java/org/apache/zest/runtime/composite/FunctionStateResolver.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/composite/FunctionStateResolver.java
@@ -77,18 +77,15 @@ public class FunctionStateResolver
 
     public void populateState( EntityModel model, EntityState state )
     {
-        for( PropertyDescriptor propDesc : model.state().properties() )
-        {
+        model.state().properties().forEach( propDesc -> {
             Object value = getPropertyState( propDesc );
             state.setPropertyValue( propDesc.qualifiedName(), value );
-        }
-        for( AssociationDescriptor assDesc : model.state().associations() )
-        {
+        } );
+        model.state().associations().forEach( assDesc -> {
             EntityReference ref = getAssociationState( assDesc );
             state.setAssociationValue( assDesc.qualifiedName(), ref );
-        }
-        for( ManyAssociationModel manyAssDesc : model.state().manyAssociations() )
-        {
+        } );
+        model.state().manyAssociations().forEach( manyAssDesc -> {
             ManyAssociationState associationState = state.manyAssociationValueOf( manyAssDesc.qualifiedName() );
             // First clear existing ones
             for( EntityReference ref : associationState )
@@ -100,9 +97,8 @@ public class FunctionStateResolver
             {
                 associationState.add( 0, ref );
             }
-        }
-        for( NamedAssociationModel namedAssDesc : model.state().namedAssociations() )
-        {
+        } );
+        model.state().namedAssociations().forEach( namedAssDesc -> {
             NamedAssociationState associationState = state.namedAssociationValueOf( namedAssDesc.qualifiedName() );
             // First clear existing ones
             for( String name : associationState )
@@ -114,6 +110,6 @@ public class FunctionStateResolver
             {
                 associationState.put( entry.getKey(), entry.getValue() );
             }
-        }
+        } );
     }
 }

http://git-wip-us.apache.org/repos/asf/zest-java/blob/bd6fbad9/core/runtime/src/main/java/org/apache/zest/runtime/composite/MixinModel.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/composite/MixinModel.java b/core/runtime/src/main/java/org/apache/zest/runtime/composite/MixinModel.java
index c0be60b..abbe7b0 100644
--- a/core/runtime/src/main/java/org/apache/zest/runtime/composite/MixinModel.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/composite/MixinModel.java
@@ -17,6 +17,8 @@ package org.apache.zest.runtime.composite;
 import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.Method;
 import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
 import org.apache.zest.api.common.ConstructionException;
 import org.apache.zest.api.composite.CompositeInstance;
 import org.apache.zest.api.injection.scope.This;
@@ -25,29 +27,25 @@ import org.apache.zest.api.mixin.InitializationException;
 import org.apache.zest.api.mixin.MixinDescriptor;
 import org.apache.zest.api.property.StateHolder;
 import org.apache.zest.functional.HierarchicalVisitor;
-import org.apache.zest.functional.Iterables;
 import org.apache.zest.functional.VisitableHierarchy;
+import org.apache.zest.runtime.injection.Dependencies;
 import org.apache.zest.runtime.injection.DependencyModel;
 import org.apache.zest.runtime.injection.InjectedFieldsModel;
 import org.apache.zest.runtime.injection.InjectedMethodsModel;
 import org.apache.zest.runtime.injection.InjectionContext;
 
-import static org.apache.zest.functional.Iterables.map;
-import static org.apache.zest.functional.Iterables.toList;
-import static org.apache.zest.functional.Iterables.unique;
-
 /**
  * JAVADOC
  */
 public final class MixinModel
-    implements MixinDescriptor, VisitableHierarchy<Object, Object>
+    implements MixinDescriptor, VisitableHierarchy<Object, Object>, Dependencies
 {
     private final Class<?> mixinClass;
     private final Class<?> instantiationClass;
     private final ConstructorsModel constructorsModel;
     private final InjectedFieldsModel injectedFieldsModel;
     private final InjectedMethodsModel injectedMethodsModel;
-    private final Iterable<Class<?>> thisMixinTypes;
+    private final List<Class<?>> thisMixinTypes;
 
     public MixinModel( Class<?> declaredMixinClass, Class<?> instantiationClass )
     {
@@ -77,10 +75,12 @@ public final class MixinModel
         return InvocationHandler.class.isAssignableFrom( mixinClass );
     }
 
-    public Iterable<DependencyModel> dependencies()
+    public Stream<DependencyModel> dependencies()
     {
-        return Iterables.flatten( constructorsModel.dependencies(), injectedFieldsModel.dependencies(), injectedMethodsModel
-            .dependencies() );
+        return Stream.of( constructorsModel, injectedFieldsModel, injectedMethodsModel )
+            .flatMap( Dependencies::dependencies );
+//        return Iterables.flatten( constructorsModel.dependencies(), injectedFieldsModel.dependencies(), injectedMethodsModel
+//            .dependencies() );
     }
 
     @Override
@@ -121,11 +121,7 @@ public final class MixinModel
                 instantiationClass.getDeclaredField( "_instance" ).set( mixin,
                                                                         injectionContext.compositeInstance() );
             }
-            catch( IllegalAccessException e )
-            {
-                e.printStackTrace();
-            }
-            catch( NoSuchFieldException e )
+            catch( IllegalAccessException | NoSuchFieldException e )
             {
                 e.printStackTrace();
             }
@@ -141,7 +137,7 @@ public final class MixinModel
             }
             catch( InitializationException e )
             {
-                List<Class<?>> compositeType = toList( compositeInstance.types() );
+                List<Class<?>> compositeType = compositeInstance.types().collect( Collectors.toList() );
                 String message = "Unable to initialize " + mixinClass + " in composite " + compositeType;
                 throw new ConstructionException( message, e );
             }
@@ -154,9 +150,14 @@ public final class MixinModel
         return thisMixinTypes;
     }
 
-    private Iterable<Class<?>> buildThisMixinTypes()
+    private List<Class<?>> buildThisMixinTypes()
     {
-        return map( new DependencyModel.InjectionTypeFunction(), unique( Iterables.filter( new DependencyModel.ScopeSpecification( This.class ), dependencies() ) ) );
+        return dependencies()
+            .filter( new DependencyModel.ScopeSpecification( This.class ) )
+            .distinct()
+            .map( new DependencyModel.InjectionTypeFunction() )
+            .collect( Collectors.toList() );
+//        return map( new DependencyModel.InjectionTypeFunction(), unique( Iterables.filter( new DependencyModel.ScopeSpecification( This.class ), dependencies() ) ) );
     }
 
     protected FragmentInvocationHandler newInvocationHandler( Method method )

http://git-wip-us.apache.org/repos/asf/zest-java/blob/bd6fbad9/core/runtime/src/main/java/org/apache/zest/runtime/composite/MixinsModel.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/composite/MixinsModel.java b/core/runtime/src/main/java/org/apache/zest/runtime/composite/MixinsModel.java
index 30fc6c0..c944c2b 100644
--- a/core/runtime/src/main/java/org/apache/zest/runtime/composite/MixinsModel.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/composite/MixinsModel.java
@@ -25,11 +25,13 @@ import java.util.Map;
 import java.util.Set;
 import java.util.function.Function;
 import java.util.function.Predicate;
+import java.util.stream.Stream;
 import org.apache.zest.api.util.Classes;
 import org.apache.zest.bootstrap.BindingException;
 import org.apache.zest.functional.HierarchicalVisitor;
 import org.apache.zest.functional.HierarchicalVisitorAdapter;
 import org.apache.zest.functional.VisitableHierarchy;
+import org.apache.zest.runtime.injection.Dependencies;
 import org.apache.zest.runtime.injection.DependencyModel;
 import org.apache.zest.runtime.injection.InjectedFieldModel;
 import org.apache.zest.runtime.model.Binder;
@@ -37,7 +39,6 @@ import org.apache.zest.runtime.model.Resolution;
 
 import static org.apache.zest.api.util.Classes.interfacesOf;
 import static org.apache.zest.functional.Iterables.filter;
-import static org.apache.zest.functional.Iterables.flattenIterables;
 import static org.apache.zest.functional.Iterables.map;
 
 /**
@@ -45,7 +46,7 @@ import static org.apache.zest.functional.Iterables.map;
  * and mixin implementations.
  */
 public class MixinsModel
-    implements Binder, VisitableHierarchy<Object, Object>
+    implements Binder, VisitableHierarchy<Object, Object>, Dependencies
 {
     protected final Map<Method, MixinModel> methodImplementation = new HashMap<Method, MixinModel>();
     protected final Map<Method, Integer> methodIndex = new HashMap<Method, Integer>();
@@ -54,9 +55,9 @@ public class MixinsModel
     private final Map<Class, Integer> mixinIndex = new HashMap<Class, Integer>();
     private final Set<Class<?>> mixinTypes = new LinkedHashSet<Class<?>>();
 
-    public Iterable<Class<?>> mixinTypes()
+    public Stream<Class<?>> mixinTypes()
     {
-        return mixinTypes;
+        return mixinTypes.stream();
     }
 
     public <T> boolean isImplemented( Class<T> mixinType )
@@ -88,10 +89,9 @@ public class MixinsModel
 
     public void addMixinType( Class mixinType )
     {
-        for( Type type : interfacesOf( mixinType ) )
-        {
-            mixinTypes.add( Classes.RAW_CLASS.apply( type ) );
-        }
+        Stream<? extends Type> stream = interfacesOf( mixinType );
+        Stream<Class<?>> rawClass = stream.map( Classes.RAW_CLASS );
+        rawClass.forEach( mixinTypes::add );
     }
 
     public void addMixinModel( MixinModel mixinModel )
@@ -189,36 +189,33 @@ public class MixinsModel
         return mixinFor( method ).newInvocationHandler( method );
     }
 
-    public Iterable<DependencyModel> dependencies()
+    public Stream<DependencyModel> dependencies()
     {
-        return flattenIterables( map( new Function<MixinModel, Iterable<DependencyModel>>()
-        {
-            @Override
-            public Iterable<DependencyModel> apply( MixinModel mixinModel )
-            {
-                return mixinModel.dependencies();
-            }
-        }, mixinModels ) );
+        return mixinModels.stream().flatMap( Dependencies::dependencies );
     }
 
-    public Iterable<Method> invocationsFor( final Class<?> mixinClass )
+    public Stream<Method> invocationsFor( final Class<?> mixinClass )
     {
-        return map( new Function<Map.Entry<Method, MixinModel>, Method>()
-        {
-            @Override
-            public Method apply( Map.Entry<Method, MixinModel> entry )
-            {
-                return entry.getKey();
-            }
-        }, filter( new Predicate<Map.Entry<Method, MixinModel>>()
-        {
-            @Override
-            public boolean test( Map.Entry<Method, MixinModel> item )
-            {
-                MixinModel model = item.getValue();
-                return model.mixinClass().equals( mixinClass );
-            }
-        }, methodImplementation.entrySet() ) );
+        return methodImplementation.entrySet()
+            .stream().filter( entry -> entry.getValue().mixinClass().equals( mixinClass ) )
+            .map( Map.Entry::getKey );
+
+//        return map( new Function<Map.Entry<Method, MixinModel>, Method>()
+//        {
+//            @Override
+//            public Method apply( Map.Entry<Method, MixinModel> entry )
+//            {
+//                return entry.getKey();
+//            }
+//        }, filter( new Predicate<Map.Entry<Method, MixinModel>>()
+//        {
+//            @Override
+//            public boolean test( Map.Entry<Method, MixinModel> item )
+//            {
+//                MixinModel model = item.getValue();
+//                return model.mixinClass().equals( mixinClass );
+//            }
+//        }, methodImplementation.entrySet() ) );
     }
 
     private class Uses

http://git-wip-us.apache.org/repos/asf/zest-java/blob/bd6fbad9/core/runtime/src/main/java/org/apache/zest/runtime/composite/SideEffectsModel.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/composite/SideEffectsModel.java b/core/runtime/src/main/java/org/apache/zest/runtime/composite/SideEffectsModel.java
index 888ec22..26d2afa 100644
--- a/core/runtime/src/main/java/org/apache/zest/runtime/composite/SideEffectsModel.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/composite/SideEffectsModel.java
@@ -19,6 +19,7 @@ import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
+import java.util.stream.Stream;
 import org.apache.zest.api.sideeffect.SideEffectsDescriptor;
 import org.apache.zest.functional.HierarchicalVisitor;
 import org.apache.zest.functional.Iterables;
@@ -43,9 +44,10 @@ public final class SideEffectsModel
     }
 
     @Override
-    public Iterable<DependencyModel> dependencies()
+    public Stream<DependencyModel> dependencies()
     {
-        return Iterables.flattenIterables( Iterables.map( Dependencies.DEPENDENCIES_FUNCTION, sideEffectModels ) );
+        return sideEffectModels.stream().flatMap( Dependencies::dependencies );
+//        return Iterables.flattenIterables( Iterables.map( Dependencies.DEPENDENCIES_FUNCTION, sideEffectModels ) );
     }
 
     // Context

http://git-wip-us.apache.org/repos/asf/zest-java/blob/bd6fbad9/core/runtime/src/main/java/org/apache/zest/runtime/composite/StateModel.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/composite/StateModel.java b/core/runtime/src/main/java/org/apache/zest/runtime/composite/StateModel.java
index a0b17cb..1ad5088 100644
--- a/core/runtime/src/main/java/org/apache/zest/runtime/composite/StateModel.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/composite/StateModel.java
@@ -18,6 +18,7 @@
 package org.apache.zest.runtime.composite;
 
 import java.lang.reflect.AccessibleObject;
+import java.util.stream.Stream;
 import org.apache.zest.api.common.QualifiedName;
 import org.apache.zest.api.composite.StateDescriptor;
 import org.apache.zest.functional.HierarchicalVisitor;
@@ -58,7 +59,7 @@ public class StateModel
     }
 
     @Override
-    public Iterable<PropertyModel> properties()
+    public Stream<PropertyModel> properties()
     {
         return propertiesModel.properties();
     }

http://git-wip-us.apache.org/repos/asf/zest-java/blob/bd6fbad9/core/runtime/src/main/java/org/apache/zest/runtime/composite/TransientBuilderInstance.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/composite/TransientBuilderInstance.java b/core/runtime/src/main/java/org/apache/zest/runtime/composite/TransientBuilderInstance.java
index e834262..6e84bf0 100644
--- a/core/runtime/src/main/java/org/apache/zest/runtime/composite/TransientBuilderInstance.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/composite/TransientBuilderInstance.java
@@ -84,10 +84,10 @@ public final class TransientBuilderInstance<T>
         throws ConstructionException
     {
         // Set correct info's (immutable) on the state
-        for( PropertyDescriptor propertyDescriptor : model.model().state().properties() )
+        model.model().state().properties().forEach( propertyDescriptor ->
         {
-            ( (PropertyInstance<Object>) state.propertyFor( propertyDescriptor.accessor() ) ).setPropertyInfo( (PropertyInfo) propertyDescriptor );
-        }
+            ( (PropertyInstance<Object>) state.propertyFor( propertyDescriptor.accessor() ) ).setPropertyInfo( propertyDescriptor );
+        } );
 
         model.model().checkConstraints( state );
 

http://git-wip-us.apache.org/repos/asf/zest-java/blob/bd6fbad9/core/runtime/src/main/java/org/apache/zest/runtime/composite/TransientClassLoader.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/composite/TransientClassLoader.java b/core/runtime/src/main/java/org/apache/zest/runtime/composite/TransientClassLoader.java
index 924ecb7..384f4fc 100644
--- a/core/runtime/src/main/java/org/apache/zest/runtime/composite/TransientClassLoader.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/composite/TransientClassLoader.java
@@ -19,6 +19,9 @@ import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
 import java.util.ArrayList;
 import java.util.List;
+import org.apache.zest.api.entity.Lifecycle;
+import org.apache.zest.api.mixin.Initializable;
+import org.apache.zest.api.util.Methods;
 import org.objectweb.asm.AnnotationVisitor;
 import org.objectweb.asm.ClassWriter;
 import org.objectweb.asm.FieldVisitor;
@@ -26,12 +29,9 @@ import org.objectweb.asm.Label;
 import org.objectweb.asm.MethodVisitor;
 import org.objectweb.asm.Opcodes;
 import org.objectweb.asm.Type;
-import org.apache.zest.api.entity.Lifecycle;
-import org.apache.zest.api.mixin.Initializable;
-import org.apache.zest.api.util.Classes;
-import org.apache.zest.api.util.Methods;
-import org.apache.zest.functional.Iterables;
 
+import static org.apache.zest.api.util.Classes.RAW_CLASS;
+import static org.apache.zest.api.util.Classes.interfacesOf;
 import static org.objectweb.asm.Opcodes.AASTORE;
 import static org.objectweb.asm.Opcodes.ACC_PRIVATE;
 import static org.objectweb.asm.Opcodes.ACC_PUBLIC;
@@ -71,7 +71,6 @@ import static org.objectweb.asm.Opcodes.POP;
 import static org.objectweb.asm.Opcodes.PUTSTATIC;
 import static org.objectweb.asm.Opcodes.RETURN;
 import static org.objectweb.asm.Type.getInternalName;
-import static org.apache.zest.api.util.Classes.interfacesOf;
 
 /**
  * Generate subclasses of classes used for transients. All methods delegate to CompositeInvoker.
@@ -88,13 +87,13 @@ import static org.apache.zest.api.util.Classes.interfacesOf;
         String jdkString = System.getProperty( "java.specification.version" );
         switch( jdkString )
         {
-            case "1.8":
-                JDK_VERSION = Opcodes.V1_8;
-                break;
-            case "1.7":
-            default:
-                JDK_VERSION = Opcodes.V1_7;
-                break;
+        case "1.8":
+            JDK_VERSION = Opcodes.V1_8;
+            break;
+        case "1.7":
+        default:
+            JDK_VERSION = Opcodes.V1_7;
+            break;
         }
     }
 
@@ -439,14 +438,7 @@ import static org.apache.zest.api.util.Classes.interfacesOf;
 
     private static boolean isOverloaded( Method method, Class baseClass )
     {
-        if( Modifier.isFinal( method.getModifiers() ) )
-        {
-            return false; // Cannot override final methods
-        }
-        else
-        {
-            return true;
-        }
+        return !Modifier.isFinal( method.getModifiers() );
     }
 
     private static boolean isInternalZestMethod( Method method, Class baseClass )
@@ -473,33 +465,29 @@ import static org.apache.zest.api.util.Classes.interfacesOf;
         }
     }
 
-    private static Class getInterfaceMethodDeclaration( Method method, Class clazz )
+    private static Class<?> getInterfaceMethodDeclaration( Method method, Class clazz )
         throws NoSuchMethodException
     {
-        Iterable<Class<?>> interfaces = Iterables.map( Classes.RAW_CLASS, interfacesOf( clazz ) );
-        for( Class<?> anInterface : interfaces )
-        {
+        return interfacesOf( clazz ).map( RAW_CLASS ).filter( intFace -> {
             try
             {
-                anInterface.getMethod( method.getName(), method.getParameterTypes() );
-                return anInterface;
+                intFace.getMethod( method.getName(), method.getParameterTypes() );
+                return true;
             }
             catch( NoSuchMethodException e )
             {
                 // Try next
+                return false;
             }
-        }
-
-        throw new NoSuchMethodException( method.getName() );
+        } ).findFirst().orElseThrow( () -> new NoSuchMethodException( method.getName() ) );
     }
 
     private static boolean isInterfaceMethod( Method method, Class<?> baseClass )
     {
-        for( Class<?> aClass : Iterables.filter( Methods.HAS_METHODS, Iterables.map( Classes.RAW_CLASS, interfacesOf( baseClass ) ) ) )
-        {
+        return interfacesOf( baseClass ).map( RAW_CLASS ).filter( Methods.HAS_METHODS ).anyMatch( clazz -> {
             try
             {
-                Method m = aClass.getMethod( method.getName(), method.getParameterTypes() );
+                Method m = clazz.getMethod( method.getName(), method.getParameterTypes() );
                 m.setAccessible( true );
                 return true;
             }
@@ -507,8 +495,8 @@ import static org.apache.zest.api.util.Classes.interfacesOf;
             {
                 // Ignore
             }
-        }
-        return false;
+            return false;
+        } );
     }
 
     private static void type( MethodVisitor mv, Class<?> aClass )

http://git-wip-us.apache.org/repos/asf/zest-java/blob/bd6fbad9/core/runtime/src/main/java/org/apache/zest/runtime/composite/TransientInstance.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/composite/TransientInstance.java b/core/runtime/src/main/java/org/apache/zest/runtime/composite/TransientInstance.java
index df15d5c..5531d52 100644
--- a/core/runtime/src/main/java/org/apache/zest/runtime/composite/TransientInstance.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/composite/TransientInstance.java
@@ -20,6 +20,7 @@ import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.Method;
 import java.lang.reflect.Proxy;
 import java.util.Arrays;
+import java.util.stream.Stream;
 import org.apache.zest.api.ZestAPI;
 import org.apache.zest.api.composite.Composite;
 import org.apache.zest.api.composite.CompositeInstance;
@@ -102,7 +103,7 @@ public class TransientInstance
     }
 
     @Override
-    public Iterable<Class<?>> types()
+    public Stream<Class<?>> types()
     {
         return compositeModel.types();
     }
@@ -213,7 +214,7 @@ public class TransientInstance
             String modelTypeName = compositeModel.getClass().getSimpleName();
             String metaTypeModel = modelTypeName.substring( 0, modelTypeName.length() - 5 );
             return metaTypeModel + "Instance{" +
-                   "mixins=" + ( mixins == null ? null : Arrays.asList( mixins ) ) +
+                   "mixins=" + Arrays.asList( mixins ) +
                    ", state=" + state +
                    ", compositeModel=" + compositeModel +
                    ", module=" + moduleInstance +

http://git-wip-us.apache.org/repos/asf/zest-java/blob/bd6fbad9/core/runtime/src/main/java/org/apache/zest/runtime/composite/TransientModel.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/composite/TransientModel.java b/core/runtime/src/main/java/org/apache/zest/runtime/composite/TransientModel.java
index 0d0ecac..cc3d343 100644
--- a/core/runtime/src/main/java/org/apache/zest/runtime/composite/TransientModel.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/composite/TransientModel.java
@@ -14,22 +14,21 @@
 
 package org.apache.zest.runtime.composite;
 
+import java.util.List;
 import org.apache.zest.api.common.MetaInfo;
 import org.apache.zest.api.common.Visibility;
 import org.apache.zest.api.composite.TransientDescriptor;
 import org.apache.zest.api.constraint.ConstraintViolationException;
 import org.apache.zest.runtime.injection.InjectionContext;
-import org.apache.zest.runtime.property.PropertyModel;
 import org.apache.zest.spi.module.ModuleSpi;
 
 /**
  * Model for Transient Composites
  */
-public class TransientModel
-    extends CompositeModel
+public class TransientModel extends CompositeModel
     implements TransientDescriptor
 {
-    public TransientModel( Iterable<Class<?>> types, final Visibility visibility,
+    public TransientModel( List<Class<?>> types, final Visibility visibility,
                            final MetaInfo metaInfo,
                            final MixinsModel mixinsModel,
                            final StateModel stateModel,
@@ -62,9 +61,8 @@ public class TransientModel
     public void checkConstraints( TransientStateInstance instanceState )
         throws ConstraintViolationException
     {
-        for( PropertyModel propertyModel : stateModel.properties() )
-        {
-            propertyModel.checkConstraints( instanceState.<Object>propertyFor( propertyModel.accessor() ).get() );
-        }
+        stateModel.properties().forEach( propertyModel ->
+            propertyModel.checkConstraints( instanceState.propertyFor( propertyModel.accessor() ).get() )
+        );
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/zest-java/blob/bd6fbad9/core/runtime/src/main/java/org/apache/zest/runtime/composite/TransientStateInstance.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/composite/TransientStateInstance.java b/core/runtime/src/main/java/org/apache/zest/runtime/composite/TransientStateInstance.java
index 14d0901..13f3853 100644
--- a/core/runtime/src/main/java/org/apache/zest/runtime/composite/TransientStateInstance.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/composite/TransientStateInstance.java
@@ -20,6 +20,7 @@ package org.apache.zest.runtime.composite;
 
 import java.lang.reflect.AccessibleObject;
 import java.util.Map;
+import java.util.stream.Stream;
 import org.apache.zest.api.property.Property;
 import org.apache.zest.api.property.StateHolder;
 
@@ -53,8 +54,8 @@ public final class TransientStateInstance
     }
 
     @Override
-    public Iterable<Property<?>> properties()
+    public Stream<Property<?>> properties()
     {
-        return properties.values();
+        return properties.values().stream();
     }
 }

http://git-wip-us.apache.org/repos/asf/zest-java/blob/bd6fbad9/core/runtime/src/main/java/org/apache/zest/runtime/composite/TransientsModel.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/composite/TransientsModel.java b/core/runtime/src/main/java/org/apache/zest/runtime/composite/TransientsModel.java
index 102719e..42a34cb 100644
--- a/core/runtime/src/main/java/org/apache/zest/runtime/composite/TransientsModel.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/composite/TransientsModel.java
@@ -15,6 +15,8 @@
 package org.apache.zest.runtime.composite;
 
 import java.util.List;
+import java.util.stream.Stream;
+import org.apache.zest.api.composite.TransientDescriptor;
 import org.apache.zest.functional.HierarchicalVisitor;
 import org.apache.zest.functional.VisitableHierarchy;
 
@@ -31,9 +33,9 @@ public class TransientsModel
         this.transientModels = transientModels;
     }
 
-    public Iterable<TransientModel> models()
+    public Stream<TransientModel> models()
     {
-        return transientModels;
+        return transientModels.stream();
     }
 
     @Override
@@ -52,4 +54,9 @@ public class TransientsModel
         }
         return modelVisitor.visitLeave( this );
     }
+
+    public Stream<? extends TransientDescriptor> stream()
+    {
+        return transientModels.stream();
+    }
 }

http://git-wip-us.apache.org/repos/asf/zest-java/blob/bd6fbad9/core/runtime/src/main/java/org/apache/zest/runtime/entity/EntitiesModel.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/entity/EntitiesModel.java b/core/runtime/src/main/java/org/apache/zest/runtime/entity/EntitiesModel.java
index 56deeb7..7106515 100644
--- a/core/runtime/src/main/java/org/apache/zest/runtime/entity/EntitiesModel.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/entity/EntitiesModel.java
@@ -15,6 +15,8 @@
 package org.apache.zest.runtime.entity;
 
 import java.util.List;
+import java.util.stream.Stream;
+import org.apache.zest.api.entity.EntityDescriptor;
 import org.apache.zest.functional.HierarchicalVisitor;
 import org.apache.zest.functional.VisitableHierarchy;
 
@@ -31,9 +33,9 @@ public class EntitiesModel
         this.entityModels = entityModels;
     }
 
-    public Iterable<EntityModel> models()
+    public Stream<EntityModel> models()
     {
-        return entityModels;
+        return entityModels.stream();
     }
 
     @Override
@@ -52,4 +54,9 @@ public class EntitiesModel
         }
         return modelVisitor.visitLeave( this );
     }
+
+    public Stream<? extends EntityDescriptor> stream()
+    {
+        return entityModels.stream();
+    }
 }

http://git-wip-us.apache.org/repos/asf/zest-java/blob/bd6fbad9/core/runtime/src/main/java/org/apache/zest/runtime/entity/EntityInstance.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/entity/EntityInstance.java b/core/runtime/src/main/java/org/apache/zest/runtime/entity/EntityInstance.java
index 8512a87..de3013e 100644
--- a/core/runtime/src/main/java/org/apache/zest/runtime/entity/EntityInstance.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/entity/EntityInstance.java
@@ -17,13 +17,11 @@ package org.apache.zest.runtime.entity;
 
 import java.lang.reflect.Method;
 import java.lang.reflect.Proxy;
-import java.util.HashSet;
-import java.util.Set;
-import org.apache.zest.api.association.Association;
+import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
 import org.apache.zest.api.association.AssociationDescriptor;
 import org.apache.zest.api.association.AssociationStateDescriptor;
-import org.apache.zest.api.association.ManyAssociation;
-import org.apache.zest.api.association.NamedAssociation;
 import org.apache.zest.api.composite.CompositeDescriptor;
 import org.apache.zest.api.composite.CompositeInstance;
 import org.apache.zest.api.constraint.ConstraintViolationException;
@@ -41,6 +39,8 @@ import org.apache.zest.spi.entity.EntityState;
 import org.apache.zest.spi.entity.EntityStatus;
 import org.apache.zest.spi.module.ModuleSpi;
 
+import static java.util.stream.Collectors.toList;
+
 /**
  * Entity instance
  */
@@ -128,7 +128,7 @@ public final class EntityInstance
     }
 
     @Override
-    public Iterable<Class<?>> types()
+    public Stream<Class<?>> types()
     {
         return entityModel.types();
     }
@@ -268,50 +268,27 @@ public final class EntityInstance
     {
         // Calculate aggregated Entities
         AssociationStateDescriptor stateDescriptor = entityModel.state();
-        Set<Object> aggregatedEntities = new HashSet<>();
-        Iterable<? extends AssociationDescriptor> associations = stateDescriptor.associations();
-        for( AssociationDescriptor association : associations )
-        {
-            if( association.isAggregated() )
-            {
-                Association<?> assoc = state.associationFor( association.accessor() );
-                Object aggregatedEntity = assoc.get();
-                if( aggregatedEntity != null )
-                {
-                    aggregatedEntities.add( aggregatedEntity );
-                }
-            }
-        }
-        Iterable<? extends AssociationDescriptor> manyAssociations = stateDescriptor.manyAssociations();
-        for( AssociationDescriptor association : manyAssociations )
-        {
-            if( association.isAggregated() )
-            {
-                ManyAssociation<?> manyAssoc = state.manyAssociationFor( association.accessor() );
-                for( Object entity : manyAssoc )
-                {
-                    aggregatedEntities.add( entity );
-                }
-            }
-        }
-        Iterable<? extends AssociationDescriptor> namedAssociations = stateDescriptor.namedAssociations();
-        for( AssociationDescriptor association : namedAssociations )
-        {
-            if( association.isAggregated() )
-            {
-                NamedAssociation<?> namedAssoc = state.namedAssociationFor( association.accessor() );
-                for( String name : namedAssoc )
-                {
-                    aggregatedEntities.add( namedAssoc.get( name ) );
-                }
-            }
-        }
-
-        // Remove aggregated Entities
-        for( Object aggregatedEntity : aggregatedEntities )
-        {
-            unitOfWork.remove( aggregatedEntity );
-        }
+        Stream.concat(
+            stateDescriptor.associations()
+                .filter( AssociationDescriptor::isAggregated )
+                .map( association -> state.associationFor( association.accessor() ).get() )
+                .filter( entity -> entity != null ),
+
+            Stream.concat(
+                stateDescriptor.manyAssociations()
+                    .filter( AssociationDescriptor::isAggregated )
+                    .flatMap( association -> state.manyAssociationFor( association.accessor() ).toList().stream() )
+                    .filter( entity -> entity != null ),
+
+                stateDescriptor.namedAssociations()
+                    .filter( AssociationDescriptor::isAggregated )
+                    .flatMap( association -> state.namedAssociationFor( association.accessor() )
+                        .toMap()
+                        .values()
+                        .stream() )
+                    .filter( entity -> entity != null )
+            )
+        ).distinct().forEach( unitOfWork::remove );
     }
 
     public void checkConstraints()
@@ -322,8 +299,8 @@ public final class EntityInstance
         }
         catch( ConstraintViolationException e )
         {
-            throw new ConstraintViolationException( identity.identity(), entityModel.types(), e.mixinTypeName(), e.methodName(), e
-                .constraintViolations() );
+            List<Class<?>> entityModelList = entityModel.types().collect( toList() );
+            throw new ConstraintViolationException( identity.identity(), entityModelList, e.mixinTypeName(), e.methodName(), e.constraintViolations() );
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/zest-java/blob/bd6fbad9/core/runtime/src/main/java/org/apache/zest/runtime/entity/EntityModel.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/entity/EntityModel.java b/core/runtime/src/main/java/org/apache/zest/runtime/entity/EntityModel.java
index aa45b18..8079507 100644
--- a/core/runtime/src/main/java/org/apache/zest/runtime/entity/EntityModel.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/entity/EntityModel.java
@@ -15,6 +15,7 @@
 package org.apache.zest.runtime.entity;
 
 import java.lang.reflect.Method;
+import java.util.List;
 import org.apache.zest.api.association.AssociationDescriptor;
 import org.apache.zest.api.common.ConstructionException;
 import org.apache.zest.api.common.MetaInfo;
@@ -29,7 +30,6 @@ import org.apache.zest.api.property.PropertyDescriptor;
 import org.apache.zest.api.property.StateHolder;
 import org.apache.zest.api.unitofwork.EntityCompositeAlreadyExistsException;
 import org.apache.zest.api.util.Annotations;
-import org.apache.zest.functional.Iterables;
 import org.apache.zest.runtime.composite.CompositeMethodsModel;
 import org.apache.zest.runtime.composite.CompositeModel;
 import org.apache.zest.runtime.property.PropertyModel;
@@ -40,16 +40,10 @@ import org.apache.zest.spi.entitystore.EntityStoreException;
 import org.apache.zest.spi.entitystore.EntityStoreUnitOfWork;
 import org.apache.zest.spi.module.ModuleSpi;
 
-import static org.apache.zest.functional.Iterables.filter;
-import static org.apache.zest.functional.Iterables.first;
-import static org.apache.zest.functional.Iterables.flattenIterables;
-import static org.apache.zest.functional.Iterables.map;
-
 /**
  * JAVADOC
  */
-public final class EntityModel
-    extends CompositeModel
+public final class EntityModel extends CompositeModel
     implements EntityDescriptor
 {
     private static final Method IDENTITY_METHOD;
@@ -68,7 +62,7 @@ public final class EntityModel
 
     private final boolean queryable;
 
-    public EntityModel( Iterable<Class<?>> types,
+    public EntityModel( List<Class<?>> types,
                         Visibility visibility,
                         MetaInfo info,
                         EntityMixinsModel mixinsModel,
@@ -78,10 +72,12 @@ public final class EntityModel
     {
         super( types, visibility, info, mixinsModel, stateModel, compositeMethodsModel );
 
-        final Queryable queryable = first( Iterables.<Queryable>cast(
-            filter( Annotations.isType( Queryable.class ),
-                    flattenIterables( map( Annotations.ANNOTATIONS_OF, types ) ) ) ) );
-        this.queryable = queryable == null || queryable.value();
+        this.queryable = types.stream()
+            .flatMap( Annotations.ANNOTATIONS_OF )
+            .filter( Annotations.isType( Queryable.class ) )
+            .map( annot -> ( (Queryable) annot ).value() )
+            .findFirst()
+            .orElse( false );
     }
 
     @Override
@@ -98,8 +94,7 @@ public final class EntityModel
 
     public EntityInstance newInstance( ModuleUnitOfWork uow, ModuleSpi moduleInstance, EntityState state )
     {
-        EntityInstance instance = new EntityInstance( uow, moduleInstance, this, state );
-        return instance;
+        return new EntityInstance( uow, moduleInstance, this, state );
     }
 
     public Object[] newMixinHolder()
@@ -143,28 +138,24 @@ public final class EntityModel
     public void initState( ModuleSpi module, EntityState entityState )
     {
         // Set new properties to default value
-        for( PropertyModel propertyDescriptor : state().properties() )
-        {
+        state().properties().forEach( propertyDescriptor -> {
             entityState.setPropertyValue( propertyDescriptor.qualifiedName(), propertyDescriptor.initialValue( module ) );
-        }
+        } );
 
         // Set new associations to null
-        for( AssociationDescriptor associationDescriptor : state().associations() )
-        {
+        state().associations().forEach( associationDescriptor -> {
             entityState.setAssociationValue( associationDescriptor.qualifiedName(), null );
-        }
+        } );
 
         // Set new many-associations to empty
-        for( AssociationDescriptor associationDescriptor : state().manyAssociations() )
-        {
+        state().manyAssociations().forEach( associationDescriptor -> {
             entityState.manyAssociationValueOf( associationDescriptor.qualifiedName() );
-        }
+        } );
 
         // Set new named-associations to empty
-        for( AssociationDescriptor associationDescriptor : state().namedAssociations() )
-        {
+        state().namedAssociations().forEach( associationDescriptor -> {
             entityState.namedAssociationValueOf( associationDescriptor.qualifiedName() );
-        }
+        } );
     }
 
     public void invokeLifecycle( boolean create, Object[] mixins, CompositeInstance instance, StateHolder state )

http://git-wip-us.apache.org/repos/asf/zest-java/blob/bd6fbad9/core/runtime/src/main/java/org/apache/zest/runtime/entity/EntityStateInstance.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/entity/EntityStateInstance.java b/core/runtime/src/main/java/org/apache/zest/runtime/entity/EntityStateInstance.java
index 82a511b..9ab2326 100644
--- a/core/runtime/src/main/java/org/apache/zest/runtime/entity/EntityStateInstance.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/entity/EntityStateInstance.java
@@ -24,18 +24,15 @@ import java.lang.reflect.Type;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.function.BiFunction;
-import java.util.function.Function;
+import java.util.stream.Stream;
 import org.apache.zest.api.association.Association;
-import org.apache.zest.api.association.AssociationDescriptor;
 import org.apache.zest.api.association.AssociationStateHolder;
 import org.apache.zest.api.association.ManyAssociation;
 import org.apache.zest.api.association.NamedAssociation;
 import org.apache.zest.api.entity.EntityReference;
 import org.apache.zest.api.property.Property;
-import org.apache.zest.api.property.PropertyDescriptor;
 import org.apache.zest.api.unitofwork.UnitOfWork;
 import org.apache.zest.api.util.Classes;
-import org.apache.zest.functional.Iterables;
 import org.apache.zest.runtime.association.AssociationInstance;
 import org.apache.zest.runtime.association.AssociationModel;
 import org.apache.zest.runtime.association.ManyAssociationInstance;
@@ -98,16 +95,9 @@ public final class EntityStateInstance
     }
 
     @Override
-    public Iterable<Property<?>> properties()
+    public Stream<Property<?>> properties()
     {
-        return Iterables.map( new Function<PropertyDescriptor, Property<?>>()
-        {
-            @Override
-            public Property<?> apply( PropertyDescriptor propertyDescriptor )
-            {
-                return propertyFor( propertyDescriptor.accessor() );
-            }
-        }, stateModel.properties() );
+        return stateModel.properties().map( descriptor -> propertyFor( descriptor.accessor() ) );
     }
 
     @Override
@@ -127,20 +117,20 @@ public final class EntityStateInstance
                 : associationModel,
                 entityFunction,
                 new Property<EntityReference>()
-            {
-                @Override
-                public EntityReference get()
-                {
-                    return entityState.associationValueOf( associationModel.qualifiedName() );
-                }
-
-                @Override
-                public void set( EntityReference newValue )
-                    throws IllegalArgumentException, IllegalStateException
                 {
-                    entityState.setAssociationValue( associationModel.qualifiedName(), newValue );
-                }
-            } );
+                    @Override
+                    public EntityReference get()
+                    {
+                        return entityState.associationValueOf( associationModel.qualifiedName() );
+                    }
+
+                    @Override
+                    public void set( EntityReference newValue )
+                        throws IllegalArgumentException, IllegalStateException
+                    {
+                        entityState.setAssociationValue( associationModel.qualifiedName(), newValue );
+                    }
+                } );
             state.put( accessor, association );
         }
 
@@ -148,16 +138,9 @@ public final class EntityStateInstance
     }
 
     @Override
-    public Iterable<Association<?>> allAssociations()
+    public Stream<? extends Association<?>> allAssociations()
     {
-        return Iterables.map( new Function<AssociationDescriptor, Association<?>>()
-        {
-            @Override
-            public Association<?> apply( AssociationDescriptor associationDescriptor )
-            {
-                return associationFor( associationDescriptor.accessor() );
-            }
-        }, stateModel.associations() );
+        return stateModel.associations().map( descriptor -> associationFor( descriptor.accessor() ) );
     }
 
     @Override
@@ -184,16 +167,9 @@ public final class EntityStateInstance
     }
 
     @Override
-    public Iterable<ManyAssociation<?>> allManyAssociations()
+    public Stream<ManyAssociation<?>> allManyAssociations()
     {
-        return Iterables.map( new Function<AssociationDescriptor, ManyAssociation<?>>()
-        {
-            @Override
-            public ManyAssociation<?> apply( AssociationDescriptor associationDescriptor )
-            {
-                return manyAssociationFor( associationDescriptor.accessor() );
-            }
-        }, stateModel.manyAssociations() );
+        return stateModel.manyAssociations().map( descriptor -> manyAssociationFor( descriptor.accessor() ) );
     }
 
     @Override
@@ -220,33 +196,22 @@ public final class EntityStateInstance
     }
 
     @Override
-    public Iterable<? extends NamedAssociation<?>> allNamedAssociations()
+    public Stream<? extends NamedAssociation<?>> allNamedAssociations()
     {
-        return Iterables.map( new Function<AssociationDescriptor, NamedAssociation<?>>()
-        {
-            @Override
-            public NamedAssociation<?> apply( AssociationDescriptor associationDescriptor )
-            {
-                return namedAssociationFor( associationDescriptor.accessor() );
-            }
-        }, stateModel.namedAssociations() );
+        return stateModel.namedAssociations().map( descriptor -> namedAssociationFor( descriptor.accessor() ) );
     }
 
     public void checkConstraints()
     {
-        for( PropertyDescriptor propertyDescriptor : stateModel.properties() )
-        {
-            ConstraintsCheck constraints = (ConstraintsCheck) propertyDescriptor;
+        stateModel.properties().forEach( propertyDescriptor -> {
             Property<Object> property = this.propertyFor( propertyDescriptor.accessor() );
-            constraints.checkConstraints( property.get() );
-        }
+            propertyDescriptor.checkConstraints( property.get() );
+        } );
 
-        for( AssociationDescriptor associationDescriptor : stateModel.associations() )
-        {
-            ConstraintsCheck constraints = (ConstraintsCheck) associationDescriptor;
+        stateModel.associations().forEach( associationDescriptor -> {
             Association<Object> association = this.associationFor( associationDescriptor.accessor() );
-            constraints.checkConstraints( association.get() );
-        }
+            associationDescriptor.checkConstraints( association.get() );
+        } );
 
         // TODO Should ManyAssociations and NamedAssociations be checked too?
     }

http://git-wip-us.apache.org/repos/asf/zest-java/blob/bd6fbad9/core/runtime/src/main/java/org/apache/zest/runtime/entity/EntityStateModel.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/entity/EntityStateModel.java b/core/runtime/src/main/java/org/apache/zest/runtime/entity/EntityStateModel.java
index 8b9b56e..82952b5 100644
--- a/core/runtime/src/main/java/org/apache/zest/runtime/entity/EntityStateModel.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/entity/EntityStateModel.java
@@ -20,6 +20,7 @@
 package org.apache.zest.runtime.entity;
 
 import java.lang.reflect.AccessibleObject;
+import java.util.stream.Stream;
 import org.apache.zest.api.association.AssociationDescriptor;
 import org.apache.zest.api.association.AssociationStateDescriptor;
 import org.apache.zest.api.common.QualifiedName;
@@ -117,19 +118,19 @@ public final class EntityStateModel
     }
 
     @Override
-    public Iterable<AssociationModel> associations()
+    public Stream<AssociationModel> associations()
     {
         return associationsModel.associations();
     }
 
     @Override
-    public Iterable<ManyAssociationModel> manyAssociations()
+    public Stream<ManyAssociationModel> manyAssociations()
     {
         return manyAssociationsModel.manyAssociations();
     }
 
     @Override
-    public Iterable<NamedAssociationModel> namedAssociations()
+    public Stream<NamedAssociationModel> namedAssociations()
     {
         return namedAssociationsModel.namedAssociations();
     }

http://git-wip-us.apache.org/repos/asf/zest-java/blob/bd6fbad9/core/runtime/src/main/java/org/apache/zest/runtime/injection/Dependencies.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/injection/Dependencies.java b/core/runtime/src/main/java/org/apache/zest/runtime/injection/Dependencies.java
index 4d68cff..55ee4f9 100644
--- a/core/runtime/src/main/java/org/apache/zest/runtime/injection/Dependencies.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/injection/Dependencies.java
@@ -19,20 +19,14 @@
 package org.apache.zest.runtime.injection;
 
 import java.util.function.Function;
+import java.util.stream.Stream;
 
 /**
  * TODO
  */
 public interface Dependencies
 {
-    public static Function<Dependencies, Iterable<DependencyModel>> DEPENDENCIES_FUNCTION = new Function<Dependencies, Iterable<DependencyModel>>()
-    {
-        @Override
-        public Iterable<DependencyModel> apply( Dependencies dependencies )
-        {
-            return dependencies.dependencies();
-        }
-    };
+    Function<Dependencies, Stream<DependencyModel>> DEPENDENCIES_FUNCTION = Dependencies::dependencies;
 
-    Iterable<DependencyModel> dependencies();
+    Stream<DependencyModel> dependencies();
 }

http://git-wip-us.apache.org/repos/asf/zest-java/blob/bd6fbad9/core/runtime/src/main/java/org/apache/zest/runtime/injection/InjectedFieldModel.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/injection/InjectedFieldModel.java b/core/runtime/src/main/java/org/apache/zest/runtime/injection/InjectedFieldModel.java
index f521e11..349a750 100644
--- a/core/runtime/src/main/java/org/apache/zest/runtime/injection/InjectedFieldModel.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/injection/InjectedFieldModel.java
@@ -20,6 +20,8 @@ import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.Proxy;
 import java.util.Collection;
 import java.util.function.Predicate;
+import java.util.stream.Stream;
+import org.apache.zest.api.composite.DependencyDescriptor;
 import org.apache.zest.api.composite.InjectedFieldDescriptor;
 import org.apache.zest.api.util.Classes;
 import org.apache.zest.bootstrap.BindingException;
@@ -36,7 +38,7 @@ import static java.util.Collections.singleton;
  * JAVADOC
  */
 public final class InjectedFieldModel
-    implements InjectedFieldDescriptor, VisitableHierarchy<InjectedFieldModel, DependencyModel>
+    implements InjectedFieldDescriptor, Dependencies, VisitableHierarchy<InjectedFieldModel, DependencyModel>
 {
     private DependencyModel dependencyModel;
     private Field injectedField;
@@ -49,9 +51,9 @@ public final class InjectedFieldModel
     }
 
     @Override
-    public DependencyModel dependency()
+    public Stream<DependencyModel> dependencies()
     {
-        return dependencyModel;
+        return Stream.of( dependencyModel );
     }
 
     @Override
@@ -60,6 +62,12 @@ public final class InjectedFieldModel
         return injectedField;
     }
 
+    @Override
+    public DependencyDescriptor dependency()
+    {
+        return dependencyModel;
+    }
+
     public void bind( Resolution resolution )
         throws BindingException
     {
@@ -80,7 +88,11 @@ public final class InjectedFieldModel
         catch( IllegalArgumentException e )
         {
             String valueClassName;
-            if( Proxy.isProxyClass( value.getClass() ) )
+            if( value == null )
+            {
+                valueClassName = "<null>";
+            }
+            else if( Proxy.isProxyClass( value.getClass() ) )
             {
                 InvocationHandler invocationHandler = Proxy.getInvocationHandler( value );
                 if( invocationHandler instanceof TransientInstance )

http://git-wip-us.apache.org/repos/asf/zest-java/blob/bd6fbad9/core/runtime/src/main/java/org/apache/zest/runtime/injection/InjectedFieldsModel.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/injection/InjectedFieldsModel.java b/core/runtime/src/main/java/org/apache/zest/runtime/injection/InjectedFieldsModel.java
index 0767282..18126eb 100644
--- a/core/runtime/src/main/java/org/apache/zest/runtime/injection/InjectedFieldsModel.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/injection/InjectedFieldsModel.java
@@ -20,21 +20,18 @@ import java.lang.reflect.ParameterizedType;
 import java.lang.reflect.Type;
 import java.lang.reflect.TypeVariable;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
-import java.util.function.Function;
+import java.util.stream.Stream;
 import org.apache.zest.api.injection.InjectionScope;
 import org.apache.zest.api.util.Classes;
 import org.apache.zest.api.util.Fields;
 import org.apache.zest.functional.HierarchicalVisitor;
-import org.apache.zest.functional.Iterables;
 import org.apache.zest.functional.VisitableHierarchy;
 
 import static org.apache.zest.api.util.Annotations.hasAnnotation;
 import static org.apache.zest.api.util.Annotations.type;
-import static org.apache.zest.functional.Iterables.filter;
-import static org.apache.zest.functional.Iterables.first;
-import static org.apache.zest.functional.Iterables.iterable;
-import static org.apache.zest.functional.Specifications.translate;
+import static org.apache.zest.runtime.legacy.Specifications.translate;
 
 /**
  * JAVADOC
@@ -42,20 +39,17 @@ import static org.apache.zest.functional.Specifications.translate;
 public final class InjectedFieldsModel
     implements Dependencies, VisitableHierarchy<Object, Object>
 {
-    private final List<InjectedFieldModel> fields = new ArrayList<InjectedFieldModel>();
+    private final List<InjectedFieldModel> fields = new ArrayList<>();
 
     public InjectedFieldsModel( Class fragmentClass )
     {
-        Iterable<Field> mappedFields = Fields.FIELDS_OF.apply( fragmentClass );
-        for( Field field : mappedFields )
-        {
-            Annotation injectionAnnotation = first( filter( translate( type(), hasAnnotation( InjectionScope.class ) ), iterable( field
-                                                                                                                                      .getAnnotations() ) ) );
-            if( injectionAnnotation != null )
-            {
-                addModel( fragmentClass, field, injectionAnnotation );
-            }
-        }
+        Fields.fieldsOf( fragmentClass ).forEach( field ->
+            Arrays.stream( field.getAnnotations() )
+                .filter( translate( type(), hasAnnotation( InjectionScope.class ) ) )
+                .filter( annot -> annot != null )
+                .forEach( injectionAnnotation ->  addModel( fragmentClass, field, injectionAnnotation )
+            )
+        );
     }
 
     private void addModel( Class fragmentClass, Field field, Annotation injectionAnnotation )
@@ -85,16 +79,17 @@ public final class InjectedFieldsModel
     }
 
     @Override
-    public Iterable<DependencyModel> dependencies()
+    public Stream<DependencyModel> dependencies()
     {
-        return Iterables.map( new Function<InjectedFieldModel, DependencyModel>()
-        {
-            @Override
-            public DependencyModel apply( InjectedFieldModel injectedFieldModel )
-            {
-                return injectedFieldModel.dependency();
-            }
-        }, fields );
+        return fields.stream().flatMap( Dependencies::dependencies );
+//        return Iterables.map( new Function<InjectedFieldModel, DependencyModel>()
+//        {
+//            @Override
+//            public DependencyModel apply( InjectedFieldModel injectedFieldModel )
+//            {
+//                return injectedFieldModel.dependency();
+//            }
+//        }, fields );
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/zest-java/blob/bd6fbad9/core/runtime/src/main/java/org/apache/zest/runtime/injection/InjectedMethodModel.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/injection/InjectedMethodModel.java b/core/runtime/src/main/java/org/apache/zest/runtime/injection/InjectedMethodModel.java
index b0ec660..bdb8d22 100644
--- a/core/runtime/src/main/java/org/apache/zest/runtime/injection/InjectedMethodModel.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/injection/InjectedMethodModel.java
@@ -16,6 +16,7 @@ package org.apache.zest.runtime.injection;
 
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
+import java.util.stream.Stream;
 import org.apache.zest.api.composite.InjectedMethodDescriptor;
 import org.apache.zest.bootstrap.InjectionException;
 import org.apache.zest.functional.HierarchicalVisitor;
@@ -45,7 +46,7 @@ public final class InjectedMethodModel
     }
 
     @Override
-    public Iterable<DependencyModel> dependencies()
+    public Stream<DependencyModel> dependencies()
     {
         return parameters.dependencies();
     }

http://git-wip-us.apache.org/repos/asf/zest-java/blob/bd6fbad9/core/runtime/src/main/java/org/apache/zest/runtime/injection/InjectedMethodsModel.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/injection/InjectedMethodsModel.java b/core/runtime/src/main/java/org/apache/zest/runtime/injection/InjectedMethodsModel.java
index 864143e..d4c5d06 100644
--- a/core/runtime/src/main/java/org/apache/zest/runtime/injection/InjectedMethodsModel.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/injection/InjectedMethodsModel.java
@@ -15,26 +15,23 @@
 package org.apache.zest.runtime.injection;
 
 import java.lang.annotation.Annotation;
-import java.lang.reflect.Method;
 import java.lang.reflect.ParameterizedType;
 import java.lang.reflect.Type;
 import java.lang.reflect.TypeVariable;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
+import java.util.Optional;
+import java.util.stream.Stream;
 import org.apache.zest.api.injection.InjectionScope;
 import org.apache.zest.api.util.Annotations;
 import org.apache.zest.api.util.Classes;
 import org.apache.zest.api.util.Methods;
 import org.apache.zest.functional.HierarchicalVisitor;
-import org.apache.zest.functional.Specifications;
+import org.apache.zest.runtime.legacy.Specifications;
 import org.apache.zest.functional.VisitableHierarchy;
 
 import static org.apache.zest.api.util.Annotations.hasAnnotation;
-import static org.apache.zest.functional.Iterables.filter;
-import static org.apache.zest.functional.Iterables.first;
-import static org.apache.zest.functional.Iterables.flattenIterables;
-import static org.apache.zest.functional.Iterables.iterable;
-import static org.apache.zest.functional.Iterables.map;
 
 /**
  * JAVADOC
@@ -43,57 +40,70 @@ public final class InjectedMethodsModel
     implements Dependencies, VisitableHierarchy<Object, Object>
 {
     // Model
-    private final List<InjectedMethodModel> methodModels = new ArrayList<InjectedMethodModel>();
+    private final List<InjectedMethodModel> methodModels = new ArrayList<>();
 
     public InjectedMethodsModel( Class fragmentClass )
     {
-        nextMethod:
-        for( Method method : Methods.METHODS_OF.apply( fragmentClass ) )
-        {
+        Methods.methodsOf( fragmentClass ).forEach( method -> {
             Annotation[][] parameterAnnotations = method.getParameterAnnotations();
             if( parameterAnnotations.length > 0 )
             {
                 InjectedParametersModel parametersModel = new InjectedParametersModel();
                 final Type[] genericParameterTypes = method.getGenericParameterTypes();
+                boolean found = true;
                 for( int i = 0; i < parameterAnnotations.length; i++ )
                 {
-                    Annotation injectionAnnotation = first( filter( Specifications.translate( Annotations.type(), hasAnnotation( InjectionScope.class ) ), iterable( parameterAnnotations[ i ] ) ) );
-                    if( injectionAnnotation == null )
-                    {
-                        continue nextMethod;
-                    }
-
-                    Type genericType = genericParameterTypes[ i ];
-                    if( genericType instanceof ParameterizedType )
+                    Optional<Annotation> opt = Arrays.stream( parameterAnnotations[ i ] )
+                        .filter( Specifications.translate( Annotations.type(), hasAnnotation( InjectionScope.class ) ) )
+                        .findFirst();
+                    if( opt.isPresent() )
                     {
-                        genericType = new ParameterizedTypeInstance( ( (ParameterizedType) genericType ).getActualTypeArguments(), ( (ParameterizedType) genericType )
-                            .getRawType(), ( (ParameterizedType) genericType ).getOwnerType() );
-
-                        for( int j = 0; j < ( (ParameterizedType) genericType ).getActualTypeArguments().length; j++ )
+                        Annotation injectionAnnotation = opt.get();
+                        Type genericType = genericParameterTypes[ i ];
+                        if( genericType instanceof ParameterizedType )
                         {
-                            Type type = ( (ParameterizedType) genericType ).getActualTypeArguments()[ j ];
-                            if( type instanceof TypeVariable )
+                            genericType = createParameterizedTypeInstance( (ParameterizedType) genericType );
+
+                            for( int j = 0; j < ( (ParameterizedType) genericType ).getActualTypeArguments().length; j++ )
                             {
-                                type = Classes.resolveTypeVariable( (TypeVariable) type, method.getDeclaringClass(), fragmentClass );
-                                ( (ParameterizedType) genericType ).getActualTypeArguments()[ j ] = type;
+                                Type type = ( (ParameterizedType) genericType ).getActualTypeArguments()[ j ];
+                                if( type instanceof TypeVariable )
+                                {
+                                    type = Classes.resolveTypeVariable( (TypeVariable) type, method.getDeclaringClass(), fragmentClass );
+                                    ( (ParameterizedType) genericType ).getActualTypeArguments()[ j ] = type;
+                                }
                             }
                         }
+                        boolean optional = DependencyModel.isOptional( injectionAnnotation, parameterAnnotations[ i ] );
+                        DependencyModel dependencyModel = new DependencyModel( injectionAnnotation, genericType, fragmentClass, optional, parameterAnnotations[ i ] );
+                        parametersModel.addDependency( dependencyModel );
                     }
-
-                    boolean optional = DependencyModel.isOptional( injectionAnnotation, parameterAnnotations[ i ] );
-                    DependencyModel dependencyModel = new DependencyModel( injectionAnnotation, genericType, fragmentClass, optional, parameterAnnotations[ i ] );
-                    parametersModel.addDependency( dependencyModel );
+                    else
+                    {
+                        found = false;
+                        break;
+                    }
+                }
+                if( found )
+                {
+                    methodModels.add( new InjectedMethodModel( method, parametersModel ) );
                 }
-                InjectedMethodModel methodModel = new InjectedMethodModel( method, parametersModel );
-                methodModels.add( methodModel );
             }
-        }
+        } );
+    }
+
+    private Type createParameterizedTypeInstance( ParameterizedType genericType )
+    {
+        return new ParameterizedTypeInstance(
+            genericType.getActualTypeArguments(), genericType.getRawType(), genericType.getOwnerType()
+        );
     }
 
     @Override
-    public Iterable<DependencyModel> dependencies()
+    public Stream<DependencyModel> dependencies()
     {
-        return flattenIterables( map( Dependencies.DEPENDENCIES_FUNCTION, methodModels ) );
+        return methodModels.stream().flatMap( InjectedMethodModel::dependencies );
+//        return flattenIterables( map( Dependencies.DEPENDENCIES_FUNCTION, methodModels ) );
     }
 
     // Context

http://git-wip-us.apache.org/repos/asf/zest-java/blob/bd6fbad9/core/runtime/src/main/java/org/apache/zest/runtime/injection/InjectedParametersModel.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/injection/InjectedParametersModel.java b/core/runtime/src/main/java/org/apache/zest/runtime/injection/InjectedParametersModel.java
index 1a4c723..91aeeb7 100644
--- a/core/runtime/src/main/java/org/apache/zest/runtime/injection/InjectedParametersModel.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/injection/InjectedParametersModel.java
@@ -18,9 +18,11 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
 import java.util.function.Predicate;
+import java.util.stream.Stream;
 import org.apache.zest.api.composite.InjectedParametersDescriptor;
 import org.apache.zest.functional.HierarchicalVisitor;
 import org.apache.zest.functional.VisitableHierarchy;
+import org.apache.zest.runtime.composite.ConstructorModel;
 
 /**
  * JAVADOC
@@ -36,9 +38,9 @@ public final class InjectedParametersModel
     }
 
     @Override
-    public Iterable<DependencyModel> dependencies()
+    public Stream<DependencyModel> dependencies()
     {
-        return parameterDependencies;
+        return parameterDependencies.stream();
     }
 
     // Context

http://git-wip-us.apache.org/repos/asf/zest-java/blob/bd6fbad9/core/runtime/src/main/java/org/apache/zest/runtime/injection/provider/InjectionProviderFactoryStrategy.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/injection/provider/InjectionProviderFactoryStrategy.java b/core/runtime/src/main/java/org/apache/zest/runtime/injection/provider/InjectionProviderFactoryStrategy.java
index 8d87bb9..05a5fa4 100644
--- a/core/runtime/src/main/java/org/apache/zest/runtime/injection/provider/InjectionProviderFactoryStrategy.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/injection/provider/InjectionProviderFactoryStrategy.java
@@ -35,16 +35,14 @@ import org.apache.zest.runtime.injection.InjectionProvider;
 import org.apache.zest.runtime.injection.InjectionProviderFactory;
 import org.apache.zest.runtime.model.Resolution;
 
-import static org.apache.zest.functional.Iterables.first;
-
 /**
  * JAVADOC
  */
 public final class InjectionProviderFactoryStrategy
     implements InjectionProviderFactory
 {
-    private final Map<Class<? extends Annotation>, InjectionProviderFactory> generalProviderFactories = new HashMap<Class<? extends Annotation>, InjectionProviderFactory>();
-    private final Map<Class<? extends Annotation>, InjectionProviderFactory> valuesProviderFactories = new HashMap<Class<? extends Annotation>, InjectionProviderFactory>();
+    private final Map<Class<? extends Annotation>, InjectionProviderFactory> generalProviderFactories = new HashMap<>();
+    private final Map<Class<? extends Annotation>, InjectionProviderFactory> valuesProviderFactories = new HashMap<>();
     private MetaInfo metaInfo;
 
     public InjectionProviderFactoryStrategy( MetaInfo metaInfo )
@@ -82,7 +80,7 @@ public final class InjectionProviderFactoryStrategy
             }
         }
         ModelDescriptor composite = resolution.model();
-        Class<?> compositeType = first( composite.types() );
+        Class<?> compositeType = composite.types().findFirst().orElse( null );
         if( factory1 != null && ValueComposite.class.isAssignableFrom( compositeType ) )
         {
             throw new InvalidValueCompositeException( "@" + injectionAnnotationType.getSimpleName() + " is not allowed in ValueComposites: " + compositeType );

http://git-wip-us.apache.org/repos/asf/zest-java/blob/bd6fbad9/core/runtime/src/main/java/org/apache/zest/runtime/injection/provider/ServiceInjectionProviderFactory.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/injection/provider/ServiceInjectionProviderFactory.java b/core/runtime/src/main/java/org/apache/zest/runtime/injection/provider/ServiceInjectionProviderFactory.java
index 764d227..9b65780 100644
--- a/core/runtime/src/main/java/org/apache/zest/runtime/injection/provider/ServiceInjectionProviderFactory.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/injection/provider/ServiceInjectionProviderFactory.java
@@ -26,7 +26,7 @@ import org.apache.zest.api.util.Annotations;
 import org.apache.zest.api.util.Classes;
 import org.apache.zest.bootstrap.InvalidInjectionException;
 import org.apache.zest.functional.Iterables;
-import org.apache.zest.functional.Specifications;
+import org.apache.zest.runtime.legacy.Specifications;
 import org.apache.zest.runtime.injection.DependencyModel;
 import org.apache.zest.runtime.injection.InjectionContext;
 import org.apache.zest.runtime.injection.InjectionProvider;

http://git-wip-us.apache.org/repos/asf/zest-java/blob/bd6fbad9/core/runtime/src/main/java/org/apache/zest/runtime/injection/provider/ThisInjectionProviderFactory.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/injection/provider/ThisInjectionProviderFactory.java b/core/runtime/src/main/java/org/apache/zest/runtime/injection/provider/ThisInjectionProviderFactory.java
index 70c8160..a3e2bf4 100644
--- a/core/runtime/src/main/java/org/apache/zest/runtime/injection/provider/ThisInjectionProviderFactory.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/injection/provider/ThisInjectionProviderFactory.java
@@ -21,6 +21,9 @@ package org.apache.zest.runtime.injection.provider;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.Proxy;
+import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
 import org.apache.zest.api.composite.CompositeDescriptor;
 import org.apache.zest.api.util.Classes;
 import org.apache.zest.bootstrap.InvalidInjectionException;
@@ -32,9 +35,6 @@ import org.apache.zest.runtime.injection.InjectionProvider;
 import org.apache.zest.runtime.injection.InjectionProviderFactory;
 import org.apache.zest.runtime.model.Resolution;
 
-import static org.apache.zest.functional.Iterables.first;
-import static org.apache.zest.functional.Iterables.iterable;
-
 /**
  * JAVADOC
  */
@@ -51,7 +51,7 @@ public final class ThisInjectionProviderFactory
             // If Composite type then return real type, otherwise use the specified one
             final Class<?> thisType = dependencyModel.rawInjectionType();
 
-            Iterable<Class<?>> injectionTypes = null;
+            Stream<Class<?>> injectionTypes;
             if( Classes.assignableTypeSpecification( thisType ).test( bindingContext.model() ) )
             {
                 injectionTypes = bindingContext.model().types();
@@ -59,25 +59,17 @@ public final class ThisInjectionProviderFactory
             else
             {
                 CompositeDescriptor acd = ( (CompositeDescriptor) bindingContext.model() );
-                for( Class<?> mixinType : acd.mixinTypes() )
-                {
-                    if( thisType.isAssignableFrom( mixinType ) )
-                    {
-                        Iterable<? extends Class<?>> iterable = iterable( thisType );
-                        injectionTypes = (Iterable<Class<?>>) iterable;
-                        break;
-                    }
-                }
-
-                if( injectionTypes == null )
-                {
-                    throw new InvalidInjectionException( "Composite " + bindingContext.model()
-                                                         + " does not implement @This type " + thisType.getName() + " in fragment "
-                                                         + dependencyModel.injectedClass().getName() );
-                }
+                injectionTypes = acd.mixinTypes().filter( thisType::isAssignableFrom );
             }
 
-            return new ThisInjectionProvider( injectionTypes );
+            List<Class<?>> classes = injectionTypes.collect( Collectors.toList() );
+            if( classes.size() == 0 )
+            {
+                throw new InvalidInjectionException( "Composite " + bindingContext.model()
+                                                     + " does not implement @This type " + thisType.getName() + " in fragment "
+                                                     + dependencyModel.injectedClass().getName() );
+            }
+            return new ThisInjectionProvider( classes );
         }
         else
         {
@@ -85,27 +77,27 @@ public final class ThisInjectionProviderFactory
         }
     }
 
-    @SuppressWarnings( {"raw", "unchecked"} )
+    @SuppressWarnings( { "raw", "unchecked" } )
     private static class ThisInjectionProvider
         implements InjectionProvider
     {
         Constructor proxyConstructor;
         private Class[] interfaces;
 
-        private ThisInjectionProvider( Iterable<Class<?>> types )
+        private ThisInjectionProvider( List<Class<?>> types )
         {
             try
             {
                 Class proxyClass;
-                if( Proxy.class.isAssignableFrom( first( types ) ) )
+                Class<?> mainType = types.get( 0 );
+                if( Proxy.class.isAssignableFrom( mainType ) )
                 {
-                    proxyClass = first( types );
+                    proxyClass = mainType;
                 }
                 else
                 {
-                    Class<?> mainType = first( types );
                     interfaces = Iterables.toArray( Class.class, Iterables.<Class>cast( types ) );
-                    proxyClass = ProxyGenerator.createProxyClass(mainType.getClassLoader(), interfaces);
+                    proxyClass = ProxyGenerator.createProxyClass( mainType.getClassLoader(), interfaces );
                 }
 
                 proxyConstructor = proxyClass.getConstructor( InvocationHandler.class );


Mime
View raw message