You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by hl...@apache.org on 2011/04/01 01:28:48 UTC

svn commit: r1087505 - in /tapestry/tapestry5/trunk/tapestry-ioc/src: main/java/org/apache/tapestry5/ioc/services/TapestryIOCModule.java test/java/org/apache/tapestry5/ioc/internal/services/TypeCoercerImplTest.java

Author: hlship
Date: Thu Mar 31 23:28:48 2011
New Revision: 1087505

URL: http://svn.apache.org/viewvc?rev=1087505&view=rev
Log:
TAP5-1390: Functional programming improvements

Modified:
    tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/TapestryIOCModule.java
    tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/TypeCoercerImplTest.java

Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/TapestryIOCModule.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/TapestryIOCModule.java?rev=1087505&r1=1087504&r2=1087505&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/TapestryIOCModule.java (original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/TapestryIOCModule.java Thu Mar 31 23:28:48 2011
@@ -30,6 +30,7 @@ import java.util.concurrent.LinkedBlocki
 import java.util.concurrent.ThreadPoolExecutor;
 import java.util.concurrent.TimeUnit;
 
+import org.apache.tapestry5.func.Flow;
 import org.apache.tapestry5.ioc.*;
 import org.apache.tapestry5.ioc.annotations.Contribute;
 import org.apache.tapestry5.ioc.annotations.IntermediateType;
@@ -180,6 +181,8 @@ public final class TapestryIOCModule
      * <li>{@link org.apache.tapestry5.ioc.util.TimeInterval} to Long</li>
      * <li>Object to Object[] (wrapping the object as an array)</li>
      * <li>Collection to Object[] (via the toArray() method)
+     * <li>{@link Flow} to List</li>
+     * <li>{@link Flow} to Boolean (false if empty)</li>
      * </ul>
      */
     @Contribute(TypeCoercer.class)
@@ -410,6 +413,22 @@ public final class TapestryIOCModule
                 return input.toArray();
             }
         });
+
+        add(configuration, Flow.class, List.class, new Coercion<Flow, List>()
+        {
+            public List coerce(Flow input)
+            {
+                return input.toList();
+            }
+        });
+
+        add(configuration, Flow.class, Boolean.class, new Coercion<Flow, Boolean>()
+        {
+            public Boolean coerce(Flow input)
+            {
+                return !input.isEmpty();
+            }
+        });
     }
 
     private static <S, T> void add(Configuration<CoercionTuple> configuration, Class<S> sourceType,

Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/TypeCoercerImplTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/TypeCoercerImplTest.java?rev=1087505&r1=1087504&r2=1087505&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/TypeCoercerImplTest.java (original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/TypeCoercerImplTest.java Thu Mar 31 23:28:48 2011
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007, 2008, 2009, 2010 The Apache Software Foundation
+// Copyright 2006, 2007, 2008, 2009, 2010, 2011 The Apache Software Foundation
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -14,6 +14,7 @@
 
 package org.apache.tapestry5.ioc.internal.services;
 
+import org.apache.tapestry5.func.F;
 import org.apache.tapestry5.ioc.internal.IOCInternalTestCase;
 import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
 import org.apache.tapestry5.ioc.services.Coercion;
@@ -173,7 +174,7 @@ public class TypeCoercerImplTest extends
         short short1 = 34, short2 = 98;
         return new Object[][]
         {
-        // There's a lot of these!
+                // There's a lot of these!
 
                 { this, String.class, toString() },
 
@@ -273,6 +274,12 @@ public class TypeCoercerImplTest extends
 
                 { "2 h", TimeInterval.class, new TimeInterval("120 m") },
 
+                { F.flow(), Boolean.class, false },
+
+                { F.flow(1, 2, 3), Boolean.class, true },
+
+                { F.flow(1, 2, 3), List.class, Arrays.asList(1, 2, 3) },
+
                 // null to arbitrary object is still null
 
                 { null, XMLReader.class, null } };