commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject svn commit: r1439637 - in /commons/proper/functor/branches/FUNCTOR-14-mm/core/src: main/java/org/apache/commons/functor/generator/loop/ test/java/org/apache/commons/functor/generator/loop/
Date Mon, 28 Jan 2013 21:21:26 GMT
Author: mbenson
Date: Mon Jan 28 21:21:25 2013
New Revision: 1439637

URL: http://svn.apache.org/viewvc?rev=1439637&view=rev
Log:
fix predicated generators' implementations/tests

Modified:
    commons/proper/functor/branches/FUNCTOR-14-mm/core/src/main/java/org/apache/commons/functor/generator/loop/GenerateUntil.java
    commons/proper/functor/branches/FUNCTOR-14-mm/core/src/main/java/org/apache/commons/functor/generator/loop/GenerateWhile.java
    commons/proper/functor/branches/FUNCTOR-14-mm/core/src/main/java/org/apache/commons/functor/generator/loop/UntilGenerate.java
    commons/proper/functor/branches/FUNCTOR-14-mm/core/src/main/java/org/apache/commons/functor/generator/loop/WhileGenerate.java
    commons/proper/functor/branches/FUNCTOR-14-mm/core/src/test/java/org/apache/commons/functor/generator/loop/TestGenerateUntil.java
    commons/proper/functor/branches/FUNCTOR-14-mm/core/src/test/java/org/apache/commons/functor/generator/loop/TestGenerateWhile.java
    commons/proper/functor/branches/FUNCTOR-14-mm/core/src/test/java/org/apache/commons/functor/generator/loop/TestUntilGenerate.java

