rwaldhoff    2003/12/01 17:01:59

  Modified:    functor/src/java/org/apache/commons/functor/generator
                        Generator.java BaseGenerator.java
               functor/src/test/org/apache/commons/functor/example/kata
                        TestAll.java
  Added:       functor/src/test/org/apache/commons/functor/example/kata/four
                        weather.txt TestSoccer.java Weather.java soccer.txt
                        TestAll.java BaseDataMunger.java TestWeather.java
                        Soccer.java
  Log:
  kata four examples
  
  Revision  Changes    Path
  1.1                  
jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/example/kata/four/weather.txt
  
  Index: weather.txt
  ===================================================================
  Daily Climate Data (Morristown, NJ)
  (Unofficial, Preliminary Data).
   Source: http://www.erh.noaa.gov/er/box/dailystns.html
  
   MMU June 2002
  
    Dy MxT   MnT   AvT   HDDay  AvDP 1HrP TPcpn WxType PDir AvSp Dir MxS SkyC MxR MnR 
AvSLP
  
     1  88    59    74          53.8       0.00 F       280  9.6 270  17  1.6  93 23 
1004.5
     2  79    63    71          46.5       0.00         330  8.7 340  23  3.3  70 28 
1004.5
     3  77    55    66          39.6       0.00         350  5.0 350   9  2.8  59 24 
1016.8
     4  77    59    68          51.1       0.00         110  9.1 130  12  8.6  62 40 
1021.1
     5  90    66    78          68.3       0.00 TFH     220  8.3 260  12  6.9  84 55 
1014.4
     6  81    61    71          63.7       0.00 RFH     030  6.2 030  13  9.7  93 60 
1012.7
     7  73    57    65          53.0       0.00 RF      050  9.5 050  17  5.3  90 48 
1021.8
     8  75    54    65          50.0       0.00 FH      160  4.2 150  10  2.6  93 41 
1026.3
     9  86    32*   59       6  61.5       0.00         240  7.6 220  12  6.0  78 46 
1018.6
    10  84    64    74          57.5       0.00 F       210  6.6 050   9  3.4  84 40 
1019.0
    11  91    59    75          66.3       0.00 H       250  7.1 230  12  2.5  93 45 
1012.6
    12  88    73    81          68.7       0.00 RTH     250  8.1 270  21  7.9  94 51 
1007.0
    13  70    59    65          55.0       0.00 H       150  3.0 150   8 10.0  83 59 
1012.6
    14  61    59    60       5  55.9       0.00 RF      060  6.7 080   9 10.0  93 87 
1008.6
    15  64    55    60       5  54.9       0.00 F       040  4.3 200   7  9.6  96 70 
1006.1
    16  79    59    69          56.7       0.00 F       250  7.6 240  21  7.8  87 44 
1007.0
    17  81    57    69          51.7       0.00 T       260  9.1 270  29* 5.2  90 34 
1012.5
    18  82    52    67          52.6       0.00         230  4.0 190  12  5.0  93 34 
1021.3
    19  81    61    71          58.9       0.00 H       250  5.2 230  12  5.3  87 44 
1028.5
    20  84    57    71          58.9       0.00 FH      150  6.3 160  13  3.6  90 43 
1032.5
    21  86    59    73          57.7       0.00 F       240  6.1 250  12  1.0  87 35 
1030.7
    22  90    64    77          61.1       0.00 H       250  6.4 230   9  0.2  78 38 
1026.4
    23  90    68    79          63.1       0.00 H       240  8.3 230  12  0.2  68 42 
1021.3
    24  90    77    84          67.5       0.00 H       350  8.5 010  14  6.9  74 48 
1018.2
    25  90    72    81          61.3       0.00         190  4.9 230   9  5.6  81 29 
1019.6
    26  97*   64    81          70.4       0.00 H       050  5.1 200  12  4.0 107 45 
1014.9
    27  91    72    82          69.7       0.00 RTH     250 12.1 230  17  7.1  90 47 
1009.0
    28  84    68    76          65.6       0.00 RTFH    280  7.6 340  16  7.0 100 51 
1011.0
    29  88    66    77          59.7       0.00         040  5.4 020   9  5.3  84 33 
1020.6
    30  90    45    68          63.6       0.00 H       240  6.0 220  17  4.8 200 41 
1022.7
    mo  82.9  60.5  71.7    16  58.8       0.00              6.9          5.3          
    
  
  
  
  1.1                  
jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/example/kata/four/TestSoccer.java
  
  Index: TestSoccer.java
  ===================================================================
  /* 
   * $Header: 
/home/cvs/jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/example/kata/four/TestSoccer.java,v
 1.1 2003/12/02 01:01:59 rwaldhoff Exp $
   * ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived 
   *    from this software without prior written permission. For written
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  package org.apache.commons.functor.example.kata.four;
  
  import junit.framework.Test;
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  
  /**
   * See http://pragprog.com/pragdave/Practices/Kata/KataFour.rdoc,v
   * for more information on this Kata.
   * 
   * @version $Revision: 1.1 $ $Date: 2003/12/02 01:01:59 $
   * @author Rodney Waldhoff
   */
  public class TestSoccer extends TestCase {
      public TestSoccer(String testName) {
          super(testName);
      }
  
      public static Test suite() {
          return new TestSuite(TestSoccer.class);
      }
      
      public void test() throws Exception {
          assertEquals("Aston_Villa",new Soccer().evaluate("soccer.txt"));            
      }
  
  }
  
  
  
  
  1.1                  
jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/example/kata/four/Weather.java
  
  Index: Weather.java
  ===================================================================
  /* 
   * $Header: 
/home/cvs/jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/example/kata/four/Weather.java,v
 1.1 2003/12/02 01:01:59 rwaldhoff Exp $
   * ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived 
   *    from this software without prior written permission. For written
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  package org.apache.commons.functor.example.kata.four;
  
  
  /**
   * @version $Revision: 1.1 $ $Date: 2003/12/02 01:01:59 $
   * @author Rodney Waldhoff
   */
  public class Weather extends BaseDataMunger {
      public Object evaluate(Object obj) {
          return getEvaluator(0,1,2).evaluate(obj);
      }
  }
  
  
  
  1.1                  
jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/example/kata/four/soccer.txt
  
  Index: soccer.txt
  ===================================================================
  English Premier League, 2001/2002 Tables
  
  Source http://sunsite.tut.fi/rec/riku/soccer_data/tab/93_94/table.eng0.01_02.html
         Team            P     W    L   D    F      A     Pts
      1. Arsenal         38    26   9   3    79  -  36    87
      2. Liverpool       38    24   8   6    67  -  30    80
      3. Manchester_U    38    24   5   9    87  -  45    77
      4. Newcastle       38    21   8   9    74  -  52    71
      5. Leeds           38    18  12   8    53  -  37    66
      6. Chelsea         38    17  13   8    66  -  38    64
      7. West_Ham        38    15   8  15    48  -  57    53
      8. Aston_Villa     38    12  14  12    46  -  47    50
      9. Tottenham       38    14   8  16    49  -  53    50
     10. Blackburn       38    12  10  16    55  -  51    46
     11. Southampton     38    12   9  17    46  -  54    45
     12. Middlesbrough   38    12   9  17    35  -  47    45
     13. Fulham          38    10  14  14    36  -  44    44
     14. Charlton        38    10  14  14    38  -  49    44
     15. Everton         38    11  10  17    45  -  57    43
     16. Bolton          38     9  13  16    44  -  62    40
     17. Sunderland      38    10  10  18    29  -  51    40
     -------------------------------------------------------
     18. Ipswich         38     9   9  20    41  -  64    36
     19. Derby           38     8   6  24    33  -  63    30
     20. Leicester       38     5  13  20    30  -  64    28
  
  
  
  
  1.1                  
jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/example/kata/four/TestAll.java
  
  Index: TestAll.java
  ===================================================================
  /* 
   * $Header: 
/home/cvs/jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/example/kata/four/TestAll.java,v
 1.1 2003/12/02 01:01:59 rwaldhoff Exp $
   * ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived 
   *    from this software without prior written permission. For written
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  package org.apache.commons.functor.example.kata.four;
  
  import junit.framework.Test;
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  
  /**
   * See http://pragprog.com/pragdave/Practices/Kata/KataTwo.rdoc,v
   * for more information on this Kata.
   * 
   * @version $Revision: 1.1 $ $Date: 2003/12/02 01:01:59 $
   * @author Rodney Waldhoff
   */
  public class TestAll extends TestCase {
      public TestAll(String testName) {
          super(testName);
      }
  
      public static Test suite() {
          TestSuite suite = new TestSuite();
          suite.addTest(TestWeather.suite());
          suite.addTest(TestSoccer.suite());
          return suite;
      }
  }
  
  
  
  1.1                  
jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/example/kata/four/BaseDataMunger.java
  
  Index: BaseDataMunger.java
  ===================================================================
  /* 
   * $Header: 
/home/cvs/jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/example/kata/four/BaseDataMunger.java,v
 1.1 2003/12/02 01:01:59 rwaldhoff Exp $
   * ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived 
   *    from this software without prior written permission. For written
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  package org.apache.commons.functor.example.kata.four;
  
  import java.io.InputStreamReader;
  import java.io.Reader;
  import java.util.StringTokenizer;
  
  import org.apache.commons.functor.Algorithms;
  import org.apache.commons.functor.BinaryFunction;
  import org.apache.commons.functor.UnaryFunction;
  import org.apache.commons.functor.UnaryPredicate;
  import org.apache.commons.functor.core.composite.CompositeUnaryFunction;
  import org.apache.commons.functor.example.lines.Lines;
  
  /**
   * @version $Revision: 1.1 $ $Date: 2003/12/02 01:01:59 $
   * @author Rodney Waldhoff
   */
  public abstract class BaseDataMunger implements UnaryFunction {
  
      protected final UnaryFunction getEvaluator(final int selected, final int col1, 
final int col2) {
          return new UnaryFunction() {
              public Object evaluate(final Object obj) {
                  return nthColumn(selected).evaluate(
                      Algorithms.inject(
                          Lines.from(resource(obj)).where(nthColumnIsInteger(0)), 
                          null,
                          new BinaryFunction() {
                              public Object evaluate(Object left, Object right) {
                                  return lesserSpread(col1,col2).evaluate(left,right);
                              }
                          }));
              }
          };
      }
      
  
      /** 
       * A UnaryFunction that selects the nth column from the input 
       * String and converts it to an Integer.
       */
      private final UnaryFunction nthInteger(int n) {  
          return new CompositeUnaryFunction(toInteger(),nthColumn(n));
      }
  
      /** 
       * Selects the nth column from the input 
       * obj (String) and converts it to an int.
       */
      private final int nthInteger(int n, Object obj) {
          return toInt(nthInteger(n).evaluate(obj));  
      }
  
      /** 
       * A UnaryPredicate that returns true iff the the nth column 
       * in the input String can be converted into an Integer.
       * See [EMAIL PROTECTED] #toInteger}.
       */
      private final UnaryPredicate nthColumnIsInteger(final int n) {
          return new UnaryPredicate() {
              public boolean test(Object obj) {
                  try {
                      nthInteger(n).evaluate(obj);
                      return true;
                  } catch(RuntimeException e) {
                      return false;
                  }
              }
          };
      }
      
      /** 
       * A UnaryFunction that returns the nth whitespace
       * delimited column in the given input String, or 
       * null if there is no such column.
       */
      private final static UnaryFunction nthColumn(final int n) {
          return new UnaryFunction() {
              public Object evaluate(Object obj) {
                  StringTokenizer toker = new StringTokenizer((String)obj);
                  for(int count = 0; count < n && toker.hasMoreTokens();count++) {
                      toker.nextToken();
                  }
                  return toker.hasMoreTokens() ? toker.nextToken() : null;
              }
          };
      }
      
      /** 
       * Accessor method for [EMAIL PROTECTED] #TO_INTEGER}.
       */
      private final UnaryFunction toInteger() {
          return TO_INTEGER;
      }
      
      /** 
       * Converts the input String to an Integer.
       * Any trailing characters that aren't digits
       * are ignored.
       */
      private final UnaryFunction TO_INTEGER = new UnaryFunction() {
          public Object evaluate(Object obj) {
              return evaluate((String)obj);
          }
          
          public Object evaluate(String str) {
              StringBuffer buf = new StringBuffer();
              for(int i=0;i<str.length();i++) {
                  if(Character.isDigit(str.charAt(i))) {
                      buf.append(str.charAt(i));
                  } else {
                      break;
                  }
              }
              try {
                  return new Integer(buf.toString());
              } catch(NumberFormatException e) {
                  throw new NumberFormatException(str);
              }
          }
      };
  
      /** 
       * A BinaryFunction that will calcuate the absolute
       * difference between col1 and col2 in the given 
       * String arguments, and return the argument
       * whose difference is smallest.
       */
      private final BinaryFunction lesserSpread(final int col1, final int col2) {
          return new BinaryFunction() {
              public Object evaluate(Object left, Object right) {
                  if(null == left) {
                      return right;
                  } else {
                      return absSpread(left) < absSpread(right) ? left : right;
                  }
              }
              
              private int absSpread(Object obj) {
                  return Math.abs(nthInteger(col1,obj) - nthInteger(col2,obj));
              }
          };
      }
  
      /**
       * Convert the given Number into an int.
       */    
      private int toInt(Object obj) {
          return ((Number)obj).intValue();
      }
      
      /**
       * Open an InputStreamReader on the specified (String) resource.
       */    
      private Reader resource(Object resource) {
          return new 
InputStreamReader(getClass().getResourceAsStream((String)resource)); 
      }
  }
  
  
  
  1.1                  
jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/example/kata/four/TestWeather.java
  
  Index: TestWeather.java
  ===================================================================
  /* 
   * $Header: 
/home/cvs/jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/example/kata/four/TestWeather.java,v
 1.1 2003/12/02 01:01:59 rwaldhoff Exp $
   * ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived 
   *    from this software without prior written permission. For written
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  package org.apache.commons.functor.example.kata.four;
  
  import junit.framework.Test;
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  
  /**
   * See http://pragprog.com/pragdave/Practices/Kata/KataFour.rdoc,v
   * for more information on this Kata.
   * 
   * @version $Revision: 1.1 $ $Date: 2003/12/02 01:01:59 $
   * @author Rodney Waldhoff
   */
  public class TestWeather extends TestCase {
      public TestWeather(String testName) {
          super(testName);
      }
  
      public static Test suite() {
          return new TestSuite(TestWeather.class);
      }
  
      public void test() throws Exception {
          assertEquals("14",new Weather().evaluate("weather.txt"));            
      }
  
  }
  
  
  
  
  1.1                  
jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/example/kata/four/Soccer.java
  
  Index: Soccer.java
  ===================================================================
  /* 
   * $Header: 
/home/cvs/jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/example/kata/four/Soccer.java,v
 1.1 2003/12/02 01:01:59 rwaldhoff Exp $
   * ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived 
   *    from this software without prior written permission. For written
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  package org.apache.commons.functor.example.kata.four;
  
  
  /**
   * @version $Revision: 1.1 $ $Date: 2003/12/02 01:01:59 $
   * @author Rodney Waldhoff
   */
  public class Soccer extends BaseDataMunger {
      public Object evaluate(Object obj) {
          return getEvaluator(1,6,8).evaluate(obj);
      }
  }
  
  
  
  1.8       +4 -2      
jakarta-commons-sandbox/functor/src/java/org/apache/commons/functor/generator/Generator.java
  
  Index: Generator.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons-sandbox/functor/src/java/org/apache/commons/functor/generator/Generator.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- Generator.java    25 Nov 2003 21:16:15 -0000      1.7
  +++ Generator.java    2 Dec 2003 01:01:59 -0000       1.8
  @@ -91,6 +91,8 @@
       public abstract Generator reject(UnaryPredicate pred);
       /** See [EMAIL PROTECTED] org.apache.commons.functor.Algorithms#select}. */
       public abstract Generator select(UnaryPredicate pred);
  +    /** See [EMAIL PROTECTED] org.apache.commons.functor.Algorithms#select}. */
  +    public abstract Generator where(UnaryPredicate pred);
       /** See [EMAIL PROTECTED] org.apache.commons.functor.Algorithms#until}. */
       public abstract Generator until(UnaryPredicate pred);
       /**
  
  
  
  1.5       +7 -2      
jakarta-commons-sandbox/functor/src/java/org/apache/commons/functor/generator/BaseGenerator.java
  
  Index: BaseGenerator.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons-sandbox/functor/src/java/org/apache/commons/functor/generator/BaseGenerator.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- BaseGenerator.java        25 Nov 2003 21:16:15 -0000      1.4
  +++ BaseGenerator.java        2 Dec 2003 01:01:59 -0000       1.5
  @@ -155,6 +155,11 @@
           return Algorithms.select(this, pred);
       }
   
  +    /** See [EMAIL PROTECTED] Algorithms#select}. */
  +    public final Generator where(UnaryPredicate pred) {
  +        return Algorithms.select(this, pred);
  +    }
  +
       /** See [EMAIL PROTECTED] Algorithms#until}. */
       public final Generator until(UnaryPredicate pred) {
           return Algorithms.until(this, pred);
  
  
  
  1.3       +3 -2      
jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/example/kata/TestAll.java
  
  Index: TestAll.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/example/kata/TestAll.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TestAll.java      1 Dec 2003 07:30:24 -0000       1.2
  +++ TestAll.java      2 Dec 2003 01:01:59 -0000       1.3
  @@ -73,6 +73,7 @@
           TestSuite suite = new TestSuite();
           suite.addTest(org.apache.commons.functor.example.kata.one.TestAll.suite());
           suite.addTest(org.apache.commons.functor.example.kata.two.TestAll.suite());
  +        suite.addTest(org.apache.commons.functor.example.kata.four.TestAll.suite());
           return suite;
       }
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to