commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simonetrip...@apache.org
Subject svn commit: r1156109 - in /commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/algorithm: FoldLeft.java FoldRight.java GeneratorContains.java IndexOfInGenerator.java
Date Wed, 10 Aug 2011 11:33:03 GMT
Author: simonetripodi
Date: Wed Aug 10 11:33:02 2011
New Revision: 1156109

URL: http://svn.apache.org/viewvc?rev=1156109&view=rev
Log:
inner helper classes made static

Modified:
    commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/algorithm/FoldLeft.java
    commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/algorithm/FoldRight.java
    commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/algorithm/GeneratorContains.java
    commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/algorithm/IndexOfInGenerator.java

Modified: commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/algorithm/FoldLeft.java
URL: http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/algorithm/FoldLeft.java?rev=1156109&r1=1156108&r2=1156109&view=diff
==============================================================================
--- commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/algorithm/FoldLeft.java
(original)
+++ commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/algorithm/FoldLeft.java
Wed Aug 10 11:33:02 2011
@@ -41,23 +41,26 @@ public class FoldLeft<T> implements Unar
     /**
      * Helper procedure
      */
-    private class FoldLeftHelper implements UnaryProcedure<T> {
+    private static class FoldLeftHelper<T> implements UnaryProcedure<T> {
+        private final BinaryFunction<? super T, ? super T, ? extends T> function;
         private T seed;
         private boolean started;
 
         /**
          * Create a seedless FoldLeftHelper.
          */
-        public FoldLeftHelper() {
+        public FoldLeftHelper(BinaryFunction<? super T, ? super T, ? extends T> function)
{
+            this(null, function);
         }
 
         /**
          * Create a new FoldLeftHelper.
          * @param seed initial left argument
          */
-        FoldLeftHelper(T seed) {
+        FoldLeftHelper(T seed, BinaryFunction<? super T, ? super T, ? extends T> function)
{
             this.seed = seed;
-            started = true;
+            started = seed != null ? true : false;
+            this.function = function;
         }
 
         /**
@@ -97,7 +100,7 @@ public class FoldLeft<T> implements Unar
      * @param obj {@link Generator} to transform
      */
     public T evaluate(Generator<T> obj) {
-        FoldLeftHelper helper = new FoldLeftHelper();
+        FoldLeftHelper<T> helper = new FoldLeftHelper<T>(function);
         obj.run(helper);
         return helper.getResult();
     }
@@ -108,7 +111,7 @@ public class FoldLeft<T> implements Unar
      * @param right seed object
      */
     public T evaluate(Generator<T> left, T right) {
-        FoldLeftHelper helper = new FoldLeftHelper(right);
+        FoldLeftHelper<T> helper = new FoldLeftHelper<T>(right, function);
         left.run(helper);
         return helper.getResult();
     }

Modified: commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/algorithm/FoldRight.java
URL: http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/algorithm/FoldRight.java?rev=1156109&r1=1156108&r2=1156109&view=diff
==============================================================================
--- commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/algorithm/FoldRight.java
(original)
+++ commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/algorithm/FoldRight.java
Wed Aug 10 11:33:02 2011
@@ -41,26 +41,27 @@ public class FoldRight<T> implements Una
     /**
      * Helper class
      */
-    private class FoldRightHelper implements UnaryProcedure<T> {
+    private static class FoldRightHelper<T> implements UnaryProcedure<T> {
         private final Stack<T> stk = new Stack<T>();
+        private final BinaryFunction<? super T, ? super T, ? extends T> function;
         private final T seed;
         private final boolean hasSeed;
 
         /**
          * Create a seedless FoldRightHelper.
          */
-        public FoldRightHelper() {
-            seed = null;
-            hasSeed = false;
+        public FoldRightHelper(BinaryFunction<? super T, ? super T, ? extends T> function)
{
+            this(null, function);
         }
 
         /**
          * Create a new FoldRightHelper.
          * @param seed initial left argument
          */
-        FoldRightHelper(T seed) {
+        FoldRightHelper(T seed, BinaryFunction<? super T, ? super T, ? extends T> function)
{
             this.seed = seed;
-            hasSeed = true;
+            hasSeed = seed != null ? true : false;
+            this.function = function;
         }
 
         /**
@@ -106,7 +107,7 @@ public class FoldRight<T> implements Una
      * @param obj {@link Generator} to transform
      */
     public T evaluate(Generator<T> obj) {
-        FoldRightHelper helper = new FoldRightHelper();
+        FoldRightHelper<T> helper = new FoldRightHelper<T>(function);
         obj.run(helper);
         return helper.getResult();
     }
@@ -117,7 +118,7 @@ public class FoldRight<T> implements Una
      * @param right seed object
      */
     public T evaluate(Generator<T> left, T right) {
-        FoldRightHelper helper = new FoldRightHelper(right);
+        FoldRightHelper<T> helper = new FoldRightHelper<T>(right, function);
         left.run(helper);
         return helper.getResult();
     }

Modified: commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/algorithm/GeneratorContains.java
URL: http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/algorithm/GeneratorContains.java?rev=1156109&r1=1156108&r2=1156109&view=diff
==============================================================================
--- commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/algorithm/GeneratorContains.java
(original)
+++ commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/algorithm/GeneratorContains.java
Wed Aug 10 11:33:02 2011
@@ -39,7 +39,7 @@ public final class GeneratorContains<T> 
     /**
      * Helper procedure.
      */
-    private class ContainsProcedure implements UnaryProcedure<T> {
+    private static class ContainsProcedure<T> implements UnaryProcedure<T> {
         private final UnaryPredicate<? super T> pred;
         private boolean found;
 
@@ -65,7 +65,7 @@ public final class GeneratorContains<T> 
      * @param right UnaryPredicate
      */
     public boolean test(Generator<? extends T> left, UnaryPredicate<? super T>
right) {
-        ContainsProcedure findProcedure = new ContainsProcedure(right);
+        ContainsProcedure<T> findProcedure = new ContainsProcedure<T>(right);
         left.run(findProcedure);
         return findProcedure.found;
     }

Modified: commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/algorithm/IndexOfInGenerator.java
URL: http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/algorithm/IndexOfInGenerator.java?rev=1156109&r1=1156108&r2=1156109&view=diff
==============================================================================
--- commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/algorithm/IndexOfInGenerator.java
(original)
+++ commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/algorithm/IndexOfInGenerator.java
Wed Aug 10 11:33:02 2011
@@ -38,7 +38,7 @@ public final class IndexOfInGenerator<T>
     /**
      * Helper procedure.
      */
-    private class IndexProcedure implements UnaryProcedure<T> {
+    private static class IndexProcedure<T> implements UnaryProcedure<T> {
         private final Generator<? extends T> generator;
         private final UnaryPredicate<? super T> pred;
         private long index = -1L;
@@ -71,7 +71,7 @@ public final class IndexOfInGenerator<T>
      * @param right UnaryPredicate
      */
     public Number evaluate(Generator<? extends T> left, UnaryPredicate<? super T>
right) {
-        IndexProcedure findProcedure = new IndexProcedure(left, right);
+        IndexProcedure<T> findProcedure = new IndexProcedure<T>(left, right);
         left.run(findProcedure);
         return findProcedure.index;
     }



Mime
View raw message