Modified: commons/proper/functor/branches/FUNCTOR-14-mm/core/src/main/java/org/apache/commons/functor/generator/loop/GenerateUntil.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/branches/FUNCTOR-14-mm/core/src/main/java/org/apache/commons/functor/generator/loop/GenerateUntil.java?rev=1439637&r1=1439636&r2=1439637&view=diff
==============================================================================
--- commons/proper/functor/branches/FUNCTOR-14-mm/core/src/main/java/org/apache/commons/functor/generator/loop/GenerateUntil.java
(original)
+++ commons/proper/functor/branches/FUNCTOR-14-mm/core/src/main/java/org/apache/commons/functor/generator/loop/GenerateUntil.java
Mon Jan 28 21:21:25 2013
@@ -51,9 +51,12 @@ public class GenerateUntil<E> extends Lo
     public void run(final UnaryProcedure<? super E> proc) {
         getWrappedGenerator().run(new UnaryProcedure<E>() {
             public void run(E obj) {
+                if (isStopped()) {
+                    return;
+                }
                 proc.run(obj);
                 if (test.test(obj)) {
-                    GenerateUntil.this.stop();
+                    stop();
                 }
             }
         });

Modified: commons/proper/functor/branches/FUNCTOR-14-mm/core/src/main/java/org/apache/commons/functor/generator/loop/GenerateWhile.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/branches/FUNCTOR-14-mm/core/src/main/java/org/apache/commons/functor/generator/loop/GenerateWhile.java?rev=1439637&r1=1439636&r2=1439637&view=diff
==============================================================================
--- commons/proper/functor/branches/FUNCTOR-14-mm/core/src/main/java/org/apache/commons/functor/generator/loop/GenerateWhile.java
(original)
+++ commons/proper/functor/branches/FUNCTOR-14-mm/core/src/main/java/org/apache/commons/functor/generator/loop/GenerateWhile.java
Mon Jan 28 21:21:25 2013
@@ -51,9 +51,12 @@ public class GenerateWhile<E> extends Lo
     public void run(final UnaryProcedure<? super E> proc) {
         getWrappedGenerator().run(new UnaryProcedure<E>() {
             public void run(E obj) {
+                if (isStopped()) {
+                    return;
+                }
                 proc.run(obj);
                 if (!test.test(obj)) {
-                    GenerateWhile.this.stop();
+                    stop();
                 }
             }
         });

Modified: commons/proper/functor/branches/FUNCTOR-14-mm/core/src/main/java/org/apache/commons/functor/generator/loop/UntilGenerate.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/branches/FUNCTOR-14-mm/core/src/main/java/org/apache/commons/functor/generator/loop/UntilGenerate.java?rev=1439637&r1=1439636&r2=1439637&view=diff
==============================================================================
--- commons/proper/functor/branches/FUNCTOR-14-mm/core/src/main/java/org/apache/commons/functor/generator/loop/UntilGenerate.java
(original)
+++ commons/proper/functor/branches/FUNCTOR-14-mm/core/src/main/java/org/apache/commons/functor/generator/loop/UntilGenerate.java
Mon Jan 28 21:21:25 2013
@@ -51,8 +51,11 @@ public class UntilGenerate<E> extends Lo
     public void run(final UnaryProcedure<? super E> proc) {
         getWrappedGenerator().run(new UnaryProcedure<E>() {
             public void run(E obj) {
+                if (isStopped()) {
+                    return;
+                }
                 if (test.test(obj)) {
-                    UntilGenerate.this.stop();
+                    stop();
                 } else {
                     proc.run(obj);
                 }

Modified: commons/proper/functor/branches/FUNCTOR-14-mm/core/src/main/java/org/apache/commons/functor/generator/loop/WhileGenerate.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/branches/FUNCTOR-14-mm/core/src/main/java/org/apache/commons/functor/generator/loop/WhileGenerate.java?rev=1439637&r1=1439636&r2=1439637&view=diff
==============================================================================
--- commons/proper/functor/branches/FUNCTOR-14-mm/core/src/main/java/org/apache/commons/functor/generator/loop/WhileGenerate.java
(original)
+++ commons/proper/functor/branches/FUNCTOR-14-mm/core/src/main/java/org/apache/commons/functor/generator/loop/WhileGenerate.java
Mon Jan 28 21:21:25 2013
@@ -51,8 +51,11 @@ public class WhileGenerate<E> extends Lo
     public void run(final UnaryProcedure<? super E> proc) {
         getWrappedGenerator().run(new UnaryProcedure<E>() {
             public void run(E obj) {
+                if (isStopped()) {
+                    return;
+                }
                 if (!test.test(obj)) {
-                    WhileGenerate.this.stop();
+                    stop();
                 } else {
                     proc.run(obj);
                 }

Modified: commons/proper/functor/branches/FUNCTOR-14-mm/core/src/test/java/org/apache/commons/functor/generator/loop/TestGenerateUntil.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/branches/FUNCTOR-14-mm/core/src/test/java/org/apache/commons/functor/generator/loop/TestGenerateUntil.java?rev=1439637&r1=1439636&r2=1439637&view=diff
==============================================================================
--- commons/proper/functor/branches/FUNCTOR-14-mm/core/src/test/java/org/apache/commons/functor/generator/loop/TestGenerateUntil.java
(original)
+++ commons/proper/functor/branches/FUNCTOR-14-mm/core/src/test/java/org/apache/commons/functor/generator/loop/TestGenerateUntil.java
Mon Jan 28 21:21:25 2013
@@ -19,7 +19,12 @@ package org.apache.commons.functor.gener
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
 import org.apache.commons.functor.UnaryPredicate;
+import org.apache.commons.functor.UnaryProcedure;
 import org.apache.commons.functor.generator.Generator;
 import org.apache.commons.functor.generator.range.IntegerRange;
 import org.junit.After;
@@ -99,4 +104,18 @@ public class TestGenerateUntil {
         assertEquals(generateUntil.hashCode(), generateUntil.hashCode());
         assertEquals(generateUntil.hashCode(), new GenerateUntil<Integer>(wrappedGenerator,
isMoreThanFive).hashCode());
     }
+    
+    @Test
+    public void testGenerate() {
+        final List<Integer> numbersLESix = new ArrayList<Integer>();
+        generateUntil.run(new UnaryProcedure<Integer>() {
+            public void run( Integer obj ) {
+                numbersLESix.add(obj);
+            }
+        });
+        assertEquals(6, numbersLESix.size());
+
+        final List<Integer> expected = Arrays.asList(1, 2, 3, 4, 5, 6);
+        assertEquals(expected, numbersLESix);
+    }
 }

Modified: commons/proper/functor/branches/FUNCTOR-14-mm/core/src/test/java/org/apache/commons/functor/generator/loop/TestGenerateWhile.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/branches/FUNCTOR-14-mm/core/src/test/java/org/apache/commons/functor/generator/loop/TestGenerateWhile.java?rev=1439637&r1=1439636&r2=1439637&view=diff
==============================================================================
--- commons/proper/functor/branches/FUNCTOR-14-mm/core/src/test/java/org/apache/commons/functor/generator/loop/TestGenerateWhile.java
(original)
+++ commons/proper/functor/branches/FUNCTOR-14-mm/core/src/test/java/org/apache/commons/functor/generator/loop/TestGenerateWhile.java
Mon Jan 28 21:21:25 2013
@@ -19,7 +19,12 @@ package org.apache.commons.functor.gener
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
 import org.apache.commons.functor.UnaryPredicate;
+import org.apache.commons.functor.UnaryProcedure;
 import org.apache.commons.functor.generator.Generator;
 import org.apache.commons.functor.generator.range.IntegerRange;
 import org.junit.After;
@@ -100,4 +105,17 @@ public class TestGenerateWhile {
         assertEquals(generateWhile.hashCode(), new GenerateWhile<Integer>(wrappedGenerator,
isLessThanFive).hashCode());
     }
 
+    @Test
+    public void testGenerate() {
+        final List<Integer> numbersLEFive = new ArrayList<Integer>();
+        generateWhile.run(new UnaryProcedure<Integer>() {
+            public void run( Integer obj ) {
+                numbersLEFive.add(obj);
+            }
+        });
+        assertEquals(5, numbersLEFive.size());
+
+        List<Integer> expected = Arrays.asList(1, 2, 3, 4, 5);
+        assertEquals(expected, numbersLEFive);
+    }
 }

Modified: commons/proper/functor/branches/FUNCTOR-14-mm/core/src/test/java/org/apache/commons/functor/generator/loop/TestUntilGenerate.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/branches/FUNCTOR-14-mm/core/src/test/java/org/apache/commons/functor/generator/loop/TestUntilGenerate.java?rev=1439637&r1=1439636&r2=1439637&view=diff
==============================================================================
--- commons/proper/functor/branches/FUNCTOR-14-mm/core/src/test/java/org/apache/commons/functor/generator/loop/TestUntilGenerate.java
(original)
+++ commons/proper/functor/branches/FUNCTOR-14-mm/core/src/test/java/org/apache/commons/functor/generator/loop/TestUntilGenerate.java
Mon Jan 28 21:21:25 2013
@@ -41,9 +41,9 @@ public class TestUntilGenerate {
     private static final Integer FIVE = new Integer(5);
 
     private LoopGenerator<Integer> wrappedGenerator = null;
-    private UnaryPredicate<Integer> isLessThanFive = new UnaryPredicate<Integer>()
{
-        public boolean test( Integer obj ) {
-            return obj < FIVE;
+    private UnaryPredicate<Integer> isGreaterThanFive = new UnaryPredicate<Integer>()
{
+        public boolean test(Integer obj) {
+            return obj > FIVE;
         }
     };
     private LoopGenerator<Integer> untilGenerate = null;
@@ -51,13 +51,13 @@ public class TestUntilGenerate {
     @Before
     public void setUp() throws Exception {
         wrappedGenerator = new IntegerRange(1, 10);
-        untilGenerate = new UntilGenerate<Integer>(isLessThanFive, wrappedGenerator);
+        untilGenerate = new UntilGenerate<Integer>(isGreaterThanFive, wrappedGenerator);
     }
 
     @After
     public void tearDown() {
         wrappedGenerator = null;
-        isLessThanFive = null;
+        isGreaterThanFive = null;
         untilGenerate = null;
     }
 
@@ -71,7 +71,7 @@ public class TestUntilGenerate {
 
     @Test(expected=NullPointerException.class)
     public void testConstructorProhibitsNullWrappedGenerator() {
-        new UntilGenerate<Integer>(isLessThanFive, null);
+        new UntilGenerate<Integer>(isGreaterThanFive, null);
     }
 
     @Test(expected=NullPointerException.class)
@@ -81,7 +81,7 @@ public class TestUntilGenerate {
 
     @Test
     public void testEquals() {
-        Generator<Integer> anotherGenerate = new UntilGenerate<Integer>(isLessThanFive,
new IntegerRange(1, 10));
+        Generator<Integer> anotherGenerate = new UntilGenerate<Integer>(isGreaterThanFive,
new IntegerRange(1, 10));
         assertEquals(untilGenerate, untilGenerate);
         assertEquals(untilGenerate, anotherGenerate);
         assertTrue(!untilGenerate.equals((UntilGenerate<Integer>)null));
@@ -94,27 +94,27 @@ public class TestUntilGenerate {
 			}, new IntegerRange(1, 10));
         assertTrue(!untilGenerate.equals(aGenerateWithADifferentPredicate));
 
-        Generator<Integer> aGenerateWithADifferentWrapped = new UntilGenerate<Integer>(isLessThanFive,
new IntegerRange(1,2));
+        Generator<Integer> aGenerateWithADifferentWrapped = new UntilGenerate<Integer>(isGreaterThanFive,
new IntegerRange(1,2));
         assertTrue(!untilGenerate.equals(aGenerateWithADifferentWrapped));
     }
 
     @Test
     public void testHashcode() {
         assertEquals(untilGenerate.hashCode(), untilGenerate.hashCode());
-        assertEquals(untilGenerate.hashCode(), new UntilGenerate<Integer>(isLessThanFive,
wrappedGenerator).hashCode());
+        assertEquals(untilGenerate.hashCode(), new UntilGenerate<Integer>(isGreaterThanFive,
wrappedGenerator).hashCode());
     }
 
     @Test
     public void testGenerate() {
-        final List<Integer> numbersGreaterThanFive = new ArrayList<Integer>();
+        final List<Integer> numbersLEFive = new ArrayList<Integer>();
         untilGenerate.run(new UnaryProcedure<Integer>() {
             public void run( Integer obj ) {
-                numbersGreaterThanFive.add(obj);
+                numbersLEFive.add(obj);
             }
         });
-        assertEquals(5, numbersGreaterThanFive.size());
+        assertEquals(5, numbersLEFive.size());
 
-        final List<Integer> expected = Arrays.asList(5, 6, 7, 8, 9);
-        assertEquals(expected, numbersGreaterThanFive);
+        final List<Integer> expected = Arrays.asList(1, 2, 3, 4, 5);
+        assertEquals(expected, numbersLEFive);
     }
 }



Mime
View raw message