commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject svn commit: r658418 - in /commons/sandbox/functor/trunk/src: main/java/org/apache/commons/functor/core/algorithm/ main/java/org/apache/commons/functor/generator/ test/java/org/apache/commons/functor/ test/java/org/apache/commons/functor/example/ test/j...
Date Tue, 20 May 2008 20:40:33 GMT
Author: mbenson
Date: Tue May 20 13:40:32 2008
New Revision: 658418

URL: http://svn.apache.org/viewvc?rev=658418&view=rev
Log:
merge from branch: add functor implementations of Algorithms algorithms

Added:
    commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/algorithm/
      - copied from r656297, commons/sandbox/functor/branches/mjbRadicalExperimentation/src/main/java/org/apache/commons/functor/core/algorithm/
    commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/algorithm/DoUntil.java
      - copied unchanged from r656297, commons/sandbox/functor/branches/mjbRadicalExperimentation/src/main/java/org/apache/commons/functor/core/algorithm/DoUntil.java
    commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/algorithm/DoWhile.java
      - copied unchanged from r656297, commons/sandbox/functor/branches/mjbRadicalExperimentation/src/main/java/org/apache/commons/functor/core/algorithm/DoWhile.java
    commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/algorithm/FindWithinGenerator.java
      - copied unchanged from r656297, commons/sandbox/functor/branches/mjbRadicalExperimentation/src/main/java/org/apache/commons/functor/core/algorithm/FindWithinGenerator.java
    commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/algorithm/FoldLeft.java
      - copied unchanged from r656297, commons/sandbox/functor/branches/mjbRadicalExperimentation/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
      - copied unchanged from r656297, commons/sandbox/functor/branches/mjbRadicalExperimentation/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
      - copied unchanged from r656297, commons/sandbox/functor/branches/mjbRadicalExperimentation/src/main/java/org/apache/commons/functor/core/algorithm/GeneratorContains.java
    commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/algorithm/InPlaceTransform.java
      - copied unchanged from r656297, commons/sandbox/functor/branches/mjbRadicalExperimentation/src/main/java/org/apache/commons/functor/core/algorithm/InPlaceTransform.java
    commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/algorithm/IndexOfInGenerator.java
      - copied unchanged from r656297, commons/sandbox/functor/branches/mjbRadicalExperimentation/src/main/java/org/apache/commons/functor/core/algorithm/IndexOfInGenerator.java
    commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/algorithm/PredicatedLoop.java
      - copied unchanged from r656297, commons/sandbox/functor/branches/mjbRadicalExperimentation/src/main/java/org/apache/commons/functor/core/algorithm/PredicatedLoop.java
    commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/algorithm/RecursiveEvaluation.java
      - copied unchanged from r656297, commons/sandbox/functor/branches/mjbRadicalExperimentation/src/main/java/org/apache/commons/functor/core/algorithm/RecursiveEvaluation.java
    commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/algorithm/RemoveMatching.java
      - copied unchanged from r656297, commons/sandbox/functor/branches/mjbRadicalExperimentation/src/main/java/org/apache/commons/functor/core/algorithm/RemoveMatching.java
    commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/algorithm/RetainMatching.java
      - copied unchanged from r656297, commons/sandbox/functor/branches/mjbRadicalExperimentation/src/main/java/org/apache/commons/functor/core/algorithm/RetainMatching.java
    commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/algorithm/UntilDo.java
      - copied unchanged from r656297, commons/sandbox/functor/branches/mjbRadicalExperimentation/src/main/java/org/apache/commons/functor/core/algorithm/UntilDo.java
    commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/algorithm/WhileDo.java
      - copied unchanged from r656297, commons/sandbox/functor/branches/mjbRadicalExperimentation/src/main/java/org/apache/commons/functor/core/algorithm/WhileDo.java
    commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/algorithm/package.html
      - copied unchanged from r656297, commons/sandbox/functor/branches/mjbRadicalExperimentation/src/main/java/org/apache/commons/functor/core/algorithm/package.html
    commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/generator/GenerateUntil.java
      - copied unchanged from r656297, commons/sandbox/functor/branches/mjbRadicalExperimentation/src/main/java/org/apache/commons/functor/generator/GenerateUntil.java
    commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/generator/GenerateWhile.java
      - copied unchanged from r656291, commons/sandbox/functor/branches/mjbRadicalExperimentation/src/main/java/org/apache/commons/functor/generator/GenerateWhile.java
    commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/generator/TransformedGenerator.java
      - copied unchanged from r656297, commons/sandbox/functor/branches/mjbRadicalExperimentation/src/main/java/org/apache/commons/functor/generator/TransformedGenerator.java
    commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/generator/UntilGenerate.java
      - copied unchanged from r656297, commons/sandbox/functor/branches/mjbRadicalExperimentation/src/main/java/org/apache/commons/functor/generator/UntilGenerate.java
    commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/generator/WhileGenerate.java
      - copied unchanged from r656292, commons/sandbox/functor/branches/mjbRadicalExperimentation/src/main/java/org/apache/commons/functor/generator/WhileGenerate.java
