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/11/25 20:55:03 UTC

cvs commit: jakarta-commons-sandbox/functor/src/java/org/apache/commons/functor/generator/util CollectionTransformer.java

rwaldhoff    2003/11/25 11:55:03

  Modified:    functor/src/java/org/apache/commons/functor/generator
                        Transformer.java
               functor/src/test/org/apache/commons/functor/generator
                        TestAll.java
               functor/src/java/org/apache/commons/functor/generator/util
                        CollectionTransformer.java
  Added:       functor/src/java/org/apache/commons/functor/generator
                        BaseTransformer.java
               functor/src/test/org/apache/commons/functor/generator
                        TestBaseTransformer.java
  Log:
  * have Transformer extend UnaryFunction
  * add BaseTransformer
  * add tests
  
  Revision  Changes    Path
  1.2       +6 -4      jakarta-commons-sandbox/functor/src/java/org/apache/commons/functor/generator/Transformer.java
  
  Index: Transformer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/functor/src/java/org/apache/commons/functor/generator/Transformer.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Transformer.java	30 Jun 2003 11:00:13 -0000	1.1
  +++ Transformer.java	25 Nov 2003 19:55:02 -0000	1.2
  @@ -57,6 +57,8 @@
   
   package org.apache.commons.functor.generator;
   
  +import org.apache.commons.functor.UnaryFunction;
  +
   /**
    * Transformers are used to change a {@link Generator} into something else,
    * such as a {@link java.util.Collection}.
  @@ -66,6 +68,6 @@
    * @author  Jason Horman (jason@jhorman.org)
    */
   
  -public interface Transformer {
  -    public Object transform(Generator generator);
  +public interface Transformer extends UnaryFunction {
  +    Object transform(Generator generator);
   }
  
  
  
  1.1                  jakarta-commons-sandbox/functor/src/java/org/apache/commons/functor/generator/BaseTransformer.java
  
  Index: BaseTransformer.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/functor/src/java/org/apache/commons/functor/generator/BaseTransformer.java,v 1.1 2003/11/25 19:55:02 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.generator;
  
  /**
   * @since 1.0
   * @version $Revision: 1.1 $ $Date: 2003/11/25 19:55:02 $
   * @author Rodney Waldhoff
   */
  public abstract class BaseTransformer implements Transformer {
      public abstract Object transform(Generator gen);
  
      public Object evaluate(Object obj) {
          return transform((Generator)obj);
      }
  }
  
  
  1.4       +3 -2      jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/generator/TestAll.java
  
  Index: TestAll.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/generator/TestAll.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- TestAll.java	25 Nov 2003 18:22:50 -0000	1.3
  +++ TestAll.java	25 Nov 2003 19:55:03 -0000	1.4
  @@ -72,6 +72,7 @@
       public static Test suite() {
           TestSuite suite = new TestSuite();
           suite.addTest(TestGenerator.suite());
  +        suite.addTest(TestBaseTransformer.suite());
           suite.addTest(TestIteratorToGeneratorAdapter.suite());
           suite.addTest(org.apache.commons.functor.generator.util.TestAll.suite());
           return suite;
  
  
  
  1.1                  jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/generator/TestBaseTransformer.java
  
  Index: TestBaseTransformer.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/generator/TestBaseTransformer.java,v 1.1 2003/11/25 19:55:03 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.generator;
  
  import junit.framework.Test;
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  
  /**
   * @version $Revision: 1.1 $ $Date: 2003/11/25 19:55:03 $
   * @author Rodney Waldhoff
   */
  public class TestBaseTransformer extends TestCase {
  
      // Conventional
      // ------------------------------------------------------------------------
  
      public TestBaseTransformer(String name) {
          super(name);
      }
  
      public static Test suite() {
          return new TestSuite(TestBaseTransformer.class);
      }
  
      // Lifecycle
      // ------------------------------------------------------------------------
  
      // Tests
      // ------------------------------------------------------------------------
  
      public void testEvaluateDelegatesToTransform() {
          Transformer t = new MockTransformer();
          assertEquals(new Integer(1),t.evaluate(null));
          assertEquals(new Integer(2),t.evaluate(null));
          assertEquals(new Integer(3),t.evaluate(null));
      }
      
      // Classes
      // ------------------------------------------------------------------------
  
      static class MockTransformer extends BaseTransformer {
          public Object transform(Generator gen) {
              return new Integer(++timesCalled);
          }
          
          public int timesCalled = 0;
      }
  }
  
  
  1.3       +5 -5      jakarta-commons-sandbox/functor/src/java/org/apache/commons/functor/generator/util/CollectionTransformer.java
  
  Index: CollectionTransformer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/functor/src/java/org/apache/commons/functor/generator/util/CollectionTransformer.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- CollectionTransformer.java	17 Jul 2003 22:44:46 -0000	1.2
  +++ CollectionTransformer.java	25 Nov 2003 19:55:03 -0000	1.3
  @@ -61,8 +61,8 @@
   import java.util.Collection;
   
   import org.apache.commons.functor.UnaryProcedure;
  +import org.apache.commons.functor.generator.BaseTransformer;
   import org.apache.commons.functor.generator.Generator;
  -import org.apache.commons.functor.generator.Transformer;
   
   /**
    * Transforms a generator into a collection. If a collection is not passed into
  @@ -70,10 +70,10 @@
    *
    * @since 1.0
    * @version $Revision$ $Date$
  - * @author  Jason Horman (jason@jhorman.org)
  + * @author Jason Horman (jason@jhorman.org)
    */
   
  -public class CollectionTransformer implements Transformer {
  +public class CollectionTransformer extends BaseTransformer {
   
       /***************************************************
        *  Instance variables
  
  
  

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