You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by rw...@apache.org on 2003/12/01 06:29:09 UTC

cvs commit: jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/example/kata TestAll.java

rwaldhoff    2003/11/30 21:29:09

  Modified:    functor/src/test/org/apache/commons/functor/example
                        TestAll.java
  Added:       functor/src/test/org/apache/commons/functor/example/kata/one
                        SupermarketPricingExample.java Divide.java
                        BinaryFunctionUnaryFunction.java TestAll.java
                        Product.java Money.java Add.java Mod.java
                        ToMoney.java Subtract.java Multiply.java
               functor/src/test/org/apache/commons/functor/example/kata
                        TestAll.java
  Log:
  add kata one examples
  
  Revision  Changes    Path
  1.1                  jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/example/kata/one/SupermarketPricingExample.java
  
  Index: SupermarketPricingExample.java
  ===================================================================
  /* 
   * $Header: /home/cvs/jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/example/kata/one/SupermarketPricingExample.java,v 1.1 2003/12/01 05:29:08 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 apache@apache.org.
   *
   * 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.one;
  
  import junit.framework.Test;
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  
  import org.apache.commons.functor.UnaryFunction;
  import org.apache.commons.functor.adapter.IgnoreRightFunction;
  import org.apache.commons.functor.core.IdentityFunction;
  import org.apache.commons.functor.core.comparator.IsGreaterThan;
  import org.apache.commons.functor.core.composite.BinaryCompositeBinaryFunction;
  import org.apache.commons.functor.core.composite.CompositeUnaryFunction;
  import org.apache.commons.functor.core.composite.ConditionalUnaryFunction;
  
  /**
   * See http://pragprog.com/pragdave/Practices/Kata/KataOne.rdoc,v
   * for more information on this Kata.
   * 
   * @version $Revision: 1.1 $ $Date: 2003/12/01 05:29:08 $
   * @author Rodney Waldhoff
   */
  public class SupermarketPricingExample extends TestCase {
      public SupermarketPricingExample(String testName) {
          super(testName);
      }
  
      public static Test suite() {
          return new TestSuite(SupermarketPricingExample.class);
      }
      
      public void setUp() throws Exception {
          super.setUp();
      }
      
      public void tearDown() throws Exception {
          super.tearDown();
      }
      
      // tests
      //----------------------------------------------------------
      
      /*
       * The simplest form of pricing is simply a constant
       * rate.  In Dave's example, a can of beans costs $0.65,
       * and n cans of beans cost n*0.65.
       * 
       * This pricing rule simply multiplies the quantity by
       * a constant, e.g.:
       *   ToMoney.from(Multiply.by(65))
       * 
       * This case is so common, we may want to introduce a
       * special Product constructor to wrap up create the
       * functors for us.
       */
      public void testConstantPricePerUnit() throws Exception {
          {
              Product beans = new Product(
                  "Can of Beans", 
                  "SKU-0001",
                  ToMoney.from(Multiply.by(65)));
  
              assertEquals(new Money(0*65),beans.getPrice(0));
              assertEquals(new Money(1*65),beans.getPrice(1));
              assertEquals(new Money(2*65),beans.getPrice(2));
              assertEquals(new Money(3*65),beans.getPrice(3));
          }
          // or, using the speical constructor:
          {
              Product beans = new Product(
                  "Can of Beans", 
                  "SKU-0001",
                  65);
  
              assertEquals(new Money(0*65),beans.getPrice(0));
              assertEquals(new Money(1*65),beans.getPrice(1));
              assertEquals(new Money(2*65),beans.getPrice(2));
              assertEquals(new Money(3*65),beans.getPrice(3));
          }
      }
  
      /*
       * A slighly more complicated example is a bulk 
       * discount.  For example, bananas may be
       * $0.33 cents each, or 4 for a dollar ($1.00).
       * 
       * This rule is underspecified by itself, there are
       * at least two ways to interpret this pricing rule:
       * 
       * a) the cost is $0.33 cents for 3 or fewer, $0.25 
       *    for 4 or more
       * 
       * or
       *  
       * b) the cost is $1.00 for every group of 4, $0.33
       *    each for anything left over
       * 
       * although I think in practice, "4 for a dollar" 
       * usually means the former and not the latter.
       *
       * We can implement either:
       */    
      public void testFourForADollar_A() throws Exception {
          Product banana = new Product(
              "Banana", 
              "SKU-0002",
              ToMoney.from(
                  new ConditionalUnaryFunction(
                      IsGreaterThan.instance(new Integer(3)),
                      Multiply.by(25),
                      Multiply.by(33))));
  
          assertEquals(new Money(0*33),banana.getPrice(0));
          assertEquals(new Money(1*33),banana.getPrice(1));
          assertEquals(new Money(2*33),banana.getPrice(2));
          assertEquals(new Money(3*33),banana.getPrice(3));
          assertEquals(new Money(4*25),banana.getPrice(4));
          assertEquals(new Money(5*25),banana.getPrice(5));
          assertEquals(new Money(6*25),banana.getPrice(6));
          assertEquals(new Money(7*25),banana.getPrice(7));
          assertEquals(new Money(8*25),banana.getPrice(8));
      }
  
  
      public void testFourForADollar_B() throws Exception {
          Product banana = new Product(
              "Banana", 
              "SKU-0002",
              ToMoney.from(
                  new BinaryFunctionUnaryFunction(
                      new BinaryCompositeBinaryFunction(
                          Add.instance(),
                          IgnoreRightFunction.adapt(
                              new CompositeUnaryFunction(
                                  Multiply.by(100),
                                  Divide.by(4))),
                          IgnoreRightFunction.adapt(
                              new CompositeUnaryFunction(
                                  Multiply.by(33),
                                  Mod.by(4)))))));
          assertEquals(new Money(0*33+0*25),banana.getPrice(0));
          assertEquals(new Money(1*33+0*25),banana.getPrice(1));
          assertEquals(new Money(2*33+0*25),banana.getPrice(2));
          assertEquals(new Money(3*33+0*25),banana.getPrice(3));
          assertEquals(new Money(0*33+4*25),banana.getPrice(4));
          assertEquals(new Money(1*33+4*25),banana.getPrice(5));
          assertEquals(new Money(2*33+4*25),banana.getPrice(6));
          assertEquals(new Money(3*33+4*25),banana.getPrice(7));
          assertEquals(new Money(0*33+8*25),banana.getPrice(8));
      }
  
  
      /*
       * Another interesting pricing rule is 
       * something like "buy 2, get 1 free". 
       * 
       * This may be implemented using a formula
       * like:
       *   costPerUnit * (quantity - quantity / 2)
       *  
       * For example...
       */    
      public void testBuyTwoGetOneFree_1() throws Exception {
          Product apple = new Product(
              "Apple", 
              "SKU-0003",
              ToMoney.from(
                  new CompositeUnaryFunction(
                      Multiply.by(40),
                      new BinaryFunctionUnaryFunction(
                          new BinaryCompositeBinaryFunction(
                              Subtract.instance(),
                              IgnoreRightFunction.adapt(IdentityFunction.instance()),
                              IgnoreRightFunction.adapt(Divide.by(3)))))));
  
          assertEquals(new Money(0*40),apple.getPrice(0));
          assertEquals(new Money(1*40),apple.getPrice(1));
          assertEquals(new Money(2*40),apple.getPrice(2));       
          assertEquals(new Money(2*40),apple.getPrice(3)); 
          assertEquals(new Money(3*40),apple.getPrice(4));
          assertEquals(new Money(4*40),apple.getPrice(5));
          assertEquals(new Money(4*40),apple.getPrice(6));
          assertEquals(new Money(5*40),apple.getPrice(7));
          assertEquals(new Money(6*40),apple.getPrice(8));
          assertEquals(new Money(6*40),apple.getPrice(9));
          assertEquals(new Money(7*40),apple.getPrice(10));
      }
  
      /*
       * ...but our pricing rule is starting to get ugly,
       * and we haven't even considered things 
       * something like "buy 3, get 2 free", etc. 
       * 
       * Perhaps a special UnaryFunction instance is in
       * order:
       */    
  
      class BuyNGetMFree implements UnaryFunction {
         public BuyNGetMFree(int n, int m, int costPerUnit) {
             this.n = n;
             this.m = m;
             this.costPerUnit = costPerUnit;
         }
          
         public Object evaluate(Object obj) {
             return evaluate((Number)obj);
         }
                      
         public Object evaluate(Number num) {
             int quantity = num.intValue();
             int cost = 0;
             
             while(quantity >= n) {
                 // buy n
                 cost += n * costPerUnit;
                 quantity -= n;
                 // get m (or fewer) free 
                 quantity -= Math.min(quantity,m);                                  
             }
             // buy less than n
             cost += quantity * costPerUnit;
             
             return new Integer(cost);
         }
          
         private int n, m, costPerUnit;        
     }
  
      public void testBuyTwoGetOneFree_2() throws Exception {
          Product apple = new Product(
              "Apple", 
              "SKU-0003",
              ToMoney.from(new BuyNGetMFree(2,1,40)));
              
          assertEquals(new Money(0*40),apple.getPrice(0));
          assertEquals(new Money(1*40),apple.getPrice(1));
          assertEquals(new Money(2*40),apple.getPrice(2));       
          assertEquals(new Money(2*40),apple.getPrice(3)); 
          assertEquals(new Money(3*40),apple.getPrice(4));
          assertEquals(new Money(4*40),apple.getPrice(5));
          assertEquals(new Money(4*40),apple.getPrice(6));
          assertEquals(new Money(5*40),apple.getPrice(7));
          assertEquals(new Money(6*40),apple.getPrice(8));
          assertEquals(new Money(6*40),apple.getPrice(9));
          assertEquals(new Money(7*40),apple.getPrice(10));
      }
  
     public void testBuyThreeGetTwoFree() throws Exception {
          Product apple = new Product(
              "Apple", 
              "SKU-0003",
              ToMoney.from(new BuyNGetMFree(3,2,40)));
              
          assertEquals(new Money(0*40),apple.getPrice(0));
          assertEquals(new Money(1*40),apple.getPrice(1));
          assertEquals(new Money(2*40),apple.getPrice(2));       
          assertEquals(new Money(3*40),apple.getPrice(3)); 
          assertEquals(new Money(3*40),apple.getPrice(4));
          assertEquals(new Money(3*40),apple.getPrice(5));
          assertEquals(new Money(4*40),apple.getPrice(6));
          assertEquals(new Money(5*40),apple.getPrice(7));
          assertEquals(new Money(6*40),apple.getPrice(8));
          assertEquals(new Money(6*40),apple.getPrice(9));
          assertEquals(new Money(6*40),apple.getPrice(10));
          assertEquals(new Money(7*40),apple.getPrice(11));
      }
  
      public void testBuyTwoGetFiveFree() throws Exception {
           Product apple = new Product(
               "Apple", 
               "SKU-0003",
               ToMoney.from(new BuyNGetMFree(2,5,40)));
              
           assertEquals(new Money(0*40),apple.getPrice(0));
           assertEquals(new Money(1*40),apple.getPrice(1));
           assertEquals(new Money(2*40),apple.getPrice(2));       
           assertEquals(new Money(2*40),apple.getPrice(3)); 
           assertEquals(new Money(2*40),apple.getPrice(4));
           assertEquals(new Money(2*40),apple.getPrice(5));
           assertEquals(new Money(2*40),apple.getPrice(6));
           assertEquals(new Money(2*40),apple.getPrice(7));
           assertEquals(new Money(3*40),apple.getPrice(8));
           assertEquals(new Money(4*40),apple.getPrice(9));
           assertEquals(new Money(4*40),apple.getPrice(10));
           assertEquals(new Money(4*40),apple.getPrice(11));
           assertEquals(new Money(4*40),apple.getPrice(12));
           assertEquals(new Money(4*40),apple.getPrice(13));
           assertEquals(new Money(4*40),apple.getPrice(14));
           assertEquals(new Money(5*40),apple.getPrice(15));
       }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/example/kata/one/Divide.java
  
  Index: Divide.java
  ===================================================================
  /* 
   * $Header: /home/cvs/jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/example/kata/one/Divide.java,v 1.1 2003/12/01 05:29:08 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 apache@apache.org.
   *
   * 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.one;
  
  import org.apache.commons.functor.BinaryFunction;
  import org.apache.commons.functor.UnaryFunction;
  import org.apache.commons.functor.adapter.RightBoundFunction;
  
  /**
   * @version $Revision: 1.1 $ $Date: 2003/12/01 05:29:08 $
   * @author Rodney Waldhoff
   */
  public class Divide implements BinaryFunction {
      public Object evaluate(Object left, Object right) {
          return evaluate((Number)left,(Number)right);
      }
  
      public Object evaluate(Number left, Number right) {
          return new Integer(left.intValue() / right.intValue());
      }
      
      public static Divide instance() {
          return INSTANCE;
      }
  
      public static UnaryFunction by(int factor) {
          return new RightBoundFunction(instance(),new Integer(factor));
      }
      
      private static Divide INSTANCE = new Divide();
  }
  
  
  
  1.1                  jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/example/kata/one/BinaryFunctionUnaryFunction.java
  
  Index: BinaryFunctionUnaryFunction.java
  ===================================================================
  /* 
   * $Header: /home/cvs/jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/example/kata/one/BinaryFunctionUnaryFunction.java,v 1.1 2003/12/01 05:29:08 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 apache@apache.org.
   *
   * 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.one;
  
  import org.apache.commons.functor.BinaryFunction;
  import org.apache.commons.functor.UnaryFunction;
  
  /**
   * @version $Revision: 1.1 $ $Date: 2003/12/01 05:29:08 $
   * @author Rodney Waldhoff
   */
  public final class BinaryFunctionUnaryFunction implements UnaryFunction {
      public BinaryFunctionUnaryFunction(BinaryFunction f) {
          if(null == f) {
              throw new NullPointerException();
          } else {
              this.function = f;
          }
      }
      
      public Object evaluate(Object obj) {
          return function.evaluate(obj,obj);
      }
  
      public static UnaryFunction adapt(BinaryFunction f) {
          return null == f ? null : new BinaryFunctionUnaryFunction(f);
      }
      
      private BinaryFunction function;
  
  }
  
  
  
  1.1                  jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/example/kata/one/TestAll.java
  
  Index: TestAll.java
  ===================================================================
  /* 
   * $Header: /home/cvs/jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/example/kata/one/TestAll.java,v 1.1 2003/12/01 05:29:08 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 apache@apache.org.
   *
   * 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.one;
  
  import junit.framework.Test;
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  
  /**
   * See http://pragprog.com/pragdave/Practices/Kata/KataOne.rdoc,v
   * for more information on this Kata.
   * 
   * @version $Revision: 1.1 $ $Date: 2003/12/01 05:29:08 $
   * @author Rodney Waldhoff
   */
  public class TestAll extends TestCase {
      public TestAll(String testName) {
          super(testName);
      }
  
      public static Test suite() {
          TestSuite suite = new TestSuite();
  
          //suite.addTest(org.apache.commons.functor.example.kata.one.TestAll.suite());
          
          return suite;
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/example/kata/one/Product.java
  
  Index: Product.java
  ===================================================================
  /* 
   * $Header: /home/cvs/jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/example/kata/one/Product.java,v 1.1 2003/12/01 05:29:08 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 apache@apache.org.
   *
   * 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.one;
  
  import org.apache.commons.functor.UnaryFunction;
  
  
  /**
   * @version $Revision: 1.1 $ $Date: 2003/12/01 05:29:08 $
   * @author Rodney Waldhoff
   */
  public class Product {
      public Product(String name, String sku, int cost) {
          this(name,sku,ToMoney.from(Multiply.by(cost)));
      }
  
      public Product(String name, String sku, UnaryFunction price) {
          this.name = name;
          this.sku = sku;
          this.priceFunction = price;
      }
  
      public String getName() {
          return name;
      }
  
      public UnaryFunction getPriceFunction() {
          return priceFunction;
      }
  
      public String getSku() {
          return sku;
      }
  
      public void setName(String string) {
          name = string;
      }
  
      public void setPriceFunction(UnaryFunction function) {
          priceFunction = function;
      }
  
      public void setSku(String string) {
          sku = string;
      }
  
      public Money getPrice(int quantity) {
          return (Money)(priceFunction.evaluate(new Integer(quantity)));
      }
  
      private String name;
      private String sku;
      private UnaryFunction priceFunction;
  }
  
  
  
  1.1                  jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/example/kata/one/Money.java
  
  Index: Money.java
  ===================================================================
  /* 
   * $Header: /home/cvs/jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/example/kata/one/Money.java,v 1.1 2003/12/01 05:29:08 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 apache@apache.org.
   *
   * 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.one;
  
  /**
   * @version $Revision: 1.1 $ $Date: 2003/12/01 05:29:08 $
   * @author Rodney Waldhoff
   */
  public class Money {
      public Money(int cents) {
          this.cents = cents;
      }
      
      public int getValueAsCents() {
          return cents;
      }
  
      public boolean equals(Object obj) {
          if(obj instanceof Money) {
              Money that = (Money)obj;
              return getValueAsCents() == that.getValueAsCents();
          } else {
              return false;
          }
      }
  
      public int hashCode() {
          return getValueAsCents();
      }
      
      public String toString() {
          return getValueAsCents() + " cents";
      }
  
      private int cents;
  }
   
  
  
  1.1                  jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/example/kata/one/Add.java
  
  Index: Add.java
  ===================================================================
  /* 
   * $Header: /home/cvs/jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/example/kata/one/Add.java,v 1.1 2003/12/01 05:29:08 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 apache@apache.org.
   *
   * 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.one;
  
  import org.apache.commons.functor.BinaryFunction;
  import org.apache.commons.functor.UnaryFunction;
  import org.apache.commons.functor.adapter.LeftBoundFunction;
  
  /**
   * @version $Revision: 1.1 $ $Date: 2003/12/01 05:29:08 $
   * @author Rodney Waldhoff
   */
  public class Add implements BinaryFunction {
      public Object evaluate(Object left, Object right) {
          return evaluate((Number)left,(Number)right);
      }
  
      public Object evaluate(Number left, Number right) {
          return new Integer(left.intValue() + right.intValue());
      }
      
      public static Add instance() {
          return INSTANCE;
      }
  
      public static UnaryFunction to(int factor) {
          return new LeftBoundFunction(instance(),new Integer(factor));
      }
      
      private static Add INSTANCE = new Add();
  }
  
  
  
  1.1                  jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/example/kata/one/Mod.java
  
  Index: Mod.java
  ===================================================================
  /* 
   * $Header: /home/cvs/jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/example/kata/one/Mod.java,v 1.1 2003/12/01 05:29:08 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 apache@apache.org.
   *
   * 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.one;
  
  import org.apache.commons.functor.BinaryFunction;
  import org.apache.commons.functor.UnaryFunction;
  import org.apache.commons.functor.adapter.RightBoundFunction;
  
  /**
   * @version $Revision: 1.1 $ $Date: 2003/12/01 05:29:08 $
   * @author Rodney Waldhoff
   */
  public class Mod implements BinaryFunction {
      public Object evaluate(Object left, Object right) {
          return evaluate((Number)left,(Number)right);
      }
  
      public Object evaluate(Number left, Number right) {
          return new Integer(left.intValue() % right.intValue());
      }
      
      public static Mod instance() {
          return INSTANCE;
      }
  
      public static UnaryFunction by(int factor) {
          return new RightBoundFunction(instance(),new Integer(factor));
      }
      
      private static Mod INSTANCE = new Mod();
  }
  
  
  
  1.1                  jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/example/kata/one/ToMoney.java
  
  Index: ToMoney.java
  ===================================================================
  /* 
   * $Header: /home/cvs/jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/example/kata/one/ToMoney.java,v 1.1 2003/12/01 05:29:08 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 apache@apache.org.
   *
   * 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.one;
  
  import org.apache.commons.functor.UnaryFunction;
  import org.apache.commons.functor.core.composite.CompositeUnaryFunction;
  
  /**
   * @version $Revision: 1.1 $ $Date: 2003/12/01 05:29:08 $
   * @author Rodney Waldhoff
   */
  public class ToMoney implements UnaryFunction {
      public Object evaluate(Object cents) {
          return evaluate((Number)cents);
      }
  
      public Object evaluate(Number cents) {
          return new Money(cents.intValue());
      }
      
      public static ToMoney instance() {
          return INSTANCE;
      }
  
      public static UnaryFunction from(UnaryFunction fn) {
          return new CompositeUnaryFunction(instance(),fn);
      }
  
      private static ToMoney INSTANCE = new ToMoney();
  }
  
  
  
  1.1                  jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/example/kata/one/Subtract.java
  
  Index: Subtract.java
  ===================================================================
  /* 
   * $Header: /home/cvs/jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/example/kata/one/Subtract.java,v 1.1 2003/12/01 05:29:08 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 apache@apache.org.
   *
   * 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.one;
  
  import org.apache.commons.functor.BinaryFunction;
  import org.apache.commons.functor.UnaryFunction;
  import org.apache.commons.functor.adapter.LeftBoundFunction;
  
  /**
   * @version $Revision: 1.1 $ $Date: 2003/12/01 05:29:08 $
   * @author Rodney Waldhoff
   */
  public class Subtract implements BinaryFunction {
      public Object evaluate(Object left, Object right) {
          return evaluate((Number)left,(Number)right);
      }
  
      public Object evaluate(Number left, Number right) {
          return new Integer(left.intValue() - right.intValue());
      }
      
      public static Subtract instance() {
          return INSTANCE;
      }
  
      public static UnaryFunction from(int factor) {
          return new LeftBoundFunction(instance(),new Integer(factor));
      }
      
      private static Subtract INSTANCE = new Subtract();
  }
  
  
  
  1.1                  jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/example/kata/one/Multiply.java
  
  Index: Multiply.java
  ===================================================================
  /* 
   * $Header: /home/cvs/jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/example/kata/one/Multiply.java,v 1.1 2003/12/01 05:29:08 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 apache@apache.org.
   *
   * 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.one;
  
  import org.apache.commons.functor.BinaryFunction;
  import org.apache.commons.functor.UnaryFunction;
  import org.apache.commons.functor.adapter.LeftBoundFunction;
  
  /**
   * @version $Revision: 1.1 $ $Date: 2003/12/01 05:29:08 $
   * @author Rodney Waldhoff
   */
  public class Multiply implements BinaryFunction {
      public Object evaluate(Object left, Object right) {
          return evaluate((Number)left,(Number)right);
      }
  
      public Object evaluate(Number left, Number right) {
          return new Integer(left.intValue() * right.intValue());
      }
      
      public static Multiply instance() {
          return INSTANCE;
      }
  
      public static UnaryFunction by(int factor) {
          return new LeftBoundFunction(instance(),new Integer(factor));
      }
      
      private static Multiply INSTANCE = new Multiply();
  }
  
  
  
  1.7       +4 -2      jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/example/TestAll.java
  
  Index: TestAll.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/example/TestAll.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- TestAll.java	26 Nov 2003 01:18:28 -0000	1.6
  +++ TestAll.java	1 Dec 2003 05:29:09 -0000	1.7
  @@ -74,8 +74,10 @@
   
           suite.addTest(FlexiMapExample.suite());
           suite.addTest(QuicksortExample.suite());
  +
           suite.addTest(org.apache.commons.functor.example.lines.TestAll.suite());
           suite.addTest(org.apache.commons.functor.example.map.TestAll.suite());
  +        suite.addTest(org.apache.commons.functor.example.kata.TestAll.suite());
           
           return suite;
       }
  
  
  
  1.1                  jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/example/kata/TestAll.java
  
  Index: TestAll.java
  ===================================================================
  /* 
   * $Header: /home/cvs/jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/example/kata/TestAll.java,v 1.1 2003/12/01 05:29:09 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 apache@apache.org.
   *
   * 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;
  
  import junit.framework.Test;
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  
  /**
   * @version $Revision: 1.1 $ $Date: 2003/12/01 05:29:09 $
   * @author Rodney Waldhoff
   */
  public class TestAll extends TestCase {
      public TestAll(String testName) {
          super(testName);
      }
  
      public static Test suite() {
          TestSuite suite = new TestSuite();
  
          suite.addTest(org.apache.commons.functor.example.kata.one.TestAll.suite());
          
          return suite;
      }
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org