commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rwaldh...@apache.org
Subject cvs commit: jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/example FlexiMapExample.java TestAll.java
Date Tue, 04 Mar 2003 21:33:57 GMT
rwaldhoff    2003/03/04 13:33:56

  Modified:    functor/src/test/org/apache/commons/functor/adapter
                        TestAll.java
               functor/src/test/org/apache/commons/functor/example
                        TestAll.java
  Added:       functor/src/java/org/apache/commons/functor/adapter
                        IgnoreLeftFunction.java IgnoreLeftPredicate.java
                        IgnoreLeftProcedure.java IgnoreRightFunction.java
                        IgnoreRightPredicate.java IgnoreRightProcedure.java
               functor/src/test/org/apache/commons/functor/adapter
                        TestIgnoreLeftFunction.java
                        TestIgnoreLeftPredicate.java
                        TestIgnoreLeftProcedure.java
                        TestIgnoreRightFunction.java
                        TestIgnoreRightPredicate.java
                        TestIgnoreRightProcedure.java
               functor/src/test/org/apache/commons/functor/example
                        FlexiMapExample.java
  Removed:     functor/src/java/org/apache/commons/functor/adapter
                        UnaryFunctionBinaryFunction.java
                        UnaryPredicateBinaryPredicate.java
                        UnaryProcedureBinaryProcedure.java
               functor/src/test/org/apache/commons/functor/adapter
                        TestUnaryFunctionBinaryFunction.java
                        TestUnaryPredicateBinaryPredicate.java
                        TestUnaryProcedureBinaryProcedure.java
  Log:
  rename several classes
  
  Revision  Changes    Path
  1.1                  jakarta-commons-sandbox/functor/src/java/org/apache/commons/functor/adapter/IgnoreLeftFunction.java
  
  Index: IgnoreLeftFunction.java
  ===================================================================
  /* 
   * $Header: /home/cvs/jakarta-commons-sandbox/functor/src/java/org/apache/commons/functor/adapter/IgnoreLeftFunction.java,v 1.1 2003/03/04 21:33:56 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.adapter;
  
  import java.io.Serializable;
  
  import org.apache.commons.functor.BinaryFunction;
  import org.apache.commons.functor.Function;
  import org.apache.commons.functor.UnaryFunction;
  
  /**
   * Adapts a
   * {@link UnaryFunction UnaryFunction} 
   * to the 
   * {@link BinaryFunction BinaryFunction} interface 
   * by ignoring the first binary argument.
   * <p/>
   * Note that although this class implements 
   * {@link Serializable}, a given instance will
   * only be truly <code>Serializable</code> if the
   * underlying functor is.  Attempts to serialize
   * an instance whose delegate is not 
   * <code>Serializable</code> will result in an exception.
   * 
   * @version $Revision: 1.1 $ $Date: 2003/03/04 21:33:56 $
   * @author Rodney Waldhoff
   */
  public final class IgnoreLeftFunction implements BinaryFunction, Serializable {
      public IgnoreLeftFunction(UnaryFunction function) {
          this.function = function;
      }
   
      public Object evaluate(Object left, Object right) {
          return function.evaluate(right);
      }   
  
      public boolean equals(Object that) {
          if(that instanceof IgnoreLeftFunction) {
              return equals((IgnoreLeftFunction)that);
          } else {
              return false;
          }
      }
          
      public boolean equals(IgnoreLeftFunction that) {
          return that == this || (null != that && (null == function ? null == that.function : function.equals(that.function)));
      }
      
      public int hashCode() {
          int hash = "IgnoreLeftFunction".hashCode();
          if(null != function) {
              hash ^= function.hashCode();
          }
          return hash;
      }
      
      public String toString() {
          return "IgnoreLeftFunction<" + function + ">";
      }
  
      public static BinaryFunction adapt(UnaryFunction function) {
          return null == function ? null : new IgnoreLeftFunction(function);
      }
  
      /** The {@link UnaryFunction UnaryFunction} I'm wrapping. */
      private UnaryFunction function = null;
  }
  
  
  
  1.1                  jakarta-commons-sandbox/functor/src/java/org/apache/commons/functor/adapter/IgnoreLeftPredicate.java
  
  Index: IgnoreLeftPredicate.java
  ===================================================================
  /* 
   * $Header: /home/cvs/jakarta-commons-sandbox/functor/src/java/org/apache/commons/functor/adapter/IgnoreLeftPredicate.java,v 1.1 2003/03/04 21:33:56 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.adapter;
  
  import java.io.Serializable;
  
  import org.apache.commons.functor.BinaryPredicate;
  import org.apache.commons.functor.Predicate;
  import org.apache.commons.functor.UnaryPredicate;
  
  /**
   * Adapts a
   * {@link UnaryPredicate UnaryPredicate} 
   * to the 
   * {@link BinaryPredicate BinaryPredicate} interface 
   * by ignoring the first binary argument.
   * <p/>
   * Note that although this class implements 
   * {@link Serializable}, a given instance will
   * only be truly <code>Serializable</code> if the
   * underlying functor is.  Attempts to serialize
   * an instance whose delegate is not 
   * <code>Serializable</code> will result in an exception.
   * 
   * @version $Revision: 1.1 $ $Date: 2003/03/04 21:33:56 $
   * @author Rodney Waldhoff
   */
  public final class IgnoreLeftPredicate implements BinaryPredicate, Serializable {
      public IgnoreLeftPredicate(UnaryPredicate predicate) {
          this.predicate = predicate;
      }
   
      public boolean test(Object left, Object right) {
          return predicate.test(right);
      }   
  
      public boolean equals(Object that) {
          if(that instanceof IgnoreLeftPredicate) {
              return equals((IgnoreLeftPredicate)that);
          } else {
              return false;
          }
      }
          
      public boolean equals(IgnoreLeftPredicate that) {
          return that == this || (null != that && (null == predicate ? null == that.predicate : predicate.equals(that.predicate)));
      }
      
      public int hashCode() {
          int hash = "IgnoreLeftPredicate".hashCode();
          if(null != predicate) {
              hash ^= predicate.hashCode();
          }
          return hash;
      }
      
      public String toString() {
          return "IgnoreLeftPredicate<" + predicate + ">";
      }
  
      public static IgnoreLeftPredicate adapt(UnaryPredicate predicate) {
          return null == predicate ? null : new IgnoreLeftPredicate(predicate);
      }
  
      /** The {@link UnaryPredicate UnaryPredicate} I'm wrapping. */
      private UnaryPredicate predicate = null;
  }
  
  
  
  1.1                  jakarta-commons-sandbox/functor/src/java/org/apache/commons/functor/adapter/IgnoreLeftProcedure.java
  
  Index: IgnoreLeftProcedure.java
  ===================================================================
  /* 
   * $Header: /home/cvs/jakarta-commons-sandbox/functor/src/java/org/apache/commons/functor/adapter/IgnoreLeftProcedure.java,v 1.1 2003/03/04 21:33:56 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.adapter;
  
  import java.io.Serializable;
  
  import org.apache.commons.functor.BinaryProcedure;
  import org.apache.commons.functor.Procedure;
  import org.apache.commons.functor.UnaryProcedure;
  
  /**
   * Adapts a
   * {@link UnaryProcedure UnaryProcedure} 
   * to the 
   * {@link BinaryProcedure BinaryProcedure} interface 
   * by ignoring the first binary argument.
   * <p/>
   * Note that although this class implements 
   * {@link Serializable}, a given instance will
   * only be truly <code>Serializable</code> if the
   * underlying functor is.  Attempts to serialize
   * an instance whose delegate is not 
   * <code>Serializable</code> will result in an exception.
   * 
   * @version $Revision: 1.1 $ $Date: 2003/03/04 21:33:56 $
   * @author Rodney Waldhoff
   */
  public final class IgnoreLeftProcedure implements BinaryProcedure, Serializable {
      public IgnoreLeftProcedure(UnaryProcedure procedure) {
          this.procedure = procedure;
      }
   
      public void run(Object left, Object right) {
          procedure.run(left);
      }   
  
      public boolean equals(Object that) {
          if(that instanceof IgnoreLeftProcedure) {
              return equals((IgnoreLeftProcedure)that);
          } else {
              return false;
          }
      }
          
      public boolean equals(IgnoreLeftProcedure that) {
          return that == this || (null != that && (null == procedure ? null == that.procedure : procedure.equals(that.procedure)));
      }
      
      public int hashCode() {
          int hash = "IgnoreLeftProcedure".hashCode();
          if(null != procedure) {
              hash ^= procedure.hashCode();
          }
          return hash;
      }
      
      public String toString() {
          return "IgnoreLeftProcedure<" + procedure + ">";
      }
  
      public static IgnoreLeftProcedure adapt(UnaryProcedure procedure) {
          return null == procedure ? null : new IgnoreLeftProcedure(procedure);
      }
  
      /** The {@link UnaryProcedure UnaryProcedure} I'm wrapping. */
      private UnaryProcedure procedure = null;
  }
  
  
  
  1.1                  jakarta-commons-sandbox/functor/src/java/org/apache/commons/functor/adapter/IgnoreRightFunction.java
  
  Index: IgnoreRightFunction.java
  ===================================================================
  /* 
   * $Header: /home/cvs/jakarta-commons-sandbox/functor/src/java/org/apache/commons/functor/adapter/IgnoreRightFunction.java,v 1.1 2003/03/04 21:33:56 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.adapter;
  
  import java.io.Serializable;
  
  import org.apache.commons.functor.BinaryFunction;
  import org.apache.commons.functor.Function;
  import org.apache.commons.functor.UnaryFunction;
  
  /**
   * Adapts a
   * {@link UnaryFunction UnaryFunction} 
   * to the 
   * {@link BinaryFunction BinaryFunction} interface 
   * by ignoring the second binary argument.
   * <p/>
   * Note that although this class implements 
   * {@link Serializable}, a given instance will
   * only be truly <code>Serializable</code> if the
   * underlying functor is.  Attempts to serialize
   * an instance whose delegate is not 
   * <code>Serializable</code> will result in an exception.
   * 
   * @version $Revision: 1.1 $ $Date: 2003/03/04 21:33:56 $
   * @author Rodney Waldhoff
   */
  public final class IgnoreRightFunction implements BinaryFunction, Serializable {
      public IgnoreRightFunction(UnaryFunction function) {
          this.function = function;
      }
   
      public Object evaluate(Object left, Object right) {
          return function.evaluate(left);
      }   
  
      public boolean equals(Object that) {
          if(that instanceof IgnoreRightFunction) {
              return equals((IgnoreRightFunction)that);
          } else {
              return false;
          }
      }
          
      public boolean equals(IgnoreRightFunction that) {
          return that == this || (null != that && (null == function ? null == that.function : function.equals(that.function)));
      }
      
      public int hashCode() {
          int hash = "IgnoreRightFunction".hashCode();
          if(null != function) {
              hash ^= function.hashCode();
          }
          return hash;
      }
      
      public String toString() {
          return "IgnoreRightFunction<" + function + ">";
      }
  
      public static BinaryFunction adapt(UnaryFunction function) {
          return null == function ? null : new IgnoreRightFunction(function);
      }
  
      /** The {@link UnaryFunction UnaryFunction} I'm wrapping. */
      private UnaryFunction function = null;
  }
  
  
  
  1.1                  jakarta-commons-sandbox/functor/src/java/org/apache/commons/functor/adapter/IgnoreRightPredicate.java
  
  Index: IgnoreRightPredicate.java
  ===================================================================
  /* 
   * $Header: /home/cvs/jakarta-commons-sandbox/functor/src/java/org/apache/commons/functor/adapter/IgnoreRightPredicate.java,v 1.1 2003/03/04 21:33:56 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.adapter;
  
  import java.io.Serializable;
  
  import org.apache.commons.functor.BinaryPredicate;
  import org.apache.commons.functor.Predicate;
  import org.apache.commons.functor.UnaryPredicate;
  
  /**
   * Adapts a
   * {@link UnaryPredicate UnaryPredicate} 
   * to the 
   * {@link BinaryPredicate BinaryPredicate} interface 
   * by ignoring the second binary argument.
   * <p/>
   * Note that although this class implements 
   * {@link Serializable}, a given instance will
   * only be truly <code>Serializable</code> if the
   * underlying functor is.  Attempts to serialize
   * an instance whose delegate is not 
   * <code>Serializable</code> will result in an exception.
   * 
   * @version $Revision: 1.1 $ $Date: 2003/03/04 21:33:56 $
   * @author Rodney Waldhoff
   */
  public final class IgnoreRightPredicate implements BinaryPredicate, Serializable {
      public IgnoreRightPredicate(UnaryPredicate predicate) {
          this.predicate = predicate;
      }
   
      public boolean test(Object left, Object right) {
          return predicate.test(left);
      }   
  
      public boolean equals(Object that) {
          if(that instanceof IgnoreRightPredicate) {
              return equals((IgnoreRightPredicate)that);
          } else {
              return false;
          }
      }
          
      public boolean equals(IgnoreRightPredicate that) {
          return that == this || (null != that && (null == predicate ? null == that.predicate : predicate.equals(that.predicate)));
      }
      
      public int hashCode() {
          int hash = "IgnoreRightPredicate".hashCode();
          if(null != predicate) {
              hash ^= predicate.hashCode();
          }
          return hash;
      }
      
      public String toString() {
          return "IgnoreRightPredicate<" + predicate + ">";
      }
  
      public static IgnoreRightPredicate adapt(UnaryPredicate predicate) {
          return null == predicate ? null : new IgnoreRightPredicate(predicate);
      }
  
      /** The {@link UnaryPredicate UnaryPredicate} I'm wrapping. */
      private UnaryPredicate predicate = null;
  }
  
  
  
  1.1                  jakarta-commons-sandbox/functor/src/java/org/apache/commons/functor/adapter/IgnoreRightProcedure.java
  
  Index: IgnoreRightProcedure.java
  ===================================================================
  /* 
   * $Header: /home/cvs/jakarta-commons-sandbox/functor/src/java/org/apache/commons/functor/adapter/IgnoreRightProcedure.java,v 1.1 2003/03/04 21:33:56 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.adapter;
  
  import java.io.Serializable;
  
  import org.apache.commons.functor.BinaryProcedure;
  import org.apache.commons.functor.Procedure;
  import org.apache.commons.functor.UnaryProcedure;
  
  /**
   * Adapts a
   * {@link UnaryProcedure UnaryProcedure} 
   * to the 
   * {@link BinaryProcedure BinaryProcedure} interface 
   * by ignoring the second binary argument.
   * <p/>
   * Note that although this class implements 
   * {@link Serializable}, a given instance will
   * only be truly <code>Serializable</code> if the
   * underlying functor is.  Attempts to serialize
   * an instance whose delegate is not 
   * <code>Serializable</code> will result in an exception.
   * 
   * @version $Revision: 1.1 $ $Date: 2003/03/04 21:33:56 $
   * @author Rodney Waldhoff
   */
  public final class IgnoreRightProcedure implements BinaryProcedure, Serializable {
      public IgnoreRightProcedure(UnaryProcedure procedure) {
          this.procedure = procedure;
      }
   
      public void run(Object left, Object right) {
          procedure.run(left);
      }   
  
      public boolean equals(Object that) {
          if(that instanceof IgnoreRightProcedure) {
              return equals((IgnoreRightProcedure)that);
          } else {
              return false;
          }
      }
          
      public boolean equals(IgnoreRightProcedure that) {
          return that == this || (null != that && (null == procedure ? null == that.procedure : procedure.equals(that.procedure)));
      }
      
      public int hashCode() {
          int hash = "IgnoreRightProcedure".hashCode();
          if(null != procedure) {
              hash ^= procedure.hashCode();
          }
          return hash;
      }
      
      public String toString() {
          return "IgnoreRightProcedure<" + procedure + ">";
      }
  
      public static IgnoreRightProcedure adapt(UnaryProcedure procedure) {
          return null == procedure ? null : new IgnoreRightProcedure(procedure);
      }
  
      /** The {@link UnaryProcedure UnaryProcedure} I'm wrapping. */
      private UnaryProcedure procedure = null;
  }
  
  
  
  1.4       +8 -5      jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/adapter/TestAll.java
  
  Index: TestAll.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/adapter/TestAll.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- TestAll.java	28 Jan 2003 23:37:50 -0000	1.3
  +++ TestAll.java	4 Mar 2003 21:33:56 -0000	1.4
  @@ -89,13 +89,16 @@
           suite.addTest(TestBinaryPredicateBinaryFunction.suite());
   
           suite.addTest(TestFunctionUnaryFunction.suite());
  -        suite.addTest(TestUnaryFunctionBinaryFunction.suite());
  +        suite.addTest(TestIgnoreRightFunction.suite());
  +        suite.addTest(TestIgnoreLeftFunction.suite());
           
           suite.addTest(TestPredicateUnaryPredicate.suite());
  -        suite.addTest(TestUnaryPredicateBinaryPredicate.suite());
  +        suite.addTest(TestIgnoreRightPredicate.suite());
  +        suite.addTest(TestIgnoreLeftPredicate.suite());
           
           suite.addTest(TestProcedureUnaryProcedure.suite());
  -        suite.addTest(TestUnaryProcedureBinaryProcedure.suite());
  +        suite.addTest(TestIgnoreRightProcedure.suite());
  +        suite.addTest(TestIgnoreLeftProcedure.suite());
           
           suite.addTest(TestBoundFunction.suite());
           suite.addTest(TestLeftBoundFunction.suite());
  
  
  
  1.1                  jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/adapter/TestIgnoreLeftFunction.java
  
  Index: TestIgnoreLeftFunction.java
  ===================================================================
  /* 
   * $Header: /home/cvs/jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/adapter/TestIgnoreLeftFunction.java,v 1.1 2003/03/04 21:33:56 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.adapter;
  
  import junit.framework.Test;
  import junit.framework.TestSuite;
  
  import org.apache.commons.functor.BaseFunctorTest;
  import org.apache.commons.functor.BinaryFunction;
  import org.apache.commons.functor.core.ConstantFunction;
  import org.apache.commons.functor.core.IdentityFunction;
  
  /**
   * @version $Revision: 1.1 $ $Date: 2003/03/04 21:33:56 $
   * @author Rodney Waldhoff
   */
  public class TestIgnoreLeftFunction extends BaseFunctorTest {
  
      // Conventional
      // ------------------------------------------------------------------------
  
      public TestIgnoreLeftFunction(String testName) {
          super(testName);
      }
  
      public static Test suite() {
          return new TestSuite(TestIgnoreLeftFunction.class);
      }
  
      // Functor Testing Framework
      // ------------------------------------------------------------------------
  
      protected Object makeFunctor() {
          return new IgnoreLeftFunction(new ConstantFunction("xyzzy"));
      }
  
      // Lifecycle
      // ------------------------------------------------------------------------
  
      public void setUp() throws Exception {
          super.setUp();
      }
  
      public void tearDown() throws Exception {
          super.tearDown();
      }
  
      // Tests
      // ------------------------------------------------------------------------    
  
      public void testEvaluate() throws Exception {
          BinaryFunction f = new IgnoreLeftFunction(new IdentityFunction());
          assertNull(f.evaluate(null,null));
          assertNull(f.evaluate("xyzzy",null));
          assertEquals("xyzzy",f.evaluate(null,"xyzzy"));
          assertEquals("xyzzy",f.evaluate("abc","xyzzy"));
      }
      
      public void testEquals() throws Exception {
          BinaryFunction f = new IgnoreLeftFunction(new ConstantFunction("xyzzy"));
          assertEquals(f,f);
          assertObjectsAreEqual(f,new IgnoreLeftFunction(new ConstantFunction("xyzzy")));
          assertObjectsAreNotEqual(f,new ConstantFunction("x"));
          assertObjectsAreNotEqual(f,new IgnoreLeftFunction(new ConstantFunction(null)));
          assertObjectsAreNotEqual(f,new ConstantFunction(null));
          assertObjectsAreNotEqual(f,new IgnoreLeftFunction(null));
          assertObjectsAreEqual(new IgnoreLeftFunction(null),new IgnoreLeftFunction(null));
      }
  
      public void testAdaptNull() throws Exception {
          assertNull(IgnoreLeftFunction.adapt(null));
      }
  
      public void testAdapt() throws Exception {
          assertNotNull(IgnoreLeftFunction.adapt(new ConstantFunction("xyzzy")));
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/adapter/TestIgnoreLeftPredicate.java
  
  Index: TestIgnoreLeftPredicate.java
  ===================================================================
  /* 
   * $Header: /home/cvs/jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/adapter/TestIgnoreLeftPredicate.java,v 1.1 2003/03/04 21:33:56 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.adapter;
  
  import junit.framework.Test;
  import junit.framework.TestSuite;
  
  import org.apache.commons.functor.BaseFunctorTest;
  import org.apache.commons.functor.BinaryPredicate;
  import org.apache.commons.functor.core.ConstantPredicate;
  import org.apache.commons.functor.core.IdentityFunction;
  
  /**
   * @version $Revision: 1.1 $ $Date: 2003/03/04 21:33:56 $
   * @author Rodney Waldhoff
   */
  public class TestIgnoreLeftPredicate extends BaseFunctorTest {
  
      // Conventional
      // ------------------------------------------------------------------------
  
      public TestIgnoreLeftPredicate(String testName) {
          super(testName);
      }
  
      public static Test suite() {
          return new TestSuite(TestIgnoreLeftPredicate.class);
      }
  
      // Functor Testing Framework
      // ------------------------------------------------------------------------
  
      protected Object makeFunctor() {
          return new IgnoreLeftPredicate(new ConstantPredicate(true));
      }
  
      // Lifecycle
      // ------------------------------------------------------------------------
  
      public void setUp() throws Exception {
          super.setUp();
      }
  
      public void tearDown() throws Exception {
          super.tearDown();
      }
  
      // Tests
      // ------------------------------------------------------------------------    
  
      public void testEvaluate() throws Exception {
          BinaryPredicate p = new IgnoreLeftPredicate(new UnaryFunctionUnaryPredicate(new IdentityFunction()));
          assertTrue(p.test(null,Boolean.TRUE));
          assertTrue(!p.test(null,Boolean.FALSE));
      }
      
      public void testEquals() throws Exception {
          BinaryPredicate p = new IgnoreLeftPredicate(new UnaryFunctionUnaryPredicate(new IdentityFunction()));
          assertEquals(p,p);
          assertObjectsAreEqual(p,new IgnoreLeftPredicate(new UnaryFunctionUnaryPredicate(new IdentityFunction())));
          assertObjectsAreNotEqual(p,new ConstantPredicate(true));
          assertObjectsAreNotEqual(p,new IgnoreLeftPredicate(new ConstantPredicate(false)));
          assertObjectsAreNotEqual(p,new ConstantPredicate(false));
          assertObjectsAreEqual(new IgnoreLeftPredicate(null),new IgnoreLeftPredicate(null));
      }
  
      public void testAdaptNull() throws Exception {
          assertNull(IgnoreLeftPredicate.adapt(null));
      }
  
      public void testAdapt() throws Exception {
          assertNotNull(IgnoreLeftPredicate.adapt(new ConstantPredicate(true)));
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/adapter/TestIgnoreLeftProcedure.java
  
  Index: TestIgnoreLeftProcedure.java
  ===================================================================
  /* 
   * $Header: /home/cvs/jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/adapter/TestIgnoreLeftProcedure.java,v 1.1 2003/03/04 21:33:56 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.adapter;
  
  import junit.framework.Test;
  import junit.framework.TestSuite;
  
  import org.apache.commons.functor.BaseFunctorTest;
  import org.apache.commons.functor.BinaryProcedure;
  import org.apache.commons.functor.core.IdentityFunction;
  import org.apache.commons.functor.core.NoOp;
  
  /**
   * @version $Revision: 1.1 $ $Date: 2003/03/04 21:33:56 $
   * @author Rodney Waldhoff
   */
  public class TestIgnoreLeftProcedure extends BaseFunctorTest {
  
      // Conventional
      // ------------------------------------------------------------------------
  
      public TestIgnoreLeftProcedure(String testName) {
          super(testName);
      }
  
      public static Test suite() {
          return new TestSuite(TestIgnoreLeftProcedure.class);
      }
  
      // Functor Testing Framework
      // ------------------------------------------------------------------------
  
      protected Object makeFunctor() {
          return new IgnoreLeftProcedure(new NoOp());
      }
  
      // Lifecycle
      // ------------------------------------------------------------------------
  
      public void setUp() throws Exception {
          super.setUp();
      }
  
      public void tearDown() throws Exception {
          super.tearDown();
      }
  
      // Tests
      // ------------------------------------------------------------------------    
  
      public void testEvaluate() throws Exception {
          BinaryProcedure p = new IgnoreLeftProcedure(new UnaryFunctionUnaryProcedure(new IdentityFunction()));
          p.run(null,Boolean.TRUE);
      }
      
      public void testEquals() throws Exception {
          BinaryProcedure p = new IgnoreLeftProcedure(new NoOp());
          assertEquals(p,p);
          assertObjectsAreEqual(p,new IgnoreLeftProcedure(new NoOp()));
          assertObjectsAreNotEqual(p,new NoOp());
          assertObjectsAreNotEqual(p,new IgnoreLeftProcedure(null));
          assertObjectsAreEqual(new IgnoreLeftProcedure(null),new IgnoreLeftProcedure(null));
      }
  
      public void testAdaptNull() throws Exception {
          assertNull(IgnoreLeftProcedure.adapt(null));
      }
  
      public void testAdapt() throws Exception {
          assertNotNull(IgnoreLeftProcedure.adapt(new NoOp()));
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/adapter/TestIgnoreRightFunction.java
  
  Index: TestIgnoreRightFunction.java
  ===================================================================
  /* 
   * $Header: /home/cvs/jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/adapter/TestIgnoreRightFunction.java,v 1.1 2003/03/04 21:33:56 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.adapter;
  
  import junit.framework.Test;
  import junit.framework.TestSuite;
  
  import org.apache.commons.functor.BaseFunctorTest;
  import org.apache.commons.functor.BinaryFunction;
  import org.apache.commons.functor.core.ConstantFunction;
  import org.apache.commons.functor.core.IdentityFunction;
  
  /**
   * @version $Revision: 1.1 $ $Date: 2003/03/04 21:33:56 $
   * @author Rodney Waldhoff
   */
  public class TestIgnoreRightFunction extends BaseFunctorTest {
  
      // Conventional
      // ------------------------------------------------------------------------
  
      public TestIgnoreRightFunction(String testName) {
          super(testName);
      }
  
      public static Test suite() {
          return new TestSuite(TestIgnoreRightFunction.class);
      }
  
      // Functor Testing Framework
      // ------------------------------------------------------------------------
  
      protected Object makeFunctor() {
          return new IgnoreRightFunction(new ConstantFunction("xyzzy"));
      }
  
      // Lifecycle
      // ------------------------------------------------------------------------
  
      public void setUp() throws Exception {
          super.setUp();
      }
  
      public void tearDown() throws Exception {
          super.tearDown();
      }
  
      // Tests
      // ------------------------------------------------------------------------    
  
      public void testEvaluate() throws Exception {
          BinaryFunction f = new IgnoreRightFunction(new IdentityFunction());
          assertNull(f.evaluate(null,null));
          assertNull(f.evaluate(null,"xyzzy"));
          assertEquals("xyzzy",f.evaluate("xyzzy",null));
          assertEquals("xyzzy",f.evaluate("xyzzy","abc"));
      }
      
      public void testEquals() throws Exception {
          BinaryFunction f = new IgnoreRightFunction(new ConstantFunction("xyzzy"));
          assertEquals(f,f);
          assertObjectsAreEqual(f,new IgnoreRightFunction(new ConstantFunction("xyzzy")));
          assertObjectsAreNotEqual(f,new ConstantFunction("x"));
          assertObjectsAreNotEqual(f,new IgnoreRightFunction(new ConstantFunction(null)));
          assertObjectsAreNotEqual(f,new ConstantFunction(null));
          assertObjectsAreNotEqual(f,new IgnoreRightFunction(null));
          assertObjectsAreEqual(new IgnoreRightFunction(null),new IgnoreRightFunction(null));
      }
  
      public void testAdaptNull() throws Exception {
          assertNull(IgnoreRightFunction.adapt(null));
      }
  
      public void testAdapt() throws Exception {
          assertNotNull(IgnoreRightFunction.adapt(new ConstantFunction("xyzzy")));
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/adapter/TestIgnoreRightPredicate.java
  
  Index: TestIgnoreRightPredicate.java
  ===================================================================
  /* 
   * $Header: /home/cvs/jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/adapter/TestIgnoreRightPredicate.java,v 1.1 2003/03/04 21:33:56 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.adapter;
  
  import junit.framework.Test;
  import junit.framework.TestSuite;
  
  import org.apache.commons.functor.BaseFunctorTest;
  import org.apache.commons.functor.BinaryPredicate;
  import org.apache.commons.functor.core.ConstantPredicate;
  import org.apache.commons.functor.core.IdentityFunction;
  
  /**
   * @version $Revision: 1.1 $ $Date: 2003/03/04 21:33:56 $
   * @author Rodney Waldhoff
   */
  public class TestIgnoreRightPredicate extends BaseFunctorTest {
  
      // Conventional
      // ------------------------------------------------------------------------
  
      public TestIgnoreRightPredicate(String testName) {
          super(testName);
      }
  
      public static Test suite() {
          return new TestSuite(TestIgnoreRightPredicate.class);
      }
  
      // Functor Testing Framework
      // ------------------------------------------------------------------------
  
      protected Object makeFunctor() {
          return new IgnoreRightPredicate(new ConstantPredicate(true));
      }
  
      // Lifecycle
      // ------------------------------------------------------------------------
  
      public void setUp() throws Exception {
          super.setUp();
      }
  
      public void tearDown() throws Exception {
          super.tearDown();
      }
  
      // Tests
      // ------------------------------------------------------------------------    
  
      public void testEvaluate() throws Exception {
          BinaryPredicate p = new IgnoreRightPredicate(new UnaryFunctionUnaryPredicate(new IdentityFunction()));
          assertTrue(p.test(Boolean.TRUE,null));
          assertTrue(!p.test(Boolean.FALSE,null));
      }
      
      public void testEquals() throws Exception {
          BinaryPredicate p = new IgnoreRightPredicate(new UnaryFunctionUnaryPredicate(new IdentityFunction()));
          assertEquals(p,p);
          assertObjectsAreEqual(p,new IgnoreRightPredicate(new UnaryFunctionUnaryPredicate(new IdentityFunction())));
          assertObjectsAreNotEqual(p,new ConstantPredicate(true));
          assertObjectsAreNotEqual(p,new IgnoreRightPredicate(new ConstantPredicate(false)));
          assertObjectsAreNotEqual(p,new ConstantPredicate(false));
          assertObjectsAreEqual(new IgnoreRightPredicate(null),new IgnoreRightPredicate(null));
      }
  
      public void testAdaptNull() throws Exception {
          assertNull(IgnoreRightPredicate.adapt(null));
      }
  
      public void testAdapt() throws Exception {
          assertNotNull(IgnoreRightPredicate.adapt(new ConstantPredicate(true)));
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/adapter/TestIgnoreRightProcedure.java
  
  Index: TestIgnoreRightProcedure.java
  ===================================================================
  /* 
   * $Header: /home/cvs/jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/adapter/TestIgnoreRightProcedure.java,v 1.1 2003/03/04 21:33:56 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.adapter;
  
  import junit.framework.Test;
  import junit.framework.TestSuite;
  
  import org.apache.commons.functor.BaseFunctorTest;
  import org.apache.commons.functor.BinaryProcedure;
  import org.apache.commons.functor.core.IdentityFunction;
  import org.apache.commons.functor.core.NoOp;
  
  /**
   * @version $Revision: 1.1 $ $Date: 2003/03/04 21:33:56 $
   * @author Rodney Waldhoff
   */
  public class TestIgnoreRightProcedure extends BaseFunctorTest {
  
      // Conventional
      // ------------------------------------------------------------------------
  
      public TestIgnoreRightProcedure(String testName) {
          super(testName);
      }
  
      public static Test suite() {
          return new TestSuite(TestIgnoreRightProcedure.class);
      }
  
      // Functor Testing Framework
      // ------------------------------------------------------------------------
  
      protected Object makeFunctor() {
          return new IgnoreRightProcedure(new NoOp());
      }
  
      // Lifecycle
      // ------------------------------------------------------------------------
  
      public void setUp() throws Exception {
          super.setUp();
      }
  
      public void tearDown() throws Exception {
          super.tearDown();
      }
  
      // Tests
      // ------------------------------------------------------------------------    
  
      public void testEvaluate() throws Exception {
          BinaryProcedure p = new IgnoreRightProcedure(new UnaryFunctionUnaryProcedure(new IdentityFunction()));
          p.run(Boolean.TRUE,null);
      }
      
      public void testEquals() throws Exception {
          BinaryProcedure p = new IgnoreRightProcedure(new NoOp());
          assertEquals(p,p);
          assertObjectsAreEqual(p,new IgnoreRightProcedure(new NoOp()));
          assertObjectsAreNotEqual(p,new NoOp());
          assertObjectsAreNotEqual(p,new IgnoreRightProcedure(null));
          assertObjectsAreEqual(new IgnoreRightProcedure(null),new IgnoreRightProcedure(null));
      }
  
      public void testAdaptNull() throws Exception {
          assertNull(IgnoreRightProcedure.adapt(null));
      }
  
      public void testAdapt() throws Exception {
          assertNotNull(IgnoreRightProcedure.adapt(new NoOp()));
      }
  }
  
  
  
  1.2       +3 -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.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TestAll.java	20 Feb 2003 01:12:42 -0000	1.1
  +++ TestAll.java	4 Mar 2003 21:33:56 -0000	1.2
  @@ -72,6 +72,7 @@
       public static Test suite() {
           TestSuite suite = new TestSuite();
   
  +        suite.addTest(FlexiMapExample.suite());
           suite.addTest(Quicksort.suite());
           
           return suite;
  
  
  
  1.1                  jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/example/FlexiMapExample.java
  
  Index: FlexiMapExample.java
  ===================================================================
  /* 
   * $Header: /home/cvs/jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/example/FlexiMapExample.java,v 1.1 2003/03/04 21:33:56 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;
  
  import java.util.Collection;
  import java.util.HashMap;
  import java.util.Map;
  import java.util.Set;
  
  import junit.framework.Test;
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  
  import org.apache.commons.functor.BinaryFunction;
  import org.apache.commons.functor.BinaryProcedure;
  import org.apache.commons.functor.Procedure;
  import org.apache.commons.functor.UnaryProcedure;
  import org.apache.commons.functor.adapter.BinaryProcedureBinaryFunction;
  import org.apache.commons.functor.adapter.IgnoreLeftFunction;
  import org.apache.commons.functor.adapter.IgnoreLeftPredicate;
  import org.apache.commons.functor.adapter.IgnoreRightPredicate;
  import org.apache.commons.functor.adapter.UnaryProcedureUnaryFunction;
  import org.apache.commons.functor.core.ConstantFunction;
  import org.apache.commons.functor.core.IdentityFunction;
  import org.apache.commons.functor.core.IsNull;
  import org.apache.commons.functor.core.RightIdentityFunction;
  import org.apache.commons.functor.core.composite.BinaryOr;
  import org.apache.commons.functor.core.composite.ConditionalBinaryFunction;
  import org.apache.commons.functor.core.composite.ConditionalUnaryFunction;
  
  /**
   * @version $Revision: 1.1 $ $Date: 2003/03/04 21:33:56 $
   * @author Rodney Waldhoff
   */
  public class FlexiMapExample extends TestCase {
  
      public FlexiMapExample(String testName) {
          super(testName);
      }
  
      public static Test suite() {
          return new TestSuite(FlexiMapExample.class);
      }
  
      public void testBasicMap() {
          Map map = makeBasicMap();
          Object key = "key";
          Object value = new Integer(3);
          map.put(key,value);
          assertEquals(value, map.get(key) );
      }    
  
      public void testBasicMapReturnsNullForMissingKey() {
          Map map = makeBasicMap();
          assertNull( map.get("key") );
      }    
  
      public void testBasicMapAllowsNull() {
          Map map = makeBasicMap();
          Object key = "key";
          Object value = null;
          map.put(key,value);
          assertNull( map.get(key) );
      }    
  
      public void testBasicMapAllowsMultipleTypes() {
          Map map = makeBasicMap();
          map.put("key-1","value-1");
          map.put(new Integer(2),"value-2");
          map.put("key-3",new Integer(3));
          map.put(new Integer(4),new Integer(4));
  
          assertEquals("value-1", map.get("key-1") );
          assertEquals("value-2", map.get(new Integer(2)) );
          assertEquals(new Integer(3), map.get("key-3") );
          assertEquals(new Integer(4), map.get(new Integer(4)) );
      }    
  
      public void testBasicMapStoresOnlyOneValuePerKey() {
          Map map = makeBasicMap();
  
          assertNull( map.put("key","value-1") );
          assertEquals("value-1", map.get("key") );
          assertEquals("value-1", map.put("key","value-2"));
          assertEquals("value-2", map.get("key") );
      }    
      
      
      public void testForbidNull() {
          Map map = makeNullForbiddenMap();
          
          map.put("key","value");
          map.put("key2", new Integer(2) );
          try {
              map.put("key3",null);
              fail("Expected NullPointerException");
          } catch(NullPointerException e) {
              // expected
          }                
      }
  
      public void testNullDefaultsToZero() {
          Map map = makeNullAsZeroMap();        
          map.put("key", null);
          assertEquals( new Integer(0), map.get("key") );
      }
  
      static class FlexiMap implements Map {
  
          public FlexiMap(BinaryFunction putfn, BinaryFunction getfn) {
              if(null == putfn) {
                  onPut = new RightIdentityFunction();
              } else {
                  onPut = putfn;
              }
              
              if(null == getfn) {
                  onGet = new RightIdentityFunction();
              } else {
                  onGet = getfn;
              }
              
              proxiedMap = new HashMap();
          }        
          
          public Object put(Object key, Object value) {
              Object oldvalue = get(key);
              proxiedMap.put(key, onPut.evaluate(oldvalue, value));
              return oldvalue;
          }
  
          public Object get(Object key) {
              return onGet.evaluate( key, proxiedMap.get(key) );
          }
  
          public void clear() {
              throw new UnsupportedOperationException("Left as an exercise for the reader.");
          }
  
          public boolean containsKey(Object key) {
              throw new UnsupportedOperationException("Left as an exercise for the reader.");
          }
  
          public boolean containsValue(Object value) {
              throw new UnsupportedOperationException("Left as an exercise for the reader.");
          }
  
          public Set entrySet() {
              throw new UnsupportedOperationException("Left as an exercise for the reader.");
          }
  
          public boolean isEmpty() {
              throw new UnsupportedOperationException("Left as an exercise for the reader.");
          }
  
          public Set keySet() {
              throw new UnsupportedOperationException("Left as an exercise for the reader.");
          }
  
          public void putAll(Map t) {
              throw new UnsupportedOperationException("Left as an exercise for the reader.");
          }
  
          public Object remove(Object key) {
              throw new UnsupportedOperationException("Left as an exercise for the reader.");
          }
  
          public int size() {
              throw new UnsupportedOperationException("Left as an exercise for the reader.");
          }
  
          public Collection values() {
              throw new UnsupportedOperationException("Left as an exercise for the reader.");
          }
  
          private BinaryFunction onPut = null;
          private BinaryFunction onGet = null;
          private Map proxiedMap = null;
      }
  
      private Map makeBasicMap() {
          return new HashMap();
      }
      
      private Map makeNullForbiddenMap() {
          return new FlexiMap(
              IgnoreLeftFunction.adapt(                        
                  new ConditionalUnaryFunction(
                      IsNull.getIsNullPredicate(),
                      UnaryProcedureUnaryFunction.adapt(throwNPE),
                      IdentityFunction.getIdentityFunction()
                  )
              ),
              null
          );
      }
  
      private Map makeNullAsZeroMap() {
          return new FlexiMap(
              IgnoreLeftFunction.adapt(                        
                  new ConditionalUnaryFunction(
                      IsNull.getIsNullPredicate(),
                      new ConstantFunction(new Integer(0)),
                      IdentityFunction.getIdentityFunction()
                  )
              ),
              null
          );
      }
  
      private interface UniversalProcedure extends Procedure, UnaryProcedure, BinaryProcedure { }
  
      private UniversalProcedure throwNPE = new UniversalProcedure() {
          public void run() {
              throw new NullPointerException();
          }
          public void run(Object obj) {
              run();
          }
          public void run(Object left, Object right) {
              run();
          }
      };
      
  }
  
  
  

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


Mime
View raw message