You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@polygene.apache.org by ni...@apache.org on 2015/08/26 17:45:25 UTC
[22/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.
http://git-wip-us.apache.org/repos/asf/zest-java/blob/bd6fbad9/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/CompositeAssemblyImpl.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/CompositeAssemblyImpl.java b/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/CompositeAssemblyImpl.java
index 7f4b83f..01c0d75 100644
--- a/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/CompositeAssemblyImpl.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/CompositeAssemblyImpl.java
@@ -20,7 +20,6 @@ package org.apache.zest.runtime.bootstrap;
import java.lang.annotation.Annotation;
import java.lang.reflect.AccessibleObject;
-import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Member;
@@ -29,14 +28,15 @@ import java.lang.reflect.Modifier;
import java.lang.reflect.Proxy;
import java.lang.reflect.Type;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.function.Consumer;
-import java.util.function.Function;
import java.util.function.Predicate;
-import java.util.stream.StreamSupport;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
import org.apache.zest.api.common.MetaInfo;
import org.apache.zest.api.common.Optional;
import org.apache.zest.api.common.QualifiedName;
@@ -63,7 +63,6 @@ import org.apache.zest.api.util.Classes;
import org.apache.zest.api.util.Fields;
import org.apache.zest.bootstrap.StateDeclarations;
import org.apache.zest.functional.HierarchicalVisitorAdapter;
-import org.apache.zest.functional.Iterables;
import org.apache.zest.runtime.composite.AbstractConstraintModel;
import org.apache.zest.runtime.composite.CompositeConstraintModel;
import org.apache.zest.runtime.composite.CompositeMethodModel;
@@ -80,11 +79,12 @@ import org.apache.zest.runtime.composite.SideEffectsModel;
import org.apache.zest.runtime.composite.StateModel;
import org.apache.zest.runtime.composite.ValueConstraintsInstance;
import org.apache.zest.runtime.composite.ValueConstraintsModel;
+import org.apache.zest.runtime.injection.Dependencies;
import org.apache.zest.runtime.injection.DependencyModel;
import org.apache.zest.runtime.property.PropertiesModel;
import org.apache.zest.runtime.property.PropertyModel;
-import static java.util.Arrays.asList;
+import static java.util.stream.Stream.concat;
import static org.apache.zest.api.util.Annotations.hasAnnotation;
import static org.apache.zest.api.util.Annotations.isType;
import static org.apache.zest.api.util.Annotations.type;
@@ -94,22 +94,10 @@ import static org.apache.zest.api.util.Classes.isAssignableFrom;
import static org.apache.zest.api.util.Classes.typeOf;
import static org.apache.zest.api.util.Classes.typesOf;
import static org.apache.zest.api.util.Classes.wrapperClass;
-import static org.apache.zest.functional.Iterables.addAll;
-import static org.apache.zest.functional.Iterables.cast;
-import static org.apache.zest.functional.Iterables.empty;
import static org.apache.zest.functional.Iterables.filter;
import static org.apache.zest.functional.Iterables.first;
-import static org.apache.zest.functional.Iterables.flatten;
-import static org.apache.zest.functional.Iterables.flattenIterables;
import static org.apache.zest.functional.Iterables.iterable;
-import static org.apache.zest.functional.Iterables.map;
-import static org.apache.zest.functional.Iterables.matchesAny;
-import static org.apache.zest.functional.Iterables.toList;
-import static org.apache.zest.functional.Specifications.and;
-import static org.apache.zest.functional.Specifications.in;
-import static org.apache.zest.functional.Specifications.not;
-import static org.apache.zest.functional.Specifications.or;
-import static org.apache.zest.functional.Specifications.translate;
+import static org.apache.zest.runtime.legacy.Specifications.translate;
/**
* Declaration of a Composite.
@@ -140,9 +128,9 @@ public abstract class CompositeAssemblyImpl
}
@Override
- public Iterable<Class<?>> types()
+ public Stream<Class<?>> types()
{
- return types;
+ return types.stream();
}
protected StateModel createStateModel()
@@ -171,40 +159,51 @@ public abstract class CompositeAssemblyImpl
propertiesModel = new PropertiesModel();
stateModel = createStateModel();
mixinsModel = createMixinsModel();
+// compositeMethodsModel = new CompositeMethodsModel();
compositeMethodsModel = new CompositeMethodsModel( mixinsModel );
// Implement composite methods
- ArrayList<Type> allTypes = getTypes( this.types );
- Iterable<Class<? extends Constraint<?, ?>>> constraintClasses = constraintDeclarations( getTypes( this.types ) );
- Iterable<Class<?>> concernClasses = flatten( concerns, concernDeclarations( allTypes ) );
- Iterable<Class<?>> sideEffectClasses = flatten( sideEffects, sideEffectDeclarations( allTypes ) );
- Iterable<Class<?>> mixinClasses = flatten( mixins, mixinDeclarations( this.types ) );
- implementMixinType( types, constraintClasses, concernClasses, sideEffectClasses, mixinClasses );
+ List<Class<?>> constraintClasses = toList( constraintDeclarations( this.types.stream() ) );
+ List<Class<?>> concernClasses = toList( concat( concerns.stream(), concernDeclarations( this.types.stream() ) ) );
+ List<Class<?>> sideEffectClasses = toList( concat( sideEffects.stream(), sideEffectDeclarations( this.types.stream() ) ) );
+ List<Class<?>> mixinClasses = toList( concat( mixins.stream(), mixinDeclarations( this.types.stream() ) ) );
+ //noinspection unchecked
+ implementMixinType( types,
+ constraintClasses,
+ concernClasses,
+ sideEffectClasses,
+ mixinClasses
+ );
// Add state from methods and fields
+ //noinspection unchecked
addState( constraintClasses );
}
+ private List<Class<?>> toList( Stream<Class<?>> stream )
+ {
+ return stream.collect( Collectors.toList() );
+ }
+
protected void addAnnotationsMetaInfo( Class<?> type, MetaInfo compositeMetaInfo )
{
Class[] declaredInterfaces = type.getInterfaces();
for( int i = declaredInterfaces.length - 1; i >= 0; i-- )
{
- addAnnotationsMetaInfo( declaredInterfaces[ i], compositeMetaInfo );
+ addAnnotationsMetaInfo( declaredInterfaces[ i ], compositeMetaInfo );
}
compositeMetaInfo.withAnnotations( type );
}
- protected void implementMixinType( Iterable<? extends Class<?>> types,
- Iterable<Class<? extends Constraint<?, ?>>> constraintClasses,
- Iterable<Class<?>> concernClasses,
- Iterable<Class<?>> sideEffectClasses,
- Iterable<Class<?>> mixinClasses
+ protected void implementMixinType( List<? extends Class<?>> types,
+ List<Class<?>> constraintClasses,
+ List<Class<?>> concernClasses,
+ List<Class<?>> sideEffectClasses,
+ List<Class<?>> mixinClasses
)
{
Set<Class<?>> thisDependencies = new HashSet<>();
- for( Class<?> mixinType : types )
- {
+ types.forEach( mixinType -> {
for( Method method : mixinType.getMethods() )
{
if( !compositeMethodsModel.isImplemented( method )
@@ -216,20 +215,20 @@ public abstract class CompositeAssemblyImpl
ConcernsModel concernsModel = concernsFor(
method,
mixinModel.mixinClass(),
- Iterables.<Class<?>>flatten( concernDeclarations( mixinModel.mixinClass() ),
- concernClasses )
+ concat( concernDeclarations( mixinModel.mixinClass() ),
+ concernClasses.stream() )
);
SideEffectsModel sideEffectsModel = sideEffectsFor(
method,
mixinModel.mixinClass(),
- Iterables.<Class<?>>flatten( sideEffectDeclarations( mixinModel.mixinClass() ),
- sideEffectClasses )
+ concat( sideEffectDeclarations( mixinModel.mixinClass() ),
+ sideEffectClasses.stream() )
);
method.setAccessible( true );
ConstraintsModel constraints = constraintsFor(
method,
- Iterables.<Class<? extends Constraint<?, ?>>>flatten( constraintDeclarations( mixinModel.mixinClass() ),
- constraintClasses )
+ toList( concat( constraintDeclarations( mixinModel.mixinClass() ),
+ constraintClasses.stream() ) )
);
CompositeMethodModel methodComposite = new CompositeMethodModel(
method,
@@ -239,60 +238,76 @@ public abstract class CompositeAssemblyImpl
mixinsModel
);
- // Implement @This references
- Iterable<Class<?>> map = map( new DependencyModel.InjectionTypeFunction(),
- filter( new DependencyModel.ScopeSpecification( This.class ),
- methodComposite.dependencies() ) );
- Iterable<Class<?>> map1 = map( new DependencyModel.InjectionTypeFunction(),
- filter( new DependencyModel.ScopeSpecification( This.class ),
- mixinModel.dependencies() ) );
- @SuppressWarnings( "unchecked" )
- Iterable<Class<?>> filter = filter(
- not( in( Initializable.class, Lifecycle.class, InvocationHandler.class ) ),
- map( Classes.RAW_CLASS, interfacesOf( mixinModel.mixinClass() ) )
- );
- Iterable<? extends Class<?>> flatten = flatten( map, map1, filter );
- addAll( thisDependencies, flatten );
+ DependencyModel.InjectionTypeFunction injectionTypeFunction = new DependencyModel.InjectionTypeFunction();
+ DependencyModel.ScopeSpecification thisSpec = new DependencyModel.ScopeSpecification( This.class );
+ Stream<? extends Dependencies> source = Stream.of( methodComposite, mixinModel );
+ source.flatMap( Dependencies::dependencies )
+ .filter( thisSpec )
+ .map( injectionTypeFunction )
+ .forEach( thisDependencies::add );
+
+ interfacesOf( mixinModel.mixinClass() )
+ .map( Classes.RAW_CLASS )
+ .filter( clazz -> Stream.of( Initializable.class, Lifecycle.class, InvocationHandler.class ).noneMatch( c -> c
+ .equals( clazz ) ) )
+ .forEach( thisDependencies::add );
+
+// // Implement @This references
+// Iterable<Class<?>> map = map( new DependencyModel.InjectionTypeFunction(),
+// filter( new DependencyModel.ScopeSpecification( This.class ),
+// methodComposite.dependencies() ) );
+// Iterable<Class<?>> map1 = map( new DependencyModel.InjectionTypeFunction(),
+// filter( new DependencyModel.ScopeSpecification( This.class ),
+// mixinModel.dependencies() ) );
+// @SuppressWarnings( "unchecked" )
+// Iterable<Class<?>> filter = filter(
+// not( in( Initializable.class, Lifecycle.class, InvocationHandler.class ) ),
+// map( Classes.RAW_CLASS, interfacesOf( mixinModel.mixinClass() ) )
+// );
+// Iterable<? extends Class<?>> flatten = flatten( map, map1, filter );
+// addAll( thisDependencies, flatten );
compositeMethodsModel.addMethod( methodComposite );
}
}
// Add type to set of mixin types
mixinsModel.addMixinType( mixinType );
- }
+ } );
// Implement all @This dependencies that were found
- for( Class<?> thisDependency : thisDependencies )
- {
+ thisDependencies.forEach( thisDependency -> {
// Add additional declarations from the @This type
- Iterable<Class<? extends Constraint<?, ?>>> typeConstraintClasses = flatten(
- constraintClasses,
+ Stream<Class<?>> typeConstraintClasses = concat(
+ constraintClasses.stream(),
constraintDeclarations( thisDependency ) );
- Iterable<Class<?>> typeConcernClasses = flatten(
- concernClasses,
+ Stream<Class<?>> typeConcernClasses = concat(
+ concernClasses.stream(),
concernDeclarations( thisDependency ) );
- Iterable<Class<?>> typeSideEffectClasses = flatten(
- sideEffectClasses,
+ Stream<Class<?>> typeSideEffectClasses = concat(
+ sideEffectClasses.stream(),
sideEffectDeclarations( thisDependency ) );
- Iterable<Class<?>> typeMixinClasses = flatten(
- mixinClasses,
+ Stream<Class<?>> typeMixinClasses = concat(
+ mixinClasses.stream(),
mixinDeclarations( thisDependency ) );
-
- @SuppressWarnings( "unchecked" )
- Iterable<? extends Class<?>> singleton = iterable( thisDependency );
- implementMixinType( singleton, typeConstraintClasses, typeConcernClasses, typeSideEffectClasses, typeMixinClasses );
- }
+ List<? extends Class<?>> singleton = Collections.singletonList( thisDependency );
+ implementMixinType( singleton,
+ toList(typeConstraintClasses),
+ toList(typeConcernClasses),
+ toList(typeSideEffectClasses),
+ toList(typeMixinClasses)
+ );
+ } );
}
@SuppressWarnings( "raw" )
- protected MixinModel implementMethod( Method method, Iterable<Class<?>> mixinDeclarations )
+ protected MixinModel implementMethod( Method method, List<Class<?>> mixinDeclarations )
{
MixinModel implementationModel = mixinsModel.mixinFor( method );
if( implementationModel != null )
{
return implementationModel;
}
- Class mixinClass = findTypedImplementation( method, mixinDeclarations );
+ Class mixinClass = findTypedImplementation( method, mixinDeclarations.stream() );
if( mixinClass != null )
{
return implementMethodWithClass( method, mixinClass );
@@ -309,37 +324,26 @@ public abstract class CompositeAssemblyImpl
+ "\nin\n " + types );
}
- @SuppressWarnings( {"raw", "unchecked"} )
- private Class findTypedImplementation( final Method method, Iterable<Class<?>> mixins )
+ @SuppressWarnings( { "raw", "unchecked" } )
+ private Class<?> findTypedImplementation( final Method method, Stream<Class<?>> mixins )
{
// Check if mixinClass implements the method. If so, check if the mixinClass is generic or if the filter passes.
// If a mixinClass is both generic AND non-generic at the same time, then the filter applies to the non-generic
// side only.
- Predicate<Class<?>> appliesToSpec = new Predicate<Class<?>>()
- {
- @Override
- public boolean test( Class<?> item )
- {
- return helper.appliesTo( item, method, types, item );
- }
- };
- return first( filter( and( isAssignableFrom( method.getDeclaringClass() ),
- or( Genericpredicate.INSTANCE, appliesToSpec ) ),
- mixins ) );
+ Predicate<Class<?>> appliesToSpec = item -> helper.appliesTo( item, method, types, item );
+ return mixins
+ .filter( isAssignableFrom( method.getDeclaringClass() )
+ .and( Genericpredicate.INSTANCE
+ .or( appliesToSpec ) ) )
+ .findFirst().orElse( null );
}
@SuppressWarnings( "unchecked" )
private Class<?> findGenericImplementation( final Method method, Iterable<Class<?>> mixins )
{
// Check if mixinClass is generic and the applies-to filter passes
- return first( filter( and( Genericpredicate.INSTANCE, new Predicate<Class<?>>()
- {
- @Override
- public boolean test( Class<?> item )
- {
- return helper.appliesTo( item, method, types, item );
- }
- } ), mixins ) );
+ return first( filter( Genericpredicate.INSTANCE
+ .and( item -> helper.appliesTo( item, method, types, item ) ), mixins ) );
}
private MixinModel implementMethodWithClass( Method method, Class mixinClass )
@@ -356,7 +360,7 @@ public abstract class CompositeAssemblyImpl
return mixinModel;
}
- protected void addState( final Iterable<Class<? extends Constraint<?, ?>>> constraintClasses )
+ protected void addState( final List<Class<?>> constraintClasses )
{
// Add method state
compositeMethodsModel.accept( new HierarchicalVisitorAdapter<Object, Object, RuntimeException>()
@@ -390,16 +394,8 @@ public abstract class CompositeAssemblyImpl
if( visited instanceof MixinModel )
{
MixinModel model = (MixinModel) visited;
- Consumer<Field> addState = new Consumer<Field>()
- {
- @Override
- public void accept( Field field )
- {
- addStateFor( field, constraintClasses );
- }
- };
- Iterable<Field> fields = Fields.FIELDS_OF.apply( model.mixinClass() );
- StreamSupport.stream( fields.spliterator(), true )
+ Consumer<Field> addState = field -> addStateFor( field, constraintClasses );
+ Fields.FIELDS_OF.apply( model.mixinClass() )
.filter( Annotations.hasAnnotation( State.class ) )
.forEach( addState );
return false;
@@ -410,7 +406,7 @@ public abstract class CompositeAssemblyImpl
}
protected void addStateFor( AccessibleObject accessor,
- Iterable<Class<? extends Constraint<?, ?>>> constraintClasses
+ List<Class<?>> constraintClasses
)
{
String stateName = QualifiedName.fromAccessor( accessor ).name();
@@ -428,11 +424,12 @@ public abstract class CompositeAssemblyImpl
}
protected PropertyModel newPropertyModel( AccessibleObject accessor,
- Iterable<Class<? extends Constraint<?, ?>>> constraintClasses
+ List<Class<?>> constraintClasses
)
{
- Iterable<Annotation> annotations = Annotations.findAccessorAndTypeAnnotationsIn( accessor );
- boolean optional = first( filter( isType( Optional.class ), annotations ) ) != null;
+ Stream<Annotation> annotations = Annotations.findAccessorAndTypeAnnotationsIn( accessor );
+ boolean optional = annotations.anyMatch( isType( Optional.class ) );
+ annotations = Annotations.findAccessorAndTypeAnnotationsIn( accessor );
ValueConstraintsModel valueConstraintsModel = constraintsFor(
annotations,
GenericPropertyInfo.propertyTypeOf( accessor ),
@@ -449,19 +446,18 @@ public abstract class CompositeAssemblyImpl
Object initialValue = stateDeclarations.initialValueOf( accessor );
boolean useDefaults = metaInfo.get( UseDefaults.class ) != null || stateDeclarations.useDefaults( accessor );
boolean immutable = this.immutable || metaInfo.get( Immutable.class ) != null;
- PropertyModel propertyModel = new PropertyModel(
+ return new PropertyModel(
accessor,
immutable,
useDefaults,
valueConstraintsInstance,
metaInfo,
initialValue );
- return propertyModel;
}
// Model
private ConstraintsModel constraintsFor( Method method,
- Iterable<Class<? extends Constraint<?, ?>>> constraintClasses
+ List<Class<?>> constraintClasses
)
{
List<ValueConstraintsModel> parameterConstraintModels = Collections.emptyList();
@@ -470,15 +466,15 @@ public abstract class CompositeAssemblyImpl
boolean constrained = false;
for( int i = 0; i < parameterAnnotations.length; i++ )
{
- Annotation[] parameterAnnotation = parameterAnnotations[i];
+ Annotation[] parameterAnnotation = parameterAnnotations[ i ];
Name nameAnnotation = (Name) first( filter( isType( Name.class ), iterable( parameterAnnotation ) ) );
String name = nameAnnotation == null ? "param" + ( i + 1 ) : nameAnnotation.value();
boolean optional = first( filter( isType( Optional.class ), iterable( parameterAnnotation ) ) ) != null;
ValueConstraintsModel parameterConstraintsModel = constraintsFor(
- asList( parameterAnnotation ),
- parameterTypes[i],
+ Arrays.stream( parameterAnnotation ),
+ parameterTypes[ i ],
name,
optional,
constraintClasses,
@@ -506,29 +502,32 @@ public abstract class CompositeAssemblyImpl
}
protected ValueConstraintsModel constraintsFor(
- Iterable<Annotation> constraintAnnotations,
+ Stream<Annotation> constraintAnnotations,
Type valueType,
String name,
boolean optional,
- Iterable<Class<? extends Constraint<?, ?>>> constraintClasses,
+ Iterable<Class<?>> constraintClasses,
AccessibleObject accessor
)
{
valueType = wrapperClass( valueType );
List<AbstractConstraintModel> constraintModels = new ArrayList<>();
- Iterable<Annotation> filter = filter( translate( type(), hasAnnotation( ConstraintDeclaration.class ) ),
- constraintAnnotations );
+ List<Annotation> filtered = constraintAnnotations
+ .filter( translate( type(), hasAnnotation( ConstraintDeclaration.class ) ) )
+ .collect( Collectors.toList() );
+
+ // TODO: This massive block below should be cleaned up.
nextConstraint:
- for( Annotation constraintAnnotation : filter )
+ for( Annotation constraintAnnotation : filtered )
{
// Check composite declarations first
Class<? extends Annotation> annotationType = constraintAnnotation.annotationType();
- for( Class<? extends Constraint<?, ?>> constraint : constraintClasses )
+ for( Class<?> constraint : constraintClasses )
{
- if( helper.appliesTo( constraint, annotationType, valueType ) )
+ if( helper.appliesTo( (Class<? extends Constraint<?, ?>>) constraint, annotationType, valueType ) )
{
- constraintModels.add( new ConstraintModel( constraintAnnotation, constraint ) );
+ constraintModels.add( new ConstraintModel( constraintAnnotation, (Class<? extends Constraint<?, ?>>) constraint ) );
continue nextConstraint;
}
}
@@ -549,11 +548,11 @@ public abstract class CompositeAssemblyImpl
// No implementation found!
// Check if if it's a composite constraints
- Iterable<Annotation> annotations = iterable( annotationType.getAnnotations() );
- if( matchesAny( translate( type(), hasAnnotation( ConstraintDeclaration.class ) ), annotations ) )
+ if( Arrays.stream( annotationType.getAnnotations() )
+ .anyMatch( translate( type(), hasAnnotation( ConstraintDeclaration.class ) ) ) )
{
ValueConstraintsModel valueConstraintsModel = constraintsFor(
- annotations,
+ Arrays.stream( annotationType.getAnnotations() ),
valueType,
name,
optional,
@@ -563,30 +562,29 @@ public abstract class CompositeAssemblyImpl
constraintAnnotation,
valueConstraintsModel );
constraintModels.add( compositeConstraintModel );
- continue nextConstraint;
}
-
- throw new InvalidCompositeException(
- "Cannot find implementation of constraint @"
- + annotationType.getSimpleName()
- + " for "
- + valueType
- + " in method "
- + ( (Member) accessor ).getName()
- + " of composite " + types );
+ else
+ {
+ throw new InvalidCompositeException(
+ "Cannot find implementation of constraint @"
+ + annotationType.getSimpleName()
+ + " for "
+ + valueType
+ + " in method "
+ + ( (Member) accessor ).getName()
+ + " of composite " + types );
+ }
}
-
return new ValueConstraintsModel( constraintModels, name, optional );
}
private ConcernsModel concernsFor( Method method,
Class<?> mixinClass,
- Iterable<Class<?>> concernClasses
+ Stream<Class<?>> concernClasses
)
{
List<ConcernModel> concernsFor = new ArrayList<>();
- for( Class<?> concern : concernClasses )
- {
+ concernClasses.forEach( concern -> {
if( helper.appliesTo( concern, method, types, mixinClass ) )
{
concernsFor.add( helper.getConcernModel( concern ) );
@@ -610,7 +608,7 @@ public abstract class CompositeAssemblyImpl
}
}
}
- }
+ } );
// Check annotations on method that have @Concerns annotations themselves
for( Annotation annotation : method.getAnnotations() )
@@ -641,12 +639,11 @@ public abstract class CompositeAssemblyImpl
private SideEffectsModel sideEffectsFor( Method method,
Class<?> mixinClass,
- Iterable<Class<?>> sideEffectClasses
+ Stream<Class<?>> sideEffectClasses
)
{
List<SideEffectModel> sideEffectsFor = new ArrayList<>();
- for( Class<?> sideEffect : sideEffectClasses )
- {
+ sideEffectClasses.forEach( sideEffect -> {
if( helper.appliesTo( sideEffect, method, types, mixinClass ) )
{
sideEffectsFor.add( helper.getSideEffectModel( sideEffect ) );
@@ -670,7 +667,7 @@ public abstract class CompositeAssemblyImpl
}
}
}
- }
+ } );
if( sideEffectsFor.isEmpty() )
{
@@ -683,156 +680,75 @@ public abstract class CompositeAssemblyImpl
}
@SuppressWarnings( "unchecked" )
- private Iterable<Class<? extends Constraint<?, ?>>> constraintDeclarations( Class<?> type )
+ private Stream<Class<?>> constraintDeclarations( Class<?> type )
{
- ArrayList<Type> allTypes = getTypes( type );
- return constraintDeclarations( allTypes );
+ Stream<? extends Type> types = getTypes( type );
+ return constraintDeclarations( types );
}
- private Iterable<Class<? extends Constraint<?, ?>>> constraintDeclarations( ArrayList<Type> allTypes )
+ private Stream<Class<?>> constraintDeclarations( Stream<? extends Type> types )
{
- // Find all constraints and flatten them into an iterable
- Function<Type, Iterable<Class<? extends Constraint<?, ?>>>> function = new Function<Type, Iterable<Class<? extends Constraint<?, ?>>>>()
- {
- @Override
- public Iterable<Class<? extends Constraint<?, ?>>> apply( Type type )
- {
- Constraints constraints = Annotations.annotationOn( type, Constraints.class );
- if( constraints == null )
- {
- return empty();
- }
- else
- {
- return iterable( constraints.value() );
- }
- }
- };
- Iterable<Class<? extends Constraint<?, ?>>> flatten = flattenIterables( map( function, allTypes ) );
- return toList( flatten );
+ return types
+ .filter( mixinType -> Annotations.annotationOn( mixinType, Constraints.class ) != null )
+ .flatMap( mixinType -> Arrays.stream( Annotations.annotationOn( mixinType, Constraints.class ).value() ) );
}
@SuppressWarnings( "unchecked" )
- private Iterable<Class<?>> concernDeclarations( Class<?> type )
+ private Stream<Class<?>> concernDeclarations( Class<?> type )
{
- Iterable<? extends Class<?>> iterable = iterable( type );
- return concernDeclarations( getTypes( iterable ) );
+ Stream<? extends Type> types = getTypes( type );
+ return concernDeclarations( types );
}
- private Iterable<Class<?>> concernDeclarations( ArrayList<Type> allTypes )
+ private Stream<Class<?>> concernDeclarations( Stream<? extends Type> types )
{
- // Find all concerns and flattern them into an iterable
- Function<Type, Iterable<Class<?>>> function = new Function<Type, Iterable<Class<?>>>()
- {
- @Override
- public Iterable<Class<?>> apply( Type type )
- {
- Concerns concerns = Annotations.annotationOn( type, Concerns.class );
- if( concerns == null )
- {
- return empty();
- }
- else
- {
- return iterable( concerns.value() );
- }
- }
- };
- Iterable<Class<?>> flatten = flattenIterables( map( function, allTypes ) );
- return toList( flatten );
+ return types
+ .filter( mixinType -> Annotations.annotationOn( mixinType, Concerns.class ) != null )
+ .flatMap( mixinType -> Arrays.stream( Annotations.annotationOn( mixinType, Concerns.class ).value() ) );
}
@SuppressWarnings( "unchecked" )
- protected Iterable<Class<?>> sideEffectDeclarations( Class<?> type )
+ protected Stream<Class<?>> sideEffectDeclarations( Class<?> type )
{
- Iterable<? extends Class<?>> iterable = iterable( type );
- return sideEffectDeclarations( getTypes( iterable ) );
- }
-
- protected Iterable<Class<?>> sideEffectDeclarations( ArrayList<Type> allTypes )
- {
- // Find all side-effects and flattern them into an iterable
- Function<Type, Iterable<Class<?>>> function = new Function<Type, Iterable<Class<?>>>()
- {
- @Override
- public Iterable<Class<?>> apply( Type type )
- {
- SideEffects sideEffects = Annotations.annotationOn( type, SideEffects.class );
- if( sideEffects == null )
- {
- return empty();
- }
- else
- {
- return iterable( sideEffects.value() );
- }
- }
- };
- Iterable<Class<?>> flatten = flattenIterables( map( function, allTypes ) );
- return toList( flatten );
+ Stream<? extends Type> types = getTypes( type );
+ return sideEffectDeclarations( types );
}
- private ArrayList<Type> getTypes( Class<?> type )
+ private Stream<Class<?>> sideEffectDeclarations( Stream<? extends Type> types )
{
- Iterable<? extends Class<?>> iterable = iterable( type );
- return getTypes( iterable );
+ return types
+ .filter( mixinType -> Annotations.annotationOn( mixinType, SideEffects.class ) != null )
+ .flatMap( mixinType -> Arrays.stream( Annotations.annotationOn( mixinType, SideEffects.class ).value() ) );
}
- private ArrayList<Type> getTypes( Iterable<? extends Class<?>> typess )
+ private Stream<? extends Type> getTypes( Type type )
{
- // Find side-effect declarations
- ArrayList<Type> allTypes = new ArrayList<>();
- for( Class<?> type : typess )
+ if( type instanceof Class )
{
- Iterable<Type> types;
- if( type.isInterface() )
+ Class<?> clazz = (Class<?>) type;
+ if( clazz.isInterface() )
{
- types = typesOf( type );
+ return typesOf( clazz );
}
else
{
- types = cast( classHierarchy( type ) );
+ return classHierarchy( clazz );
}
- addAll( allTypes, types );
}
- return allTypes;
+ throw new UnsupportedOperationException( "Unable to handle type " + type.getTypeName() );
}
@SuppressWarnings( "unchecked" )
- protected Iterable<Class<?>> mixinDeclarations( Class<?> type )
+ protected Stream<Class<?>> mixinDeclarations( Class<?> type )
{
- Iterable<? extends Class<?>> iterable = iterable( type );
- return mixinDeclarations( iterable );
+ Stream<? extends Type> types = getTypes( type );
+ return mixinDeclarations( types );
}
- protected Iterable<Class<?>> mixinDeclarations( Iterable<? extends Class<?>> typess )
+ private Stream<Class<?>> mixinDeclarations( Stream<? extends Type> types )
{
- // Find mixin declarations
- ArrayList<Type> allTypes = new ArrayList<>();
- for( Class<?> type : typess )
- {
- Iterable<Type> types = typesOf( type );
- addAll( allTypes, types );
- }
-
- // Find all mixins and flattern them into an iterable
- Function<Type, Iterable<Class<?>>> function = new Function<Type, Iterable<Class<?>>>()
- {
- @Override
- public Iterable<Class<?>> apply( Type type )
- {
- Mixins mixins = Annotations.annotationOn( type, Mixins.class );
- if( mixins == null )
- {
- return empty();
- }
- else
- {
- return iterable( mixins.value() );
- }
- }
- };
- Iterable<Class<?>> flatten = flattenIterables( map( function, allTypes ) );
- return toList( flatten );
+ return types.flatMap( this::getTypes )
+ .filter( mixinType -> Annotations.annotationOn( mixinType, Mixins.class ) != null )
+ .flatMap( mixinType -> Arrays.stream( Annotations.annotationOn( mixinType, Mixins.class ).value() ) );
}
}
http://git-wip-us.apache.org/repos/asf/zest-java/blob/bd6fbad9/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ConfigurationAssemblyImpl.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ConfigurationAssemblyImpl.java b/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ConfigurationAssemblyImpl.java
index f755d85..37403b5 100644
--- a/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ConfigurationAssemblyImpl.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ConfigurationAssemblyImpl.java
@@ -17,6 +17,7 @@
*/
package org.apache.zest.runtime.bootstrap;
+import java.util.stream.Stream;
import org.apache.zest.bootstrap.ConfigurationAssembly;
/**
@@ -35,7 +36,7 @@ public final class ConfigurationAssemblyImpl
}
@Override
- public Iterable<Class<?>> types()
+ public Stream<Class<?>> types()
{
return value.types();
}
http://git-wip-us.apache.org/repos/asf/zest-java/blob/bd6fbad9/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/EntityAssemblyImpl.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/EntityAssemblyImpl.java b/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/EntityAssemblyImpl.java
index 23c0eb6..473ab07 100644
--- a/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/EntityAssemblyImpl.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/EntityAssemblyImpl.java
@@ -21,6 +21,8 @@ package org.apache.zest.runtime.bootstrap;
import java.lang.annotation.Annotation;
import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Member;
+import java.util.List;
+import java.util.stream.Stream;
import org.apache.zest.api.association.Association;
import org.apache.zest.api.association.GenericAssociationInfo;
import org.apache.zest.api.association.ManyAssociation;
@@ -30,7 +32,6 @@ import org.apache.zest.api.common.MetaInfo;
import org.apache.zest.api.common.Optional;
import org.apache.zest.api.common.QualifiedName;
import org.apache.zest.api.common.UseDefaults;
-import org.apache.zest.api.constraint.Constraint;
import org.apache.zest.api.entity.EntityComposite;
import org.apache.zest.api.property.GenericPropertyInfo;
import org.apache.zest.api.property.Immutable;
@@ -59,8 +60,6 @@ import org.apache.zest.runtime.property.PropertyModel;
import static org.apache.zest.api.util.Annotations.isType;
import static org.apache.zest.api.util.Classes.typeOf;
-import static org.apache.zest.functional.Iterables.filter;
-import static org.apache.zest.functional.Iterables.first;
/**
* Declaration of a EntityComposite.
@@ -116,10 +115,9 @@ public final class EntityAssemblyImpl
namedAssociationsModel = new NamedAssociationsModel();
buildComposite( helper, stateDeclarations );
- EntityModel entityModel = new EntityModel(
- types, visibility, metaInfo, (EntityMixinsModel) mixinsModel, (EntityStateModel) stateModel, compositeMethodsModel );
-
- return entityModel;
+ return new EntityModel( types, visibility, metaInfo,
+ (EntityMixinsModel) mixinsModel,
+ (EntityStateModel) stateModel, compositeMethodsModel );
}
catch( Exception e )
{
@@ -128,9 +126,7 @@ public final class EntityAssemblyImpl
}
@Override
- protected void addStateFor( AccessibleObject accessor,
- Iterable<Class<? extends Constraint<?, ?>>> constraintClasses
- )
+ protected void addStateFor( AccessibleObject accessor, List<Class<?>> constraintClasses )
{
String stateName = QualifiedName.fromAccessor( accessor ).name();
@@ -164,11 +160,12 @@ public final class EntityAssemblyImpl
@Override
protected PropertyModel newPropertyModel( AccessibleObject accessor,
- Iterable<Class<? extends Constraint<?, ?>>> constraintClasses
+ List<Class<?>> constraintClasses
)
{
- Iterable<Annotation> annotations = Annotations.findAccessorAndTypeAnnotationsIn( accessor );
- boolean optional = first( filter( isType( Optional.class ), annotations ) ) != null;
+ Stream<Annotation> annotations = Annotations.findAccessorAndTypeAnnotationsIn( accessor );
+ boolean optional = annotations.anyMatch( isType( Optional.class ) );
+ annotations = Annotations.findAccessorAndTypeAnnotationsIn( accessor );
ValueConstraintsModel valueConstraintsModel = constraintsFor( annotations, GenericPropertyInfo.propertyTypeOf( accessor ), ( (Member) accessor )
.getName(), optional, constraintClasses, accessor );
ValueConstraintsInstance valueConstraintsInstance = null;
@@ -180,16 +177,16 @@ public final class EntityAssemblyImpl
Object defaultValue = stateDeclarations.initialValueOf( accessor );
boolean useDefaults = metaInfo.get( UseDefaults.class ) != null || stateDeclarations.useDefaults( accessor );
boolean immutable = this.immutable || metaInfo.get( Immutable.class ) != null;
- PropertyModel propertyModel = new PropertyModel( accessor, immutable, useDefaults, valueConstraintsInstance, metaInfo, defaultValue );
- return propertyModel;
+ return new PropertyModel( accessor, immutable, useDefaults, valueConstraintsInstance, metaInfo, defaultValue );
}
public AssociationModel newAssociationModel( AccessibleObject accessor,
- Iterable<Class<? extends Constraint<?, ?>>> constraintClasses
+ Iterable<Class<?>> constraintClasses
)
{
- Iterable<Annotation> annotations = Annotations.findAccessorAndTypeAnnotationsIn( accessor );
- boolean optional = first( filter( isType( Optional.class ), annotations ) ) != null;
+ Stream<Annotation> annotations = Annotations.findAccessorAndTypeAnnotationsIn( accessor );
+ boolean optional = annotations.anyMatch( isType( Optional.class ) );
+ annotations = Annotations.findAccessorAndTypeAnnotationsIn( accessor );
// Constraints for Association references
ValueConstraintsModel valueConstraintsModel = constraintsFor( annotations, GenericAssociationInfo
@@ -209,16 +206,16 @@ public final class EntityAssemblyImpl
}
MetaInfo metaInfo = associationDeclarations.metaInfoFor( accessor );
- AssociationModel associationModel = new AssociationModel( accessor, valueConstraintsInstance, associationValueConstraintsInstance, metaInfo );
- return associationModel;
+ return new AssociationModel( accessor, valueConstraintsInstance, associationValueConstraintsInstance, metaInfo );
}
public ManyAssociationModel newManyAssociationModel( AccessibleObject accessor,
- Iterable<Class<? extends Constraint<?, ?>>> constraintClasses
+ List<Class<?>> constraintClasses
)
{
- Iterable<Annotation> annotations = Annotations.findAccessorAndTypeAnnotationsIn( accessor );
- boolean optional = first( filter( isType( Optional.class ), annotations ) ) != null;
+ Stream<Annotation> annotations = Annotations.findAccessorAndTypeAnnotationsIn( accessor );
+ boolean optional = annotations.anyMatch( isType( Optional.class ) );
+ annotations = Annotations.findAccessorAndTypeAnnotationsIn( accessor );
// Constraints for entities in ManyAssociation
ValueConstraintsModel valueConstraintsModel = constraintsFor( annotations, GenericAssociationInfo
@@ -237,16 +234,16 @@ public final class EntityAssemblyImpl
manyValueConstraintsInstance = valueConstraintsModel.newInstance();
}
MetaInfo metaInfo = manyAssociationDeclarations.metaInfoFor( accessor );
- ManyAssociationModel associationModel = new ManyAssociationModel( accessor, valueConstraintsInstance, manyValueConstraintsInstance, metaInfo );
- return associationModel;
+ return new ManyAssociationModel( accessor, valueConstraintsInstance, manyValueConstraintsInstance, metaInfo );
}
public NamedAssociationModel newNamedAssociationModel( AccessibleObject accessor,
- Iterable<Class<? extends Constraint<?, ?>>> constraintClasses
+ List<Class<?>> constraintClasses
)
{
- Iterable<Annotation> annotations = Annotations.findAccessorAndTypeAnnotationsIn( accessor );
- boolean optional = first( filter( isType( Optional.class ), annotations ) ) != null;
+ Stream<Annotation> annotations = Annotations.findAccessorAndTypeAnnotationsIn( accessor );
+ boolean optional = annotations.anyMatch( isType( Optional.class ) );
+ annotations = Annotations.findAccessorAndTypeAnnotationsIn( accessor );
// Constraints for entities in NamedAssociation
ValueConstraintsModel valueConstraintsModel = constraintsFor( annotations, GenericAssociationInfo
@@ -265,7 +262,6 @@ public final class EntityAssemblyImpl
namedValueConstraintsInstance = valueConstraintsModel.newInstance();
}
MetaInfo metaInfo = namedAssociationDeclarations.metaInfoFor( accessor );
- NamedAssociationModel associationModel = new NamedAssociationModel( accessor, valueConstraintsInstance, namedValueConstraintsInstance, metaInfo );
- return associationModel;
+ return new NamedAssociationModel( accessor, valueConstraintsInstance, namedValueConstraintsInstance, metaInfo );
}
}
http://git-wip-us.apache.org/repos/asf/zest-java/blob/bd6fbad9/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ImportedServiceAssemblyImpl.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ImportedServiceAssemblyImpl.java b/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ImportedServiceAssemblyImpl.java
index a07b4f8..e7dd04f 100644
--- a/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ImportedServiceAssemblyImpl.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ImportedServiceAssemblyImpl.java
@@ -17,6 +17,7 @@ package org.apache.zest.runtime.bootstrap;
import java.util.ArrayList;
import java.util.List;
+import java.util.stream.Stream;
import org.apache.zest.api.activation.Activator;
import org.apache.zest.api.common.InvalidApplicationException;
import org.apache.zest.api.common.MetaInfo;
@@ -24,7 +25,6 @@ import org.apache.zest.api.common.Visibility;
import org.apache.zest.api.service.ServiceImporter;
import org.apache.zest.api.service.importer.InstanceImporter;
import org.apache.zest.bootstrap.ImportedServiceAssembly;
-import org.apache.zest.functional.Iterables;
import org.apache.zest.runtime.activation.ActivatorsModel;
import org.apache.zest.runtime.service.ImportedServiceModel;
@@ -53,12 +53,12 @@ public final class ImportedServiceAssemblyImpl
}
@Override
- public Iterable<Class<?>> types()
+ public Stream<Class<?>> types()
{
- return Iterables.<Class<?>>iterable( serviceType );
+ return Stream.of( serviceType );
}
- @SuppressWarnings( {"raw", "unchecked"} )
+ @SuppressWarnings( { "raw", "unchecked" } )
void addImportedServiceModel( List<ImportedServiceModel> serviceModels )
{
try
http://git-wip-us.apache.org/repos/asf/zest-java/blob/bd6fbad9/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ModuleAssemblyImpl.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ModuleAssemblyImpl.java b/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ModuleAssemblyImpl.java
index 6f072de..dd5318c 100644
--- a/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ModuleAssemblyImpl.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ModuleAssemblyImpl.java
@@ -23,6 +23,8 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Predicate;
+import java.util.stream.Stream;
+import java.util.stream.StreamSupport;
import org.apache.zest.api.activation.Activator;
import org.apache.zest.api.common.MetaInfo;
import org.apache.zest.api.common.Visibility;
@@ -56,7 +58,6 @@ import org.apache.zest.bootstrap.TransientDeclaration;
import org.apache.zest.bootstrap.ValueAssembly;
import org.apache.zest.bootstrap.ValueDeclaration;
import org.apache.zest.functional.Iterables;
-import org.apache.zest.functional.Specifications;
import org.apache.zest.runtime.activation.ActivatorsModel;
import org.apache.zest.runtime.composite.TransientModel;
import org.apache.zest.runtime.composite.TransientsModel;
@@ -72,7 +73,6 @@ import org.apache.zest.runtime.structure.ModuleModel;
import org.apache.zest.runtime.value.ValueModel;
import org.apache.zest.runtime.value.ValuesModel;
-import static org.apache.zest.functional.Iterables.first;
import static org.apache.zest.functional.Iterables.iterable;
/**
@@ -145,7 +145,7 @@ public final class ModuleAssemblyImpl
}
@Override
- @SuppressWarnings( {"raw", "unchecked"} )
+ @SuppressWarnings( { "raw", "unchecked" } )
public ValueDeclaration values( Class<?>... valueTypes )
{
List<ValueAssemblyImpl> assemblies = new ArrayList<>();
@@ -183,7 +183,7 @@ public final class ModuleAssemblyImpl
}
@Override
- @SuppressWarnings( {"raw", "unchecked"} )
+ @SuppressWarnings( { "raw", "unchecked" } )
public TransientDeclaration transients( Class<?>... transientTypes )
{
List<TransientAssemblyImpl> assemblies = new ArrayList<>();
@@ -221,7 +221,7 @@ public final class ModuleAssemblyImpl
}
@Override
- @SuppressWarnings( {"raw", "unchecked"} )
+ @SuppressWarnings( { "raw", "unchecked" } )
public EntityDeclaration entities( Class<?>... entityTypes )
{
List<EntityAssemblyImpl> assemblies = new ArrayList<>();
@@ -294,14 +294,14 @@ public final class ModuleAssemblyImpl
}
}
- return new ConfigurationDeclarationImpl( entityAssemblyList, valueAssemblyList );
+ return new ConfigurationDeclarationImpl( entityAssemblyList, valueAssemblyList );
}
@Override
public ConfigurationDeclaration configurations( Predicate<HasTypes> specification )
{
Predicate<HasTypes> isConfigurationComposite = new MatchTypeSpecification( Identity.class );
- specification = Specifications.and( specification, isConfigurationComposite );
+ specification = specification.and( isConfigurationComposite );
List<EntityAssemblyImpl> entityAssmblyList = new ArrayList<>();
for( EntityAssemblyImpl entityAssembly : entityAssemblies.values() )
{
@@ -385,9 +385,9 @@ public final class ModuleAssemblyImpl
for( Class<?> serviceType : serviceTypes )
{
- if( Iterables.matchesAny( AssemblySpecifications.types( serviceType ), serviceAssemblies ) )
+ if( Iterables.matchesAny( AssemblySpecifications.ofAnyType( serviceType ), serviceAssemblies ) )
{
- Iterables.addAll( assemblies, Iterables.filter( AssemblySpecifications.types( serviceType ), serviceAssemblies ) );
+ Iterables.addAll( assemblies, Iterables.filter( AssemblySpecifications.ofAnyType( serviceType ), serviceAssemblies ) );
}
else
{
@@ -522,10 +522,10 @@ public final class ModuleAssemblyImpl
List<EntityModel> entityModels = new ArrayList<>();
for( EntityAssemblyImpl entityDeclaration : entityAssemblies.values() )
{
- entityModels.add( entityDeclaration.newEntityModel( metaInfoDeclaration,
- metaInfoDeclaration,
- metaInfoDeclaration,
- metaInfoDeclaration,
+ entityModels.add( entityDeclaration.newEntityModel( metaInfoDeclaration,
+ metaInfoDeclaration,
+ metaInfoDeclaration,
+ metaInfoDeclaration,
helper ) );
}
@@ -586,18 +586,11 @@ public final class ModuleAssemblyImpl
for( ImportedServiceModel importedServiceModel : importedServiceModels )
{
- boolean found = false;
- for( ObjectModel objectModel : objectModels )
+ if( StreamSupport.stream( objectModels.spliterator(), false )
+ .anyMatch( model ->
+ model.types().findFirst().get().equals( importedServiceModel.serviceImporter() ) )
+ )
{
- if( first( objectModel.types() ).equals( importedServiceModel.serviceImporter() ) )
- {
- found = true;
- break;
- }
- }
- if( !found )
- {
- @SuppressWarnings( "raw" )
Class<? extends ServiceImporter> serviceFactoryType = importedServiceModel.serviceImporter();
ObjectModel objectModel = new ObjectModel( serviceFactoryType, Visibility.module, new MetaInfo() );
objectModels.add( objectModel );
@@ -607,11 +600,10 @@ public final class ModuleAssemblyImpl
return moduleModel;
}
- private String generateId( Iterable<Class<?>> serviceTypes )
+ private String generateId( Stream<Class<?>> serviceTypes )
{
// Find service identity that is not yet used
- Class<?> serviceType = serviceTypes.iterator()
- .next(); // Use the first Iterable, which *SHOULD* be the main serviceType
+ Class<?> serviceType = serviceTypes.findFirst().orElse( null ); // Use the first, which *SHOULD* be the main serviceType
int idx = 0;
String id = serviceType.getSimpleName();
boolean invalid;
http://git-wip-us.apache.org/repos/asf/zest-java/blob/bd6fbad9/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ObjectAssemblyImpl.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ObjectAssemblyImpl.java b/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ObjectAssemblyImpl.java
index f4fdd9c..778ffef 100644
--- a/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ObjectAssemblyImpl.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ObjectAssemblyImpl.java
@@ -16,12 +16,12 @@ package org.apache.zest.runtime.bootstrap;
import java.lang.reflect.Modifier;
import java.util.List;
+import java.util.stream.Stream;
import org.apache.zest.api.common.InvalidApplicationException;
import org.apache.zest.api.common.MetaInfo;
import org.apache.zest.api.common.Visibility;
import org.apache.zest.api.composite.Composite;
import org.apache.zest.bootstrap.ObjectAssembly;
-import org.apache.zest.functional.Iterables;
import org.apache.zest.runtime.object.ObjectModel;
/**
@@ -46,9 +46,9 @@ public final class ObjectAssemblyImpl
}
@Override
- public Iterable<Class<?>> types()
+ public Stream<Class<?>> types()
{
- return Iterables.<Class<?>>iterable( objectType );
+ return Stream.of( objectType );
}
void addObjectModel( List<ObjectModel> objectModels )
http://git-wip-us.apache.org/repos/asf/zest-java/blob/bd6fbad9/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ServiceAssemblyImpl.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ServiceAssemblyImpl.java b/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ServiceAssemblyImpl.java
index fc1e91b..825ebe4 100644
--- a/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ServiceAssemblyImpl.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ServiceAssemblyImpl.java
@@ -16,8 +16,10 @@ package org.apache.zest.runtime.bootstrap;
import java.lang.reflect.Type;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
-import java.util.function.Function;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
import org.apache.zest.api.activation.Activator;
import org.apache.zest.api.activation.Activators;
import org.apache.zest.api.common.InvalidApplicationException;
@@ -56,14 +58,14 @@ public final class ServiceAssemblyImpl extends CompositeAssemblyImpl
return identity;
}
- @SuppressWarnings( {"raw", "unchecked"} )
+ @SuppressWarnings( { "raw", "unchecked" } )
ServiceModel newServiceModel( StateDeclarations stateDeclarations, AssemblyHelper helper )
{
try
{
buildComposite( helper, stateDeclarations );
List<Class<? extends Activator<?>>> activatorClasses = Iterables.toList(
- Iterables.<Class<? extends Activator<?>>>flatten( activators, activatorsDeclarations( types ) ) );
+ Iterables.<Class<? extends Activator<?>>>flatten( activators, activatorsDeclarations( types.stream() ) ) );
return new ServiceModel( types, visibility, metaInfo,
new ActivatorsModel( activatorClasses ),
mixinsModel, stateModel, compositeMethodsModel,
@@ -74,35 +76,22 @@ public final class ServiceAssemblyImpl extends CompositeAssemblyImpl
throw new InvalidApplicationException( "Could not register " + types, e );
}
}
-
- private Iterable<Class<? extends Activator<?>>> activatorsDeclarations( Iterable<? extends Class<?>> typess )
+
+ private Iterable<Class<? extends Activator<?>>> activatorsDeclarations( Stream<? extends Class<?>> typess )
+ {
+ return typess.flatMap( Classes::typesOf )
+ .filter( type -> Annotations.annotationOn( type, Activators.class ) == null )
+ .flatMap( this::getAnnotations )
+ .collect( Collectors.toList() );
+ }
+
+ private Stream<? extends Class<? extends Activator<?>>> getAnnotations( Type type )
{
- // Find activator declarations
- ArrayList<Type> allTypes = new ArrayList<>();
- for( Class<?> type : typess )
+ Activators activators1 = Annotations.annotationOn( type, Activators.class );
+ if( activators1 == null )
{
- Iterable<Type> types = Classes.typesOf( type );
- Iterables.addAll( allTypes, types );
+ return Stream.empty();
}
- // Find all activators and flattern them into an iterable
- Function<Type, Iterable<Class<? extends Activator<?>>>> function = new Function<Type, Iterable<Class<? extends Activator<?>>>>()
- {
- @Override
- public Iterable<Class<? extends Activator<?>>> apply( Type type )
- {
- Activators activators = Annotations.annotationOn( type, Activators.class );
- if( activators == null )
- {
- return Iterables.empty();
- }
- else
- {
- return Iterables.iterable( activators.value() );
- }
- }
- };
- Iterable<Class<? extends Activator<?>>> flatten = Iterables.flattenIterables( Iterables.map( function, allTypes ) );
- return Iterables.toList( flatten );
+ return Arrays.stream( activators1.value() );
}
-
}
http://git-wip-us.apache.org/repos/asf/zest-java/blob/bd6fbad9/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ValueAssemblyImpl.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ValueAssemblyImpl.java b/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ValueAssemblyImpl.java
index e3d9c5d..38e3b2c 100644
--- a/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ValueAssemblyImpl.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ValueAssemblyImpl.java
@@ -21,6 +21,8 @@ package org.apache.zest.runtime.bootstrap;
import java.lang.annotation.Annotation;
import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Member;
+import java.util.List;
+import java.util.stream.Stream;
import org.apache.zest.api.association.Association;
import org.apache.zest.api.association.GenericAssociationInfo;
import org.apache.zest.api.association.ManyAssociation;
@@ -30,7 +32,6 @@ import org.apache.zest.api.common.MetaInfo;
import org.apache.zest.api.common.Optional;
import org.apache.zest.api.common.QualifiedName;
import org.apache.zest.api.common.UseDefaults;
-import org.apache.zest.api.constraint.Constraint;
import org.apache.zest.api.property.GenericPropertyInfo;
import org.apache.zest.api.property.Property;
import org.apache.zest.api.util.Annotations;
@@ -53,8 +54,6 @@ import org.apache.zest.runtime.value.ValueStateModel;
import static org.apache.zest.api.util.Annotations.isType;
import static org.apache.zest.api.util.Classes.typeOf;
-import static org.apache.zest.functional.Iterables.filter;
-import static org.apache.zest.functional.Iterables.first;
/**
* Declaration of a ValueComposite.
@@ -95,10 +94,8 @@ public final class ValueAssemblyImpl
namedAssociationsModel = new NamedAssociationsModel();
buildComposite( helper, stateDeclarations );
- ValueModel valueModel = new ValueModel(
+ return new ValueModel(
types, visibility, metaInfo, mixinsModel, (ValueStateModel) stateModel, compositeMethodsModel );
-
- return valueModel;
}
catch( Exception e )
{
@@ -108,7 +105,7 @@ public final class ValueAssemblyImpl
@Override
protected void addStateFor( AccessibleObject accessor,
- Iterable<Class<? extends Constraint<?, ?>>> constraintClasses
+ List<Class<?>> constraintClasses
)
{
String stateName = QualifiedName.fromAccessor( accessor ).name();
@@ -143,11 +140,12 @@ public final class ValueAssemblyImpl
@Override
protected PropertyModel newPropertyModel( AccessibleObject accessor,
- Iterable<Class<? extends Constraint<?, ?>>> constraintClasses
+ List<Class<?>> constraintClasses
)
{
- Iterable<Annotation> annotations = Annotations.findAccessorAndTypeAnnotationsIn( accessor );
- boolean optional = first( filter( isType( Optional.class ), annotations ) ) != null;
+ Stream<Annotation> annotations = Annotations.findAccessorAndTypeAnnotationsIn( accessor );
+ boolean optional = annotations.anyMatch( isType( Optional.class ) );
+ annotations = Annotations.findAccessorAndTypeAnnotationsIn( accessor );
ValueConstraintsModel valueConstraintsModel = constraintsFor( annotations, GenericPropertyInfo.propertyTypeOf( accessor ), ( (Member) accessor )
.getName(), optional, constraintClasses, accessor );
ValueConstraintsInstance valueConstraintsInstance = null;
@@ -162,11 +160,11 @@ public final class ValueAssemblyImpl
}
public AssociationModel newAssociationModel( AccessibleObject accessor,
- Iterable<Class<? extends Constraint<?, ?>>> constraintClasses
+ List<Class<?>> constraintClasses
)
{
- Iterable<Annotation> annotations = Annotations.findAccessorAndTypeAnnotationsIn( accessor );
- boolean optional = first( filter( isType( Optional.class ), annotations ) ) != null;
+ Stream<Annotation> annotations = Annotations.findAccessorAndTypeAnnotationsIn( accessor );
+ boolean optional = annotations.anyMatch( isType( Optional.class ) );
// Constraints for Association references
ValueConstraintsModel valueConstraintsModel = constraintsFor( annotations, GenericAssociationInfo
@@ -186,16 +184,15 @@ public final class ValueAssemblyImpl
}
MetaInfo metaInfo = stateDeclarations.metaInfoFor( accessor );
- AssociationModel associationModel = new AssociationModel( accessor, valueConstraintsInstance, associationValueConstraintsInstance, metaInfo );
- return associationModel;
+ return new AssociationModel( accessor, valueConstraintsInstance, associationValueConstraintsInstance, metaInfo );
}
public ManyAssociationModel newManyAssociationModel( AccessibleObject accessor,
- Iterable<Class<? extends Constraint<?, ?>>> constraintClasses
+ List<Class<?>> constraintClasses
)
{
- Iterable<Annotation> annotations = Annotations.findAccessorAndTypeAnnotationsIn( accessor );
- boolean optional = first( filter( isType( Optional.class ), annotations ) ) != null;
+ Stream<Annotation> annotations = Annotations.findAccessorAndTypeAnnotationsIn( accessor );
+ boolean optional = annotations.anyMatch( isType( Optional.class ) );
// Constraints for entities in ManyAssociation
ValueConstraintsModel valueConstraintsModel = constraintsFor( annotations, GenericAssociationInfo
@@ -214,16 +211,15 @@ public final class ValueAssemblyImpl
manyValueConstraintsInstance = valueConstraintsModel.newInstance();
}
MetaInfo metaInfo = stateDeclarations.metaInfoFor( accessor );
- ManyAssociationModel associationModel = new ManyAssociationModel( accessor, valueConstraintsInstance, manyValueConstraintsInstance, metaInfo );
- return associationModel;
+ return new ManyAssociationModel( accessor, valueConstraintsInstance, manyValueConstraintsInstance, metaInfo );
}
-
+
public NamedAssociationModel newNamedAssociationModel( AccessibleObject accessor,
- Iterable<Class<? extends Constraint<?, ?>>> constraintClasses
+ List<Class<?>> constraintClasses
)
{
- Iterable<Annotation> annotations = Annotations.findAccessorAndTypeAnnotationsIn( accessor );
- boolean optional = first( filter( isType( Optional.class ), annotations ) ) != null;
+ Stream<Annotation> annotations = Annotations.findAccessorAndTypeAnnotationsIn( accessor );
+ boolean optional = annotations.anyMatch( isType( Optional.class ) );
// Constraints for entities in NamedAssociation
ValueConstraintsModel valueConstraintsModel = constraintsFor( annotations, GenericAssociationInfo
@@ -242,7 +238,6 @@ public final class ValueAssemblyImpl
namedValueConstraintsInstance = valueConstraintsModel.newInstance();
}
MetaInfo metaInfo = stateDeclarations.metaInfoFor( accessor );
- NamedAssociationModel associationModel = new NamedAssociationModel( accessor, valueConstraintsInstance, namedValueConstraintsInstance, metaInfo );
- return associationModel;
+ return new NamedAssociationModel( accessor, valueConstraintsInstance, namedValueConstraintsInstance, metaInfo );
}
}
http://git-wip-us.apache.org/repos/asf/zest-java/blob/bd6fbad9/core/runtime/src/main/java/org/apache/zest/runtime/composite/AbstractModifierModel.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/composite/AbstractModifierModel.java b/core/runtime/src/main/java/org/apache/zest/runtime/composite/AbstractModifierModel.java
index a2478ce..a14d597 100644
--- a/core/runtime/src/main/java/org/apache/zest/runtime/composite/AbstractModifierModel.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/composite/AbstractModifierModel.java
@@ -14,9 +14,12 @@
package org.apache.zest.runtime.composite;
+import java.lang.reflect.Array;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
+import java.util.function.IntFunction;
+import java.util.stream.Stream;
import org.apache.zest.api.common.ConstructionException;
import org.apache.zest.functional.HierarchicalVisitor;
import org.apache.zest.functional.VisitableHierarchy;
@@ -29,11 +32,6 @@ import org.apache.zest.spi.module.ModuleSpi;
import static org.apache.zest.api.util.Classes.RAW_CLASS;
import static org.apache.zest.api.util.Classes.interfacesOf;
-import static org.apache.zest.functional.Iterables.flattenIterables;
-import static org.apache.zest.functional.Iterables.iterable;
-import static org.apache.zest.functional.Iterables.map;
-import static org.apache.zest.functional.Iterables.toArray;
-import static org.apache.zest.functional.Iterables.unique;
/**
* JAVADOC
@@ -47,7 +45,7 @@ public abstract class AbstractModifierModel
private final InjectedFieldsModel injectedFieldsModel;
private final InjectedMethodsModel injectedMethodsModel;
- private final Class<?>[] nextInterfaces;
+ private final Class<Class<?>>[] nextInterfaces;
@SuppressWarnings( "unchecked" )
public AbstractModifierModel( Class<?> declaredModifierClass, Class<?> instantiationClass )
@@ -57,7 +55,10 @@ public abstract class AbstractModifierModel
injectedFieldsModel = new InjectedFieldsModel( declaredModifierClass );
injectedMethodsModel = new InjectedMethodsModel( declaredModifierClass );
Class<Class<?>> componentType = (Class<Class<?>>) Class.class.cast( Class.class );
- nextInterfaces = toArray( componentType, unique( map( RAW_CLASS, interfacesOf( declaredModifierClass ) ) ) );
+ nextInterfaces = interfacesOf( declaredModifierClass )
+ .map( RAW_CLASS )
+ .distinct()
+ .toArray( size -> (Class<Class<?>>[]) Array.newInstance( componentType, size ) );
}
public Class<?> modifierClass()
@@ -67,9 +68,11 @@ public abstract class AbstractModifierModel
@Override
@SuppressWarnings( "unchecked" )
- public Iterable<DependencyModel> dependencies()
+ public Stream<DependencyModel> dependencies()
{
- return flattenIterables( map( DEPENDENCIES_FUNCTION, iterable( constructorsModel, injectedFieldsModel, injectedMethodsModel ) ) );
+ return Stream.of( constructorsModel, injectedFieldsModel, injectedMethodsModel )
+ .flatMap( Dependencies::dependencies );
+// return flattenIterables( map( DEPENDENCIES_FUNCTION, iterable( constructorsModel, injectedFieldsModel, injectedMethodsModel ) ) );
}
public boolean isGeneric()
http://git-wip-us.apache.org/repos/asf/zest-java/blob/bd6fbad9/core/runtime/src/main/java/org/apache/zest/runtime/composite/CompositeMethodModel.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/composite/CompositeMethodModel.java b/core/runtime/src/main/java/org/apache/zest/runtime/composite/CompositeMethodModel.java
index dfaccfa..7349cfa 100644
--- a/core/runtime/src/main/java/org/apache/zest/runtime/composite/CompositeMethodModel.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/composite/CompositeMethodModel.java
@@ -22,6 +22,8 @@ import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
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.MethodDescriptor;
import org.apache.zest.api.util.NullArgumentException;
@@ -31,11 +33,6 @@ import org.apache.zest.runtime.injection.Dependencies;
import org.apache.zest.runtime.injection.DependencyModel;
import org.apache.zest.spi.module.ModuleSpi;
-import static org.apache.zest.functional.Iterables.filter;
-import static org.apache.zest.functional.Iterables.flattenIterables;
-import static org.apache.zest.functional.Iterables.iterable;
-import static org.apache.zest.functional.Specifications.notNull;
-
/**
* JAVADOC
*/
@@ -94,10 +91,11 @@ public final class CompositeMethodModel
@Override
@SuppressWarnings( "unchecked" )
- public Iterable<DependencyModel> dependencies()
+ public Stream<DependencyModel> dependencies()
{
- return flattenIterables( filter( notNull(), iterable( concerns != null ? concerns.dependencies() : null,
- sideEffects != null ? sideEffects.dependencies() : null ) ) );
+ return Stream.of( concerns, sideEffects ).filter( e -> e != null ).flatMap( Dependencies::dependencies );
+// return flattenIterables( filter( notNull(), iterable( concerns != null ? concerns.dependencies() : null,
+// sideEffects != null ? sideEffects.dependencies() : null ) ) );
}
// Context
@@ -197,7 +195,7 @@ public final class CompositeMethodModel
public Iterable<Method> invocationsFor( Class<?> mixinClass )
{
- return mixins.invocationsFor( mixinClass );
+ return mixins.invocationsFor( mixinClass ).collect( Collectors.toList() );
}
public class CompositeMethodAnnotatedElement
http://git-wip-us.apache.org/repos/asf/zest-java/blob/bd6fbad9/core/runtime/src/main/java/org/apache/zest/runtime/composite/CompositeMethodsModel.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/composite/CompositeMethodsModel.java b/core/runtime/src/main/java/org/apache/zest/runtime/composite/CompositeMethodsModel.java
index 62d44c2..d3915c1 100644
--- a/core/runtime/src/main/java/org/apache/zest/runtime/composite/CompositeMethodsModel.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/composite/CompositeMethodsModel.java
@@ -15,10 +15,11 @@
package org.apache.zest.runtime.composite;
import java.lang.reflect.Method;
+import java.util.Collection;
import java.util.LinkedHashMap;
+import java.util.stream.Stream;
import org.apache.zest.api.composite.MissingMethodException;
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;
@@ -30,20 +31,24 @@ import static org.apache.zest.functional.Iterables.map;
* Model for Composite methods. This includes both private and public methods.
*/
public final class CompositeMethodsModel
- implements VisitableHierarchy<Object, Object>
+ implements VisitableHierarchy<Object, Object>, Dependencies
{
private final LinkedHashMap<Method, CompositeMethodModel> methods;
+ // TODO: With the large block disappearing, this member has no use. Other implications are also commented out for now.
private final MixinsModel mixinsModel;
public CompositeMethodsModel( MixinsModel mixinsModel )
+// public CompositeMethodsModel()
{
methods = new LinkedHashMap<>();
this.mixinsModel = mixinsModel;
}
- public Iterable<DependencyModel> dependencies()
+ public Stream<DependencyModel> dependencies()
{
- return Iterables.flattenIterables( map( Dependencies.DEPENDENCIES_FUNCTION, methods.values() ) );
+ Collection<CompositeMethodModel> compositeMethods = methods.values();
+ return compositeMethods.stream().flatMap( Dependencies.DEPENDENCIES_FUNCTION );
+// return Iterables.flattenIterables( map( , methods.values() ) );
}
// Context
@@ -64,26 +69,22 @@ public final class CompositeMethodsModel
return mixins.invokeObject( proxy, args, method );
}
+ // TODO: Figure out what was the intention of this code block, added by Rickard in 2009. It doesn't do anything useful.
if( !method.getDeclaringClass().isInterface() )
{
- Iterable<Class<?>> types = mixinsModel.mixinTypes();
- for( Class<?> aClass : types )
- {
+ compositeMethod = mixinsModel.mixinTypes().map( aClass -> {
try
{
Method realMethod = aClass.getMethod( method.getName(), method.getParameterTypes() );
- compositeMethod = methods.get( realMethod );
- break;
- }
- catch( NoSuchMethodException e )
- {
+ return methods.get( realMethod );
}
- catch( SecurityException e )
+ catch( NoSuchMethodException | SecurityException e )
{
+
}
- }
+ return null;
+ }).filter( model -> model != null ).findFirst().orElse( null );
}
-// return mixins.invokeObject( proxy, args, method );
throw new MissingMethodException( "Method '" + method + "' is not implemented" );
}
else
http://git-wip-us.apache.org/repos/asf/zest-java/blob/bd6fbad9/core/runtime/src/main/java/org/apache/zest/runtime/composite/CompositeModel.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/composite/CompositeModel.java b/core/runtime/src/main/java/org/apache/zest/runtime/composite/CompositeModel.java
index a9554f3..e7f477e 100644
--- a/core/runtime/src/main/java/org/apache/zest/runtime/composite/CompositeModel.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/composite/CompositeModel.java
@@ -18,7 +18,9 @@ import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.util.LinkedHashSet;
+import java.util.List;
import java.util.Set;
+import java.util.stream.Stream;
import org.apache.zest.api.common.ConstructionException;
import org.apache.zest.api.common.MetaInfo;
import org.apache.zest.api.common.Visibility;
@@ -48,10 +50,11 @@ public abstract class CompositeModel
private final Visibility visibility;
private final MetaInfo metaInfo;
protected final StateModel stateModel;
+ private volatile Class<?> primaryType;
protected Class<? extends Composite> proxyClass;
protected Constructor<? extends Composite> proxyConstructor;
- protected CompositeModel( final Iterable<Class<?>> types,
+ protected CompositeModel( final List<Class<?>> types,
final Visibility visibility,
final MetaInfo metaInfo,
final MixinsModel mixinsModel,
@@ -59,7 +62,7 @@ public abstract class CompositeModel
final CompositeMethodsModel compositeMethodsModel
)
{
- this.types = Iterables.addAll( new LinkedHashSet<Class<?>>(), types );
+ this.types = new LinkedHashSet<>( types );
this.visibility = visibility;
this.metaInfo = metaInfo;
this.stateModel = stateModel;
@@ -68,13 +71,27 @@ public abstract class CompositeModel
// Create proxy class
createProxyClass();
+ primaryType = mixinTypes()
+ .filter( type -> !type.getName().equals( "scala.ScalaObject" ) )
+ .reduce( null, ( primary, type ) ->
+ {
+ if( primary == null )
+ {
+ return type;
+ }
+ else if( primary.isAssignableFrom( type ) )
+ {
+ return type;
+ }
+ return primary;
+ } );
}
// Model
@Override
- public Iterable<Class<?>> types()
+ public Stream<Class<?>> types()
{
- return types;
+ return types.stream();
}
public StateModel state()
@@ -116,35 +133,20 @@ public abstract class CompositeModel
@SuppressWarnings( { "raw", "unchecked" } )
public Class<?> primaryType()
{
- Class primaryType = null;
- for( Class type : mixinTypes() )
- {
- if( type.getName().equals( "scala.ScalaObject" ) )
- {
- continue;
- }
- if( primaryType == null )
- {
- primaryType = type;
- }
- else if( primaryType.isAssignableFrom( type ) )
- {
- primaryType = type;
- }
- }
return primaryType;
}
@Override
- public Iterable<Class<?>> mixinTypes()
+ public Stream<Class<?>> mixinTypes()
{
return mixinsModel.mixinTypes();
}
@Override
- public Iterable<DependencyModel> dependencies()
+ public Stream<DependencyModel> dependencies()
{
- return Iterables.flatten( mixinsModel.dependencies(), compositeMethodsModel.dependencies() );
+ return Stream.of( mixinsModel, compositeMethodsModel ).flatMap( Dependencies::dependencies );
+// return Iterables.flatten( mixinsModel.dependencies(), compositeMethodsModel.dependencies() );
}
@Override
@@ -214,7 +216,7 @@ public abstract class CompositeModel
public Composite newProxy( InvocationHandler invocationHandler )
throws ConstructionException
{
- Class<?> mainType = first( types() );
+ Class<?> mainType = first( types );
if( mainType.isInterface() )
{
http://git-wip-us.apache.org/repos/asf/zest-java/blob/bd6fbad9/core/runtime/src/main/java/org/apache/zest/runtime/composite/ConcernsModel.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/composite/ConcernsModel.java b/core/runtime/src/main/java/org/apache/zest/runtime/composite/ConcernsModel.java
index 22092fc..11f91ad 100644
--- a/core/runtime/src/main/java/org/apache/zest/runtime/composite/ConcernsModel.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/composite/ConcernsModel.java
@@ -18,6 +18,7 @@ import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.util.Collections;
import java.util.List;
+import java.util.stream.Stream;
import org.apache.zest.api.concern.ConcernsDescriptor;
import org.apache.zest.functional.HierarchicalVisitor;
import org.apache.zest.functional.Iterables;
@@ -42,9 +43,10 @@ public final class ConcernsModel
}
@Override
- public Iterable<DependencyModel> dependencies()
+ public Stream<DependencyModel> dependencies()
{
- return Iterables.flattenIterables( Iterables.map( Dependencies.DEPENDENCIES_FUNCTION, concernsFor ) );
+ return concernsFor.stream().flatMap( ConcernModel::dependencies );
+// return Iterables.flattenIterables( Iterables.map( Dependencies.DEPENDENCIES_FUNCTION, concernsFor ) );
}
// Context
http://git-wip-us.apache.org/repos/asf/zest-java/blob/bd6fbad9/core/runtime/src/main/java/org/apache/zest/runtime/composite/ConstraintsInstance.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/composite/ConstraintsInstance.java b/core/runtime/src/main/java/org/apache/zest/runtime/composite/ConstraintsInstance.java
index 4e3b313..e56875d 100644
--- a/core/runtime/src/main/java/org/apache/zest/runtime/composite/ConstraintsInstance.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/composite/ConstraintsInstance.java
@@ -18,13 +18,12 @@ package org.apache.zest.runtime.composite;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
+import java.util.stream.Stream;
import org.apache.zest.api.composite.Composite;
import org.apache.zest.api.composite.CompositeInstance;
import org.apache.zest.api.constraint.ConstraintViolation;
import org.apache.zest.api.constraint.ConstraintViolationException;
-import static org.apache.zest.functional.Iterables.iterable;
-
/**
* JAVADOC
*/
@@ -71,10 +70,10 @@ public final class ConstraintsInstance
}
if( instance instanceof CompositeInstance )
{
- throw new ConstraintViolationException( (Composite) ( (CompositeInstance) instance ).proxy(), method, violations );
+ throw new ConstraintViolationException( ( (CompositeInstance) instance ).proxy(), method, violations );
}
- Iterable<? extends Class<?>> types = iterable( instance.getClass() );
- throw new ConstraintViolationException( instance.toString(), (Iterable<Class<?>>) types, method, violations );
+ Stream<Class<?>> types = Stream.of( instance.getClass() );
+ throw new ConstraintViolationException( instance.toString(), types, method, violations );
}
}
}
http://git-wip-us.apache.org/repos/asf/zest-java/blob/bd6fbad9/core/runtime/src/main/java/org/apache/zest/runtime/composite/ConstructorModel.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/composite/ConstructorModel.java b/core/runtime/src/main/java/org/apache/zest/runtime/composite/ConstructorModel.java
index e78481f..c64f172 100644
--- a/core/runtime/src/main/java/org/apache/zest/runtime/composite/ConstructorModel.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/composite/ConstructorModel.java
@@ -17,6 +17,7 @@ package org.apache.zest.runtime.composite;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;
+import java.util.stream.Stream;
import org.apache.zest.api.common.ConstructionException;
import org.apache.zest.api.composite.ConstructorDescriptor;
import org.apache.zest.api.composite.InvalidCompositeException;
@@ -49,7 +50,7 @@ public final class ConstructorModel
return constructor;
}
- public Iterable<DependencyModel> dependencies()
+ public Stream<DependencyModel> dependencies()
{
return parameters.dependencies();
}