Modified:
    commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/TestAlgorithms.java
    commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/example/QuicksortExample.java
    commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/example/map/FixedSizeMap.java

Modified: commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/TestAlgorithms.java
URL: http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/TestAlgorithms.java?rev=658418&r1=658417&r2=658418&view=diff
==============================================================================
--- commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/TestAlgorithms.java
(original)
+++ commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/TestAlgorithms.java
Tue May 20 13:40:32 2008
@@ -113,9 +113,9 @@
     }
 
     public void testDetect() {
-        assertEquals(new Integer(3),Algorithms.detect(list.iterator(),equalsThree));
+        assertEquals(new Integer(3),Algorithms.detect(IteratorToGeneratorAdapter.adapt(list.iterator()),equalsThree));
         try {
-            Algorithms.detect(list.iterator(),equalsTwentyThree);
+            Algorithms.detect(IteratorToGeneratorAdapter.adapt(list.iterator()),equalsTwentyThree);
             fail("Expected NoSuchElementException");
         } catch(NoSuchElementException e) {
             // expected
@@ -123,37 +123,37 @@
     }
 
     public void testDetectIfNone() {
-        assertEquals(new Integer(3),Algorithms.detect(list.iterator(),equalsThree,"Xyzzy"));
-        assertEquals("Xyzzy",Algorithms.detect(list.iterator(),equalsTwentyThree,"Xyzzy"));
+        assertEquals(new Integer(3),Algorithms.detect(IteratorToGeneratorAdapter.adapt(list.iterator()),equalsThree,"Xyzzy"));
+        assertEquals("Xyzzy",Algorithms.detect(IteratorToGeneratorAdapter.adapt(list.iterator()),equalsTwentyThree,"Xyzzy"));
     }
 
     public void testForEach() {
         Summer summer = new Summer();
-        Algorithms.foreach(list.iterator(),summer);
+        Algorithms.foreach(IteratorToGeneratorAdapter.adapt(list.iterator()),summer);
         assertEquals(sum,summer.sum);
     }
 
     public void testSelect1() {
-        Collection result = Algorithms.collect(Algorithms.select(list.iterator(),isEven));
+        Collection result = Algorithms.select(IteratorToGeneratorAdapter.adapt(list.iterator()),isEven).toCollection();
         assertNotNull(result);
         assertEquals(evens,result);
     }
 
     public void testSelect2() {
         ArrayList result = new ArrayList();
-        assertSame(result,Algorithms.collect(Algorithms.select(list.iterator(),isEven),result));
+        assertSame(result,Algorithms.select(IteratorToGeneratorAdapter.adapt(list.iterator()),isEven).to(result));
         assertEquals(evens,result);
     }
 
     public void testReject1() {
-        Collection result = Algorithms.collect(Algorithms.reject(list.iterator(),isOdd));
+        Collection result = Algorithms.reject(IteratorToGeneratorAdapter.adapt(list.iterator()),isOdd).toCollection();
         assertNotNull(result);
         assertEquals(evens,result);
     }
 
     public void testReject2() {
         ArrayList result = new ArrayList();
-        assertSame(result,Algorithms.collect(Algorithms.reject(list.iterator(),isOdd),result));
+        assertSame(result,Algorithms.reject(IteratorToGeneratorAdapter.adapt(list.iterator()),isOdd).to(result));
         assertEquals(evens,result);
     }
 
@@ -194,14 +194,16 @@
     }
 
     public void testApply() {
-        Collection result = IteratorToGeneratorAdapter.adapt(Algorithms.apply(list.iterator(),new
Doubler())).toCollection();
+        Collection result = Algorithms.apply(IteratorToGeneratorAdapter.adapt(list.iterator()),
new Doubler())
+                .toCollection();
         assertNotNull(result);
         assertEquals(doubled,result);
     }
 
     public void testApply2() {
         Set set = new HashSet();
-        assertSame(set,IteratorToGeneratorAdapter.adapt(Algorithms.apply(list.iterator(),Identity.instance())).to(set));
+        assertSame(set, Algorithms.apply(IteratorToGeneratorAdapter.adapt(list.iterator()),
Identity.instance())
+                .to(set));
         assertEquals(list.size(),set.size());
         for (Iterator iter = list.iterator(); iter.hasNext(); ) {
             assertTrue(set.contains(iter.next()));
@@ -210,7 +212,8 @@
 
     public void testApply3() {
         Set set = new HashSet();
-        assertSame(set,IteratorToGeneratorAdapter.adapt(Algorithms.apply(listWithDuplicates.iterator(),Identity.instance())).to(set));
+        assertSame(set, Algorithms.apply(IteratorToGeneratorAdapter.adapt(listWithDuplicates.iterator()),
+                Identity.instance()).to(set));
         assertTrue(listWithDuplicates.size() > set.size());
         for (Iterator iter = listWithDuplicates.iterator(); iter.hasNext(); ) {
             assertTrue(set.contains(iter.next()));
@@ -218,13 +221,13 @@
     }
 
     public void testContains() {
-        assertTrue(Algorithms.contains(list.iterator(),equalsThree));
-        assertTrue(!Algorithms.contains(list.iterator(),equalsTwentyThree));
+        assertTrue(Algorithms.contains(IteratorToGeneratorAdapter.adapt(list.iterator()),equalsThree));
+        assertTrue(!Algorithms.contains(IteratorToGeneratorAdapter.adapt(list.iterator()),equalsTwentyThree));
     }
 
     public void testInject() {
-        Object result = Algorithms.inject(
-            list.iterator(),
+        Object result = Algorithms.inject(IteratorToGeneratorAdapter.adapt(
+            list.iterator()),
             new Integer(0),
             new BinaryFunction() {
                 public Object evaluate(Object a, Object b) {
@@ -235,7 +238,7 @@
     }
 
     public void testLimit() {
-        Collection col = IteratorToGeneratorAdapter.adapt(Algorithms.until(list.iterator(),
new Offset(2))).toCollection();
+        Collection col = Algorithms.until(IteratorToGeneratorAdapter.adapt(list.iterator()),
new Offset(2)).toCollection();
         assertEquals("[0, 1]", col.toString());
     }
 

Modified: commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/example/QuicksortExample.java
URL: http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/example/QuicksortExample.java?rev=658418&r1=658417&r2=658418&view=diff
==============================================================================
--- commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/example/QuicksortExample.java
(original)
+++ commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/example/QuicksortExample.java
Tue May 20 13:40:32 2008
@@ -33,6 +33,7 @@
 import org.apache.commons.functor.core.comparator.IsGreaterThanOrEqual;
 import org.apache.commons.functor.core.comparator.IsLessThan;
 import org.apache.commons.functor.core.composite.ConditionalUnaryFunction;
+import org.apache.commons.functor.generator.IteratorToGeneratorAdapter;
 
 /*
  * ----------------------------------------------------------------------------
@@ -461,9 +462,9 @@
  */
     private BinaryFunction lesserTail = new ObjectListFunction() {
         public Object evaluate(Object head, List tail) {
-            return Algorithms.collect(Algorithms.select(
-                tail.iterator(),
-                IsLessThan.instance((Comparable) head)));
+            return Algorithms.select(
+                    IteratorToGeneratorAdapter.adapt(tail.iterator()),
+                IsLessThan.instance((Comparable) head)).toCollection();
         }
     };
 
@@ -474,9 +475,9 @@
  */
     private BinaryFunction greaterTail = new ObjectListFunction() {
         public Object evaluate(Object head, List tail) {
-            return Algorithms.collect(Algorithms.select(
-                tail.iterator(),
-                IsGreaterThanOrEqual.instance((Comparable) head)));
+            return Algorithms.select(
+                    IteratorToGeneratorAdapter.adapt(tail.iterator()),
+                IsGreaterThanOrEqual.instance((Comparable) head)).toCollection();
         }
     };
 

Modified: commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/example/map/FixedSizeMap.java
URL: http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/example/map/FixedSizeMap.java?rev=658418&r1=658417&r2=658418&view=diff
==============================================================================
--- commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/example/map/FixedSizeMap.java
(original)
+++ commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/example/map/FixedSizeMap.java
Tue May 20 13:40:32 2008
@@ -24,6 +24,7 @@
 import org.apache.commons.functor.BinaryProcedure;
 import org.apache.commons.functor.adapter.BinaryProcedureBinaryFunction;
 import org.apache.commons.functor.core.composite.UnaryNot;
+import org.apache.commons.functor.generator.IteratorToGeneratorAdapter;
 
 /**
  * @version $Revision$ $Date$
@@ -50,7 +51,7 @@
                 Map dest = (Map) a;
                 Map src = (Map) b;
 
-                if (Algorithms.contains(src.keySet().iterator(),UnaryNot.not(new ContainsKey(dest))))
{
+                if (Algorithms.contains(IteratorToGeneratorAdapter.adapt(src.keySet().iterator()),UnaryNot.not(new
ContainsKey(dest)))) {
                     throw new IllegalArgumentException();
                 } else {
                     dest.putAll(src);



Mime
View raw message