You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by hl...@apache.org on 2010/05/27 19:33:11 UTC

svn commit: r948924 - in /tapestry/tapestry5/trunk: tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ajax/ tapestry-core/src/main/java/org/apache/tapestry5/internal/s...

Author: hlship
Date: Thu May 27 17:33:10 2010
New Revision: 948924

URL: http://svn.apache.org/viewvc?rev=948924&view=rev
Log:
Remove the various methods of F that are better implemented as part of Flow

Modified:
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/DocumentLinkerImpl.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ObjectComponentEventResultProcessor.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ajax/JavascriptSupportImpl.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/javascript/CoreJavascriptStack.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/javascript/DateFieldStack.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/javascript/JavascriptStackPathConstructorImpl.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/ImportWorker.java
    tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/MultiZoneUpdateInsideForm.java
    tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/func/F.java
    tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/func/Flow.java
    tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/func/FlowImpl.java
    tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/func/FuncTest.java
    tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/util/InternalUtilsTest.java

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/DocumentLinkerImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/DocumentLinkerImpl.java?rev=948924&r1=948923&r2=948924&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/DocumentLinkerImpl.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/DocumentLinkerImpl.java Thu May 27 17:33:10 2010
@@ -244,7 +244,7 @@ public class DocumentLinkerImpl implemen
             }
         };
 
-        F.each(addScript, scripts);
+        F.flow(scripts).each(addScript);
 
         if (existing != null)
             scriptContainer.moveBefore(existing);

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ObjectComponentEventResultProcessor.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ObjectComponentEventResultProcessor.java?rev=948924&r1=948923&r2=948924&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ObjectComponentEventResultProcessor.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ObjectComponentEventResultProcessor.java Thu May 27 17:33:10 2010
@@ -40,13 +40,13 @@ public class ObjectComponentEventResultP
 
     public void processResultValue(Object value) throws IOException
     {
-        List<String> names = F.map(new Mapper<Class, String>()
+        List<String> names = F.flow(configuredClasses).map(new Mapper<Class, String>()
         {
             public String map(Class input)
             {
                 return ClassFabUtils.toJavaClassName(input);
             }
-        }, configuredClasses);
+        }).toList();
 
         String message = String.format(
                 "A component event handler method returned the value %s. Return type %s can not be handled.", value,

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ajax/JavascriptSupportImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ajax/JavascriptSupportImpl.java?rev=948924&r1=948923&r2=948924&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ajax/JavascriptSupportImpl.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ajax/JavascriptSupportImpl.java Thu May 27 17:33:10 2010
@@ -92,13 +92,13 @@ public class JavascriptSupportImpl imple
 
     public void commit()
     {
-        F.each(new Worker<StylesheetLink>()
+        F.flow(stylesheetLinks).each(new Worker<StylesheetLink>()
         {
             public void work(StylesheetLink value)
             {
                 linker.addStylesheetLink(value);
             }
-        }, stylesheetLinks);
+        });
 
         Worker<String> linkLibrary = new Worker<String>()
         {
@@ -108,8 +108,8 @@ public class JavascriptSupportImpl imple
             }
         };
 
-        F.each(linkLibrary, stackLibraries);
-        F.each(linkLibrary, otherLibraries);
+        F.flow(stackLibraries).each(linkLibrary);
+        F.flow(otherLibraries).each(linkLibrary);
 
         for (InitializationPriority p : InitializationPriority.values())
         {

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/javascript/CoreJavascriptStack.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/javascript/CoreJavascriptStack.java?rev=948924&r1=948923&r2=948924&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/javascript/CoreJavascriptStack.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/javascript/CoreJavascriptStack.java Thu May 27 17:33:10 2010
@@ -57,7 +57,8 @@ public class CoreJavascriptStack impleme
 
     public List<StylesheetLink> getStylesheets()
     {
-        return F.map(TapestryInternalUtils.assetToStylesheetLink, clientInfrastructure.getStylesheetStack());
+        return F.flow(clientInfrastructure.getStylesheetStack()).map(TapestryInternalUtils.assetToStylesheetLink)
+                .toList();
     }
 
 }

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/javascript/DateFieldStack.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/javascript/DateFieldStack.java?rev=948924&r1=948923&r2=948924&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/javascript/DateFieldStack.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/javascript/DateFieldStack.java Thu May 27 17:33:10 2010
@@ -59,10 +59,10 @@ public class DateFieldStack implements J
         Mapper<String, StylesheetLink> pathToStylesheetLink = pathToAsset
                 .combine(TapestryInternalUtils.assetToStylesheetLink);
 
-        javascriptStack = F.map(pathToAsset, "${tapestry.datepicker}/js/datepicker.js",
-                "org/apache/tapestry5/corelib/components/datefield.js");
+        javascriptStack = F.flow("${tapestry.datepicker}/js/datepicker.js",
+                "org/apache/tapestry5/corelib/components/datefield.js").map(pathToAsset).toList();
 
-        stylesheetStack = F.map(pathToStylesheetLink, "${tapestry.datepicker}/css/datepicker.css");
+        stylesheetStack = F.flow("${tapestry.datepicker}/css/datepicker.css").map(pathToStylesheetLink).toList();
     }
 
     public String getInitialization()

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/javascript/JavascriptStackPathConstructorImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/javascript/JavascriptStackPathConstructorImpl.java?rev=948924&r1=948923&r2=948924&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/javascript/JavascriptStackPathConstructorImpl.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/javascript/JavascriptStackPathConstructorImpl.java Thu May 27 17:33:10 2010
@@ -23,6 +23,7 @@ import org.apache.tapestry5.func.Mapper;
 import org.apache.tapestry5.internal.services.RequestConstants;
 import org.apache.tapestry5.ioc.annotations.Symbol;
 import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
+import org.apache.tapestry5.ioc.internal.util.Defense;
 import org.apache.tapestry5.ioc.services.ThreadLocale;
 import org.apache.tapestry5.services.assets.AssetPathConstructor;
 import org.apache.tapestry5.services.javascript.JavascriptStack;
@@ -72,7 +73,9 @@ public class JavascriptStackPathConstruc
 
     private List<String> toPaths(List<Asset> assets)
     {
-        return F.map(toPath, assets);
+        Defense.notNull(assets, "source");
+        
+        return F.flow(assets).map(toPath).toList();
     }
 
     private List<String> combinedStackURL(String stackName)

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/ImportWorker.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/ImportWorker.java?rev=948924&r1=948923&r2=948924&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/ImportWorker.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/ImportWorker.java Thu May 27 17:33:10 2010
@@ -26,6 +26,7 @@ import org.apache.tapestry5.func.F;
 import org.apache.tapestry5.func.Mapper;
 import org.apache.tapestry5.func.Worker;
 import org.apache.tapestry5.ioc.Resource;
+import org.apache.tapestry5.ioc.internal.util.Defense;
 import org.apache.tapestry5.ioc.services.SymbolSource;
 import org.apache.tapestry5.model.MutableComponentModel;
 import org.apache.tapestry5.services.AssetSource;
