polygene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From paulmer...@apache.org
Subject [06/14] zest-java git commit: forum sample: prefer Streams over core/functional
Date Mon, 28 Nov 2016 16:07:51 GMT
forum sample: prefer Streams over core/functional


Project: http://git-wip-us.apache.org/repos/asf/zest-java/repo
Commit: http://git-wip-us.apache.org/repos/asf/zest-java/commit/ce93c2ee
Tree: http://git-wip-us.apache.org/repos/asf/zest-java/tree/ce93c2ee
Diff: http://git-wip-us.apache.org/repos/asf/zest-java/diff/ce93c2ee

Branch: refs/heads/develop
Commit: ce93c2ee4b36902adf8fda2e8910082d060640a3
Parents: 94f7cca
Author: Paul Merlin <paulmerlin@apache.org>
Authored: Mon Nov 28 09:55:34 2016 +0100
Committer: Paul Merlin <paulmerlin@apache.org>
Committed: Mon Nov 28 09:55:34 2016 +0100

----------------------------------------------------------------------
 .../sample/forum/assembler/ForumAssembler.java  | 32 +++++++++++---------
 .../sample/forum/context/EventsService.java     | 15 +++------
 .../sample/forum/domainevent/DomainEvent.java   | 15 +++------
 3 files changed, 27 insertions(+), 35 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/zest-java/blob/ce93c2ee/samples/forum/src/main/java/org/apache/zest/sample/forum/assembler/ForumAssembler.java
----------------------------------------------------------------------
diff --git a/samples/forum/src/main/java/org/apache/zest/sample/forum/assembler/ForumAssembler.java
b/samples/forum/src/main/java/org/apache/zest/sample/forum/assembler/ForumAssembler.java
index 6ef446f..d629d06 100644
--- a/samples/forum/src/main/java/org/apache/zest/sample/forum/assembler/ForumAssembler.java
+++ b/samples/forum/src/main/java/org/apache/zest/sample/forum/assembler/ForumAssembler.java
@@ -20,7 +20,7 @@
 package org.apache.zest.sample.forum.assembler;
 
 import java.lang.reflect.Modifier;
-
+import java.util.List;
 import org.apache.zest.api.common.Visibility;
 import org.apache.zest.api.entity.EntityComposite;
 import org.apache.zest.api.value.ValueComposite;
@@ -42,20 +42,20 @@ import org.apache.zest.library.rest.server.restlet.RequestReaderDelegator;
 import org.apache.zest.library.rest.server.restlet.ResponseWriterDelegator;
 import org.apache.zest.library.rest.server.spi.CommandResult;
 import org.apache.zest.sample.forum.context.Context;
-import org.apache.zest.sample.forum.domainevent.DomainCommandResult;
-import org.apache.zest.sample.forum.rest.resource.RootResource;
 import org.apache.zest.sample.forum.context.EventsService;
 import org.apache.zest.sample.forum.data.entity.User;
+import org.apache.zest.sample.forum.domainevent.DomainCommandResult;
 import org.apache.zest.sample.forum.domainevent.DomainEventValue;
 import org.apache.zest.sample.forum.domainevent.ParameterValue;
 import org.apache.zest.sample.forum.rest.ForumRestlet;
+import org.apache.zest.sample.forum.rest.resource.RootResource;
 import org.apache.zest.sample.forum.service.BootstrapData;
 import org.apache.zest.valueserialization.orgjson.OrgJsonValueSerializationAssembler;
 import org.restlet.service.MetadataService;
 
+import static java.util.stream.Collectors.toList;
 import static org.apache.zest.api.util.Classes.hasModifier;
 import static org.apache.zest.api.util.Classes.isAssignableFrom;