@@ -205,13 +206,14 @@ public class ImportWorker implements Com
 
     private List<Asset> convertPathsToAssets(final Resource baseResource, final Locale locale, String[] assetPaths)
     {
-        return F.map(new Mapper<String, Asset>()
+
+        return F.flow(assetPaths).map(new Mapper<String, Asset>()
         {
             public Asset map(String assetPath)
             {
                 return assetSource.getAsset(baseResource, assetPath, locale);
             }
-        }, assetPaths);
+        }).toList();
     }
 
     private void addMethodAssetOperationAdvice(TransformMethod method, final FieldAccess access,
@@ -224,7 +226,7 @@ public class ImportWorker implements Com
             {
                 List<Asset> assets = (List<Asset>) access.read(invocation.getInstance());
 
-                F.each(operation, assets);
+                F.flow(assets).each(operation);
 
                 invocation.proceed();
             }

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/MultiZoneUpdateInsideForm.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/MultiZoneUpdateInsideForm.java?rev=948924&r1=948923&r2=948924&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/MultiZoneUpdateInsideForm.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/MultiZoneUpdateInsideForm.java Thu May 27 17:33:10 2010
@@ -32,6 +32,7 @@ import org.apache.tapestry5.corelib.comp
 import org.apache.tapestry5.func.F;
 import org.apache.tapestry5.func.Mapper;
 import org.apache.tapestry5.ioc.annotations.Inject;
+import org.apache.tapestry5.ioc.internal.util.Defense;
 import org.apache.tapestry5.services.Request;
 import org.apache.tapestry5.util.AbstractSelectModel;
 
@@ -104,24 +105,26 @@ public class MultiZoneUpdateInsideForm
 
         public List<OptionModel> getOptions()
         {
-            return F.map(new Mapper<SelectObj, OptionModel>()
-            {
-                public OptionModel map(final SelectObj input)
-                {
-                    return new AbstractOptionModel()
-                    {
-                        public Object getValue()
-                        {
-                            return input;
-                        }
-
-                        public String getLabel()
+            Defense.notNull(options, "source");
+            
+            return F.flow(options).map(new Mapper<SelectObj, OptionModel>()
                         {
-                            return input.getLabel();
-                        }
-                    };
-                }
-            }, options);
+                            public OptionModel map(final SelectObj input)
+                            {
+                                return new AbstractOptionModel()
+                                {
+                                    public Object getValue()
+                                    {
+                                        return input;
+                                    }
+            
+                                    public String getLabel()
+                                    {
+                                        return input.getLabel();
+                                    }
+                                };
+                            }
+                        }).toList();
         }
 
         public String toClient(SelectObj value)

Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/func/F.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/func/F.java?rev=948924&r1=948923&r2=948924&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/func/F.java (original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/func/F.java Thu May 27 17:33:10 2010
@@ -14,14 +14,10 @@
 
 package org.apache.tapestry5.func;
 
-import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
-import java.util.Collections;
 import java.util.List;
 
-import org.apache.tapestry5.ioc.internal.util.Defense;
-
 /**
  * Functional operations on collections with generics support. Tending to use the equivalent names from
  * Clojure. As with Clojure, all these functions return new lists. Unlike Clojure, there's no guarantee
@@ -31,89 +27,6 @@ import org.apache.tapestry5.ioc.internal
  */
 public class F
 {
-    /**
-     * Functional map (i.e., transform operation) from a Collection&lt;S&gt; to List&lt;T&gt;.
-     */
-    public static <S, T> List<T> map(Mapper<S, T> mapper, Collection<S> source)
-    {
-        Defense.notNull(source, "source");
-        Defense.notNull(mapper, "mapper");
-
-        if (source.isEmpty())
-            return Collections.emptyList();
-
-        List<T> result = new ArrayList<T>(source.size());
-
-        for (S s : source)
-        {
-            T t = mapper.map(s);
-
-            result.add(t);
-        }
-
-        return result;
-    }
-
-    public static <S, T> List<T> map(Mapper<S, T> mapper, S... source)
-    {
-        Defense.notNull(source, "source");
-
-        return map(mapper, Arrays.asList(source));
-    }
-
-    /**
-     * Performs an operation on each element of the source collection.
-     */
-    public static <T> void each(Worker<? super T> operation, Collection<T> source)
-    {
-        for (T t : source)
-        {
-            operation.work(t);
-        }
-    }
-
-    /**
-     * Performs an operation on each of the values.
-     */
-    public static <T> void each(Worker<T> operation, T... values)
-    {
-        for (T t : values)
-        {
-            operation.work(t);
-        }
-    }
-
-    /** Returns a new list containing only those elements for which the predicate evaluates to true. */
-    public static <T> List<T> filter(Predicate<? super T> predicate, List<T> source)
-    {
-        Defense.notNull(source, "source");
-        Defense.notNull(predicate, "predicate");
-
-        if (source.isEmpty())
-            return Collections.emptyList();
-
-        List<T> result = new ArrayList<T>(source.size());
-
-        for (T item : source)
-        {
-            if (predicate.accept(item))
-                result.add(item);
-        }
-
-        return result;
-    }
-
-    /**
-     * Returns a new list containing only those values of the source list for which the predicate
-     * evaluates to false.
-     */
-    public static <T> List<T> remove(Predicate<? super T> predicate, List<T> source)
-    {
-        Defense.notNull(predicate, "predicate");
-
-        return filter(predicate.invert(), source);
-    }
-
     public static Predicate<Number> eq(final long value)
     {
         return new Predicate<Number>()
@@ -253,21 +166,6 @@ public class F
         };
     }
 
-    public static <A, T> A reduce(Reducer<A, T> reducer, A initial, Collection<T> values)
-    {
-        Defense.notNull(reducer, "reducer");
-        Defense.notNull(values, "values");
-
-        A accumulator = initial;
-
-        for (T value : values)
-        {
-            accumulator = reducer.reduce(accumulator, value);
-        }
-
-        return accumulator;
-    }
-
     public static Reducer<Integer, Integer> SUM_INTS = new Reducer<Integer, Integer>()
     {
         public Integer reduce(Integer accumulator, Integer value)
@@ -276,6 +174,11 @@ public class F
         };
     };
 
+    public static <T> Flow<T> flow(Collection<T> values)
+    {
+        return new FlowImpl<T>(values);
+    }
+
     public static <T> Flow<T> flow(List<T> values)
     {
         return new FlowImpl<T>(values);

Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/func/Flow.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/func/Flow.java?rev=948924&r1=948923&r2=948924&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/func/Flow.java (original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/func/Flow.java Thu May 27 17:33:10 2010
@@ -38,7 +38,12 @@ public interface Flow<T>
     /** Removes values where the predicate returns true, returning a new Flow with just the remaining values. */
     Flow<T> remove(Predicate<? super T> predicate);
 
-    /** Applies a reducer to the values of the Flow. */
+    /**
+     * Applies a Reducer to the values of the Flow. The Reducer is passed the initial value
+     * and the first value from the flow. The result is captured as the accumulator and passed
+     * to the Reducer with the next value from the flow, and so on. The final accumulator
+     * value is returned. If the flow is empty, the initial value is returned.
+     */
     <A> A reduce(Reducer<A, T> reducer, A initial);
 
     /**

Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/func/FlowImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/func/FlowImpl.java?rev=948924&r1=948923&r2=948924&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/func/FlowImpl.java (original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/func/FlowImpl.java Thu May 27 17:33:10 2010
@@ -14,49 +14,100 @@
 
 package org.apache.tapestry5.func;
 
+import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
 
 import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
+import org.apache.tapestry5.ioc.internal.util.Defense;
 
 class FlowImpl<T> implements Flow<T>
 {
     private final List<T> values;
 
-    public FlowImpl(List<T> values)
+    FlowImpl(Collection<T> values)
+    {
+        this(new ArrayList<T>(values));
+    }
+
+    FlowImpl(List<T> values)
     {
         this.values = values;
     }
 
     public Flow<T> each(Worker<? super T> worker)
     {
-        F.each(worker, values);
+        for (T t : values)
+        {
+            worker.work(t);
+        }
 
         return this;
     }
 
     public Flow<T> filter(Predicate<? super T> predicate)
     {
-        return new FlowImpl<T>(F.filter(predicate, values));
+        Defense.notNull(predicate, "predicate");
+
+        List<T> result = new ArrayList<T>(values.size());
+
+        for (T item : values)
+        {
+            if (predicate.accept(item))
+                result.add(item);
+        }
+
+        return new FlowImpl<T>(result);
     }
 
     public Flow<T> remove(Predicate<? super T> predicate)
     {
-        return new FlowImpl<T>(F.remove(predicate, values));
+        Defense.notNull(predicate, "predicate");
+
+        return filter(predicate.invert());
     }
 
     public <X> Flow<X> map(Mapper<T, X> mapper)
     {
-        return new FlowImpl<X>(F.map(mapper, values));
+        Defense.notNull(mapper, "mapper");
+
+        if (values.isEmpty())
+        {
+            List<X> empty = Collections.emptyList();
+            return new FlowImpl<X>(empty);
+        }
+
+        List<X> newValues = new ArrayList<X>(values.size());
+
+        for (T value : values)
+        {
+            newValues.add(mapper.map(value));
+        }
+
+        return new FlowImpl<X>(newValues);
     }
 
     public <A> A reduce(Reducer<A, T> reducer, A initial)
     {
-        return F.reduce(reducer, initial, values);
+        Defense.notNull(reducer, "reducer");
+
+        A accumulator = initial;
+
+        for (T value : values)
+        {
+            accumulator = reducer.reduce(accumulator, value);
+        }
+
+        return accumulator;
     }
 
+    /** Returns the values in the flow as an unmodifiable List. */
     public List<T> toList()
     {
+        if (values.isEmpty())
+            return Collections.emptyList();
+
         return Collections.unmodifiableList(values);
     }
 

Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/func/FuncTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/func/FuncTest.java?rev=948924&r1=948923&r2=948924&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/func/FuncTest.java (original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/func/FuncTest.java Thu May 27 17:33:10 2010
@@ -18,6 +18,7 @@ import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
 
+import org.apache.tapestry5.ioc.internal.util.Defense;
 import org.apache.tapestry5.ioc.test.TestBase;
 import org.testng.annotations.Test;
 
@@ -51,8 +52,9 @@ public class FuncTest extends TestBase
     public void map()
     {
         List<String> source = Arrays.asList("Mary", "had", "a", "little", "lamb");
+        Defense.notNull(source, "source");
 
-        List<Integer> lengths = F.map(stringToLength, source);
+        List<Integer> lengths = F.flow(source).map(stringToLength).toList();
 
         assertListsEquals(lengths, 4, 3, 1, 6, 4);
     }
@@ -72,7 +74,7 @@ public class FuncTest extends TestBase
     @Test
     public void combine_mappers()
     {
-        List<Boolean> even = F.map(stringToLength.combine(toEven), "Mary", "had", "a", "little", "lamb");
+        List<Boolean> even = F.flow("Mary", "had", "a", "little", "lamb").map(stringToLength.combine(toEven)).toList();
 
         assertListsEquals(even, true, false, false, true, true);
     }
@@ -81,8 +83,9 @@ public class FuncTest extends TestBase
     public void map_empty_collection_is_the_empty_list()
     {
         List<String> source = Arrays.asList();
+        Defense.notNull(source, "source");
 
-        List<Integer> lengths = F.map(stringToLength, source);
+        List<Integer> lengths = F.flow(source).map(stringToLength).toList();
 
         assertSame(lengths, Collections.EMPTY_LIST);
     }
@@ -105,7 +108,7 @@ public class FuncTest extends TestBase
             }
         };
 
-        F.each(worker, source);
+        F.flow(source).each(worker);
 
         assertEquals(buffer.toString(), "Mary had a little lamb");
     }
@@ -159,7 +162,7 @@ public class FuncTest extends TestBase
             }
         };
 
-        F.each(appendWorker.combine(appendLength), "Mary", "had", "a", "little", "lamb");
+        F.flow("Mary", "had", "a", "little", "lamb").each(appendWorker.combine(appendLength));
 
         assertEquals(buffer.toString(), "Mary(4) had(3) a(1) little(6) lamb(4)");
     }
@@ -169,7 +172,7 @@ public class FuncTest extends TestBase
     {
         List<Integer> input = Arrays.asList(1, 2, 3, 4, 5, 6, 7);
 
-        List<Integer> output = F.filter(evenp, input);
+        List<Integer> output = F.flow(input).filter(evenp).toList();
 
         assertListsEquals(output, 2, 4, 6);
     }
@@ -185,7 +188,7 @@ public class FuncTest extends TestBase
     {
         List<Integer> input = Arrays.asList(1, 2, 3, 4, 5, 6, 7);
 
-        List<Integer> output = F.remove(evenp, input);
+        List<Integer> output = F.flow(input).remove(evenp).toList();
 
         assertListsEquals(output, 1, 3, 5, 7);
     }
@@ -203,7 +206,7 @@ public class FuncTest extends TestBase
     {
         List<Integer> input = Arrays.asList();
 
-        List<Integer> output = F.filter(evenp, input);
+        List<Integer> output = F.flow(input).filter(evenp).toList();
 
         assertSame(output, Collections.EMPTY_LIST);
     }