-import static org.apache.zest.functional.Iterables.filter;
 
 /**
  * TODO
@@ -103,17 +103,19 @@ public class ForumAssembler
         LayerAssembly data = assembly.layer( "Data" ).uses( infrastructure );
         {
             ModuleAssembly forum = data.module( "Forum" );
-            for( Class<?> dataClass : filter( hasModifier( Modifier.INTERFACE ), filter(
isAssignableFrom( EntityComposite.class ), ClassScanner
-                .findClasses( User.class ) ) ) )
-            {
-                forum.entities( dataClass ).visibleIn( Visibility.application );
-            }
+            ClassScanner.findClasses( User.class )
+                        .filter( isAssignableFrom( EntityComposite.class ) )
+                        .filter( hasModifier( Modifier.INTERFACE ) )
+                        .forEach( dataClass -> forum.entities( dataClass ).visibleIn(
Visibility.application ) );
         }
 
         LayerAssembly context = assembly.layer( "Context" ).uses( data );
         {
             ModuleAssembly contexts = context.module( "Context" );
-            for( Class<?> contextClass : filter( hasModifier( Modifier.INTERFACE ).negate(),
ClassScanner.findClasses( Context.class ) ) )
+            List<? extends Class<?>> contextClasses = ClassScanner.findClasses(
Context.class )
+                                                                  .filter( hasModifier( Modifier.INTERFACE
).negate() )
+                                                                  .collect( toList() );
+            for( Class<?> contextClass : contextClasses )
             {
                 if( contextClass.getName().contains( "$" ) )
                 {
@@ -125,10 +127,9 @@ public class ForumAssembler
                 }
             }
 
-            for( Class<?> valueClass : filter( isAssignableFrom( ValueComposite.class
), ClassScanner.findClasses( Context.class ) ) )
-            {
-                contexts.values( valueClass ).visibleIn( Visibility.application );
-            }
+            ClassScanner.findClasses( Context.class )
+                        .filter( isAssignableFrom( ValueComposite.class ) )
+                        .forEach( valueClass -> contexts.values( valueClass ).visibleIn(
Visibility.application ) );
 
             contexts.services( EventsService.class );
 
@@ -159,7 +160,8 @@ public class ForumAssembler
             }
 
             ModuleAssembly resources = rest.module( "Resources" );
-            for( Class<?> resourceClass : ClassScanner.findClasses( RootResource.class
) )
+            List<? extends Class<?>> resourceClasses = ClassScanner.findClasses(
RootResource.class ).collect( toList() );
+            for( Class<?> resourceClass : resourceClasses )
             {
                 resources.objects( resourceClass ).visibleIn( Visibility.layer );
             }

http://git-wip-us.apache.org/repos/asf/zest-java/blob/ce93c2ee/samples/forum/src/main/java/org/apache/zest/sample/forum/context/EventsService.java
----------------------------------------------------------------------
diff --git a/samples/forum/src/main/java/org/apache/zest/sample/forum/context/EventsService.java
b/samples/forum/src/main/java/org/apache/zest/sample/forum/context/EventsService.java
index db1410b..e8a9414 100644
--- a/samples/forum/src/main/java/org/apache/zest/sample/forum/context/EventsService.java
+++ b/samples/forum/src/main/java/org/apache/zest/sample/forum/context/EventsService.java
@@ -21,7 +21,6 @@ package org.apache.zest.sample.forum.context;
 
 import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.Method;
-import java.util.function.Function;
 import org.apache.zest.api.injection.scope.Structure;
 import org.apache.zest.api.mixin.Mixins;
 import org.apache.zest.api.service.ServiceComposite;
@@ -32,12 +31,13 @@ import org.apache.zest.api.unitofwork.UnitOfWorkCompletionException;
 import org.apache.zest.api.unitofwork.UnitOfWorkFactory;
 import org.apache.zest.api.value.ValueBuilder;
 import org.apache.zest.api.value.ValueBuilderFactory;
-import org.apache.zest.functional.Iterables;
 import org.apache.zest.library.rest.server.api.ObjectSelection;
 import org.apache.zest.sample.forum.domainevent.DomainEventValue;
 import org.apache.zest.sample.forum.domainevent.ParameterValue;
 import org.restlet.Request;
 
+import static java.util.stream.Collectors.toCollection;
+
 /**
  * TODO
  */
@@ -81,14 +81,9 @@ public interface EventsService
                 prototype.parameters().get().add( parameterBuilder.newInstance() );
             }
 
-            Iterables.addAll( prototype.selection().get(), Iterables.map( new Function<Object,
String>()
-            {
-                @Override
-                public String apply( Object o )
-                {
-                    return o.toString();
-                }
-            }, ObjectSelection.current().selection() ) );
+            ObjectSelection.current().selection().stream()
+                           .map( Object::toString )
+                           .collect( toCollection( () -> prototype.selection().get() )
);
 
             final DomainEventValue domainEvent = builder.newInstance();
 

http://git-wip-us.apache.org/repos/asf/zest-java/blob/ce93c2ee/samples/forum/src/main/java/org/apache/zest/sample/forum/domainevent/DomainEvent.java
----------------------------------------------------------------------
diff --git a/samples/forum/src/main/java/org/apache/zest/sample/forum/domainevent/DomainEvent.java
b/samples/forum/src/main/java/org/apache/zest/sample/forum/domainevent/DomainEvent.java
index eae9ed9..df937fd 100644
--- a/samples/forum/src/main/java/org/apache/zest/sample/forum/domainevent/DomainEvent.java
+++ b/samples/forum/src/main/java/org/apache/zest/sample/forum/domainevent/DomainEvent.java
@@ -22,7 +22,6 @@ package org.apache.zest.sample.forum.domainevent;
 import java.lang.annotation.Retention;
 import java.lang.annotation.RetentionPolicy;
 import java.lang.reflect.Method;
-import java.util.function.Function;
 import org.apache.zest.api.concern.Concerns;
 import org.apache.zest.api.concern.GenericConcern;
 import org.apache.zest.api.injection.scope.Structure;
@@ -33,10 +32,11 @@ import org.apache.zest.api.unitofwork.UnitOfWorkCompletionException;
 import org.apache.zest.api.unitofwork.UnitOfWorkFactory;
 import org.apache.zest.api.value.ValueBuilder;
 import org.apache.zest.api.value.ValueBuilderFactory;
-import org.apache.zest.functional.Iterables;
 import org.apache.zest.library.rest.server.api.ObjectSelection;
 import org.restlet.Request;
 
+import static java.util.stream.Collectors.toCollection;
+
 /**
  * TODO
  */
@@ -82,14 +82,9 @@ public @interface DomainEvent
                 prototype.parameters().get().add( parameterBuilder.newInstance() );
             }
 
-            Iterables.addAll( prototype.selection().get(), Iterables.map( new Function<Object,
String>()
-            {
-                @Override
-                public String apply( Object o )
-                {
-                    return o.toString();
-                }
-            }, ObjectSelection.current().selection() ) );
+            ObjectSelection.current().selection().stream()
+                           .map( Object::toString )
+                           .collect( toCollection( () -> prototype.selection().get() )
);
 
             final DomainEventValue domainEvent = builder.newInstance();
 


Mime
View raw message