@@ -213,7 +216,7 @@ public class FuncTest extends TestBase
     {
         List<Integer> input = Arrays.asList(1, 2, 3, 4, 5, 6, 7);
 
-        List<Integer> output = F.filter(evenp.and(F.gt(3)), input);
+        List<Integer> output = F.flow(input).filter(evenp.and(F.gt(3))).toList();
 
         assertListsEquals(output, 4, 6);
     }
@@ -223,11 +226,11 @@ public class FuncTest extends TestBase
     {
         List<Integer> input = Arrays.asList(1, 2, 3, 4, 5, 6, 7);
 
-        assertEquals(F.filter(F.eq(3), input), Arrays.asList(3));
-        assertEquals(F.filter(F.neq(3), input), Arrays.asList(1, 2, 4, 5, 6, 7));
-        assertEquals(F.filter(F.lt(3), input), Arrays.asList(1, 2));
-        assertEquals(F.filter(F.lteq(3), input), Arrays.asList(1, 2, 3));
-        assertEquals(F.filter(F.gteq(3), input), Arrays.asList(3, 4, 5, 6, 7));
+        assertEquals(F.flow(input).filter(F.eq(3)).toList(), Arrays.asList(3));
+        assertEquals(F.flow(input).filter(F.neq(3)).toList(), Arrays.asList(1, 2, 4, 5, 6, 7));
+        assertEquals(F.flow(input).filter(F.lt(3)).toList(), Arrays.asList(1, 2));
+        assertEquals(F.flow(input).filter(F.lteq(3)).toList(), Arrays.asList(1, 2, 3));
+        assertEquals(F.flow(input).filter(F.gteq(3)).toList(), Arrays.asList(3, 4, 5, 6, 7));
     }
 
     @Test
@@ -241,8 +244,8 @@ public class FuncTest extends TestBase
         // Converting to null and then filtering out nulls is the hard way to do filter or remove,
         // but exercises the code we want to test.
 
-        List<String> filtered = F.remove(isNull, F.map(F.select(combinedp, identity), "Mary", "had", "a", "little",
-                "lamb"));
+        List<String> filtered = F.flow("Mary", "had", "a", "little", "lamb").map(F.select(combinedp, identity)).remove(
+                isNull).toList();
 
         assertListsEquals(filtered, "Mary", "little", "lamb");
     }
@@ -263,7 +266,7 @@ public class FuncTest extends TestBase
     @Test
     public void reduce()
     {
-        int total = F.reduce(F.SUM_INTS, 0, F.map(stringToLength, "Mary", "had", "a", "little", "lamb"));
+        int total = F.flow(F.flow("Mary", "had", "a", "little", "lamb").map(stringToLength).toList()).reduce(F.SUM_INTS, 0);
 
         assertEquals(total, 18);
     }

Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/util/InternalUtilsTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/util/InternalUtilsTest.java?rev=948924&r1=948923&r2=948924&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/util/InternalUtilsTest.java (original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/util/InternalUtilsTest.java Thu May 27 17:33:10 2010
@@ -687,7 +687,7 @@ public class InternalUtilsTest extends I
             }
         };
 
-        assertListsEquals(F.map(InternalUtils.toMapper(toUpper), "Mary", "had", "a", "little", "lamb"), "MARY", "HAD",
-                "A", "LITTLE", "LAMB");
+        assertListsEquals(F.flow("Mary", "had", "a", "little", "lamb").map(InternalUtils.toMapper(toUpper)).toList(),
+                "MARY", "HAD", "A", "LITTLE", "LAMB");
     }
 }