You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by sc...@apache.org on 2003/11/23 20:11:22 UTC

cvs commit: jakarta-commons/collections/src/java/org/apache/commons/collections PredicateUtils.java

scolebourne    2003/11/23 11:11:21

  Modified:    collections/src/java/org/apache/commons/collections
                        PredicateUtils.java
  Added:       collections/src/java/org/apache/commons/collections/functors
                        NullIsExceptionPredicate.java NotNullPredicate.java
                        NotPredicate.java NullIsFalsePredicate.java
                        InstanceofPredicate.java FalsePredicate.java
                        EqualPredicate.java TruePredicate.java
                        IdentityPredicate.java NullPredicate.java
                        NullIsTruePredicate.java
  Log:
  Refactor functors from inner classes to subpackage
  
  Revision  Changes    Path
  1.1                  jakarta-commons/collections/src/java/org/apache/commons/collections/functors/NullIsExceptionPredicate.java
  
  Index: NullIsExceptionPredicate.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/functors/NullIsExceptionPredicate.java,v 1.1 2003/11/23 19:11:21 scolebourne Exp $
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001-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 acknowledgement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgement may appear in the software itself,
   *    if and wherever such third-party acknowledgements 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 names 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.collections.functors;
  
  import java.io.Serializable;
  
  import org.apache.commons.collections.Predicate;
  
  /**
   * Predicate implementation that throws an exception if the input is null.
   * 
   * @since Commons Collections 3.0
   * @version $Revision: 1.1 $ $Date: 2003/11/23 19:11:21 $
   *
   * @author Stephen Colebourne
   */
  public final class NullIsExceptionPredicate implements Predicate, Serializable {
  
      /** Serial version UID */
      static final long serialVersionUID = 3243449850504576071L;
      
      /** The predicate to decorate */
      private final Predicate iPredicate;
      
      /**
       * Factory to create the null exception predicate.
       * 
       * @param predicate  the predicate to decorate, not null
       * @return the predicate
       * @throws IllegalArgumentException if the predicate is null
       */
      public static Predicate getInstance(Predicate predicate) {
          if (predicate == null) {
              throw new IllegalArgumentException("Predicate must not be null");
          }
          return new NullIsExceptionPredicate(predicate);
      }
  
      /**
       * Constructor that performs no validation.
       * Use <code>getInstance</code> if you want that.
       * 
       * @param predicate  the predicate to call after the null check
       */
      public NullIsExceptionPredicate(Predicate predicate) {
          super();
          iPredicate = predicate;
      }
  
      /**
       * Return true if the object equals null else call the decorated predicate.
       */
      public boolean evaluate(Object object) {
          if (object == null) {
              throw new FunctorException("Input Object must not be null");
          }
          return iPredicate.evaluate(object);
      }
      
  }
  
  
  
  1.1                  jakarta-commons/collections/src/java/org/apache/commons/collections/functors/NotNullPredicate.java
  
  Index: NotNullPredicate.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/functors/NotNullPredicate.java,v 1.1 2003/11/23 19:11:21 scolebourne Exp $
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001-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 acknowledgement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgement may appear in the software itself,
   *    if and wherever such third-party acknowledgements 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 names 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.collections.functors;
  
  import java.io.Serializable;
  
  import org.apache.commons.collections.Predicate;
  
  /**
   * Predicate implementation that returns true if the input is not null.
   * 
   * @since Commons Collections 3.0
   * @version $Revision: 1.1 $ $Date: 2003/11/23 19:11:21 $
   *
   * @author Stephen Colebourne
   */
  public final class NotNullPredicate implements Predicate, Serializable {
  
      /** Serial version UID */
      static final long serialVersionUID = 7533784454832764388L;
      
      /** Singleton predicate instance */    
      public static final Predicate INSTANCE = new NotNullPredicate();
      
      /**
       * Restricted constructor.
       */
      private NotNullPredicate() {
          super();
      }
  
      /**
       * Return true if the object equals null.
       */
      public boolean evaluate(Object object) {
          return (object != null);
      }
      
  }
  
  
  
  1.1                  jakarta-commons/collections/src/java/org/apache/commons/collections/functors/NotPredicate.java
  
  Index: NotPredicate.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/functors/NotPredicate.java,v 1.1 2003/11/23 19:11:21 scolebourne Exp $
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001-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 acknowledgement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgement may appear in the software itself,
   *    if and wherever such third-party acknowledgements 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 names 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.collections.functors;
  
  import java.io.Serializable;
  
  import org.apache.commons.collections.Predicate;
  
  /**
   * Predicate implementation that returns the opposite of the decorated predicate.
   * 
   * @since Commons Collections 3.0
   * @version $Revision: 1.1 $ $Date: 2003/11/23 19:11:21 $
   *
   * @author Stephen Colebourne
   */
  public final class NotPredicate implements Predicate, Serializable {
  
      /** Serial version UID */
      static final long serialVersionUID = -2654603322338049674L;
      
      /** The predicate to decorate */
      private final Predicate iPredicate;
      
      /**
       * Factory to create the not predicate.
       * 
       * @param predicate  the predicate to decorate, not null
       * @return the predicate
       * @throws IllegalArgumentException if the predicate is null
       */
      public static Predicate getInstance(Predicate predicate) {
          if (predicate == null) {
              throw new IllegalArgumentException("Predicate must not be null");
          }
          return new NotPredicate(predicate);
      }
  
      /**
       * Constructor that performs no validation.
       * Use <code>getInstance</code> if you want that.
       * 
       * @param predicate  the predicate to call after the null check
       */
      public NotPredicate(Predicate predicate) {
          super();
          iPredicate = predicate;
      }
  
      /**
       * Return the negated predicate result.
       */
      public boolean evaluate(Object object) {
          return !(iPredicate.evaluate(object));
      }
      
  }
  
  
  
  1.1                  jakarta-commons/collections/src/java/org/apache/commons/collections/functors/NullIsFalsePredicate.java
  
  Index: NullIsFalsePredicate.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/functors/NullIsFalsePredicate.java,v 1.1 2003/11/23 19:11:21 scolebourne Exp $
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001-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 acknowledgement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgement may appear in the software itself,
   *    if and wherever such third-party acknowledgements 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 names 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.collections.functors;
  
  import java.io.Serializable;
  
  import org.apache.commons.collections.Predicate;
  
  /**
   * Predicate implementation that returns false if the input is null.
   * 
   * @since Commons Collections 3.0
   * @version $Revision: 1.1 $ $Date: 2003/11/23 19:11:21 $
   *
   * @author Stephen Colebourne
   */
  public final class NullIsFalsePredicate implements Predicate, Serializable {
  
      /** Serial version UID */
      static final long serialVersionUID = -2997501534564735525L;
      
      /** The predicate to decorate */
      private final Predicate iPredicate;
      
      /**
       * Factory to create the null false predicate.
       * 
       * @param predicate  the predicate to decorate, not null
       * @return the predicate
       * @throws IllegalArgumentException if the predicate is null
       */
      public static Predicate getInstance(Predicate predicate) {
          if (predicate == null) {
              throw new IllegalArgumentException("Predicate must not be null");
          }
          return new NullIsFalsePredicate(predicate);
      }
  
      /**
       * Constructor that performs no validation.
       * Use <code>getInstance</code> if you want that.
       * 
       * @param predicate  the predicate to call after the null check
       */
      public NullIsFalsePredicate(Predicate predicate) {
          super();
          iPredicate = predicate;
      }
  
      /**
       * Return false if the object equals null else call the decorated predicate.
       */
      public boolean evaluate(Object object) {
          if (object == null) {
              return false;
          }
          return iPredicate.evaluate(object);
      }
      
  }
  
  
  
  1.1                  jakarta-commons/collections/src/java/org/apache/commons/collections/functors/InstanceofPredicate.java
  
  Index: InstanceofPredicate.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/functors/InstanceofPredicate.java,v 1.1 2003/11/23 19:11:21 scolebourne Exp $
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001-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 acknowledgement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgement may appear in the software itself,
   *    if and wherever such third-party acknowledgements 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 names 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.collections.functors;
  
  import java.io.Serializable;
  
  import org.apache.commons.collections.Predicate;
  
  /**
   * Predicate implementation that returns true if the input is an instanceof
   * the type stored in this predicate.
   * 
   * @since Commons Collections 3.0
   * @version $Revision: 1.1 $ $Date: 2003/11/23 19:11:21 $
   *
   * @author Stephen Colebourne
   */
  public final class InstanceofPredicate implements Predicate, Serializable {
  
      /** Serial version UID */
      static final long serialVersionUID = -6682656911025165584L;
  
      /** The type to compare to */
      private final Class iType;
      
      /**
       * Factory to create the identity predicate.
       * 
       * @param type  the type to check for, may not be null
       * @return the predicate
       * @throws IllegalArgumentException if the class is null
       */
      public static Predicate getInstance(Class type) {
          if (type == null) {
              throw new IllegalArgumentException("The type to check instanceof must not be null");
          }
          return new InstanceofPredicate(type);
      }
  
      /**
       * Constructor that performs no validation.
       * Use <code>getInstance</code> if you want that.
       * 
       * @param object  the object to compare to
       */
      public InstanceofPredicate(Class type) {
          super();
          iType = type;
      }
  
      /**
       * Return the predicate result.
       */
      public boolean evaluate(Object object) {
          return (iType.isInstance(object));
      }
      
  }
  
  
  
  1.1                  jakarta-commons/collections/src/java/org/apache/commons/collections/functors/FalsePredicate.java
  
  Index: FalsePredicate.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/functors/FalsePredicate.java,v 1.1 2003/11/23 19:11:21 scolebourne Exp $
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001-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 acknowledgement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgement may appear in the software itself,
   *    if and wherever such third-party acknowledgements 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 names 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.collections.functors;
  
  import java.io.Serializable;
  
  import org.apache.commons.collections.Predicate;
  
  /**
   * Predicate implementation that always returns false.
   * 
   * @since Commons Collections 3.0
   * @version $Revision: 1.1 $ $Date: 2003/11/23 19:11:21 $
   *
   * @author Stephen Colebourne
   */
  public final class FalsePredicate implements Predicate, Serializable {
  
      /** Serial version UID */
      static final long serialVersionUID = 7533784454832764388L;
      
      /** Singleton predicate instance */    
      public static final Predicate INSTANCE = new FalsePredicate();
      
      /**
       * Restricted constructor.
       */
      private FalsePredicate() {
          super();
      }
  
      /**
       * Always return true.
       */
      public boolean evaluate(Object object) {
          return false;
      }
      
  }
  
  
  
  1.1                  jakarta-commons/collections/src/java/org/apache/commons/collections/functors/EqualPredicate.java
  
  Index: EqualPredicate.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/functors/EqualPredicate.java,v 1.1 2003/11/23 19:11:21 scolebourne Exp $
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001-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 acknowledgement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgement may appear in the software itself,
   *    if and wherever such third-party acknowledgements 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 names 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.collections.functors;
  
  import java.io.Serializable;
  
  import org.apache.commons.collections.Predicate;
  
  /**
   * Predicate implementation that returns true if the input is the same object
   * as the one stored in this predicate by equals.
   * 
   * @since Commons Collections 3.0
   * @version $Revision: 1.1 $ $Date: 2003/11/23 19:11:21 $
   *
   * @author Stephen Colebourne
   */
  public final class EqualPredicate implements Predicate, Serializable {
  
      /** Serial version UID */
      static final long serialVersionUID = 5633766978029907089L;
  
      /** The value to compare to */
      private final Object iValue;
      
      /**
       * Factory to create the identity predicate.
       * 
       * @param object  the object to compare to
       * @return the predicate
       * @throws IllegalArgumentException if the predicate is null
       */
      public static Predicate getInstance(Object object) {
          if (object == null) {
              return NullPredicate.INSTANCE;
          }
          return new EqualPredicate(object);
      }
  
      /**
       * Constructor that performs no validation.
       * Use <code>getInstance</code> if you want that.
       * 
       * @param object  the object to compare to
       */
      public EqualPredicate(Object object) {
          super();
          iValue = object;
      }
  
      /**
       * Return the predicate result.
       */
      public boolean evaluate(Object object) {
          return (iValue.equals(object));
      }
      
  }
  
  
  
  1.1                  jakarta-commons/collections/src/java/org/apache/commons/collections/functors/TruePredicate.java
  
  Index: TruePredicate.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/functors/TruePredicate.java,v 1.1 2003/11/23 19:11:21 scolebourne Exp $
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001-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 acknowledgement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgement may appear in the software itself,
   *    if and wherever such third-party acknowledgements 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 names 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.collections.functors;
  
  import java.io.Serializable;
  
  import org.apache.commons.collections.Predicate;
  
  /**
   * Predicate implementation that always returns true.
   * 
   * @since Commons Collections 3.0
   * @version $Revision: 1.1 $ $Date: 2003/11/23 19:11:21 $
   *
   * @author Stephen Colebourne
   */
  public final class TruePredicate implements Predicate, Serializable {
  
      /** Serial version UID */
      static final long serialVersionUID = 3374767158756189740L;
      
      /** Singleton predicate instance */    
      public static final Predicate INSTANCE = new TruePredicate();
      
      /**
       * Restricted constructor.
       */
      private TruePredicate() {
          super();
      }
  
      /**
       * Always return true.
       */
      public boolean evaluate(Object object) {
          return true;
      }
      
  }
  
  
  
  1.1                  jakarta-commons/collections/src/java/org/apache/commons/collections/functors/IdentityPredicate.java
  
  Index: IdentityPredicate.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/functors/IdentityPredicate.java,v 1.1 2003/11/23 19:11:21 scolebourne Exp $
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001-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 acknowledgement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgement may appear in the software itself,
   *    if and wherever such third-party acknowledgements 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 names 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.collections.functors;
  
  import java.io.Serializable;
  
  import org.apache.commons.collections.Predicate;
  
  /**
   * Predicate implementation that returns true if the input is the same object
   * as the one stored in this predicate.
   * 
   * @since Commons Collections 3.0
   * @version $Revision: 1.1 $ $Date: 2003/11/23 19:11:21 $
   *
   * @author Stephen Colebourne
   */
  public final class IdentityPredicate implements Predicate, Serializable {
  
      /** Serial version UID */
      static final long serialVersionUID = -89901658494523293L;
  
      
      /** The value to compare to */
      private final Object iValue;
      
      /**
       * Factory to create the identity predicate.
       * 
       * @param object  the object to compare to
       * @return the predicate
       * @throws IllegalArgumentException if the predicate is null
       */
      public static Predicate getInstance(Object object) {
          if (object == null) {
              return NullPredicate.INSTANCE;
          }
          return new IdentityPredicate(object);
      }
  
      /**
       * Constructor that performs no validation.
       * Use <code>getInstance</code> if you want that.
       * 
       * @param object  the object to compare to
       */
      public IdentityPredicate(Object object) {
          super();
          iValue = object;
      }
  
      /**
       * Return the predicate result.
       */
      public boolean evaluate(Object object) {
          return (iValue == object);
      }
      
  }
  
  
  
  1.1                  jakarta-commons/collections/src/java/org/apache/commons/collections/functors/NullPredicate.java
  
  Index: NullPredicate.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/functors/NullPredicate.java,v 1.1 2003/11/23 19:11:21 scolebourne Exp $
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001-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 acknowledgement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgement may appear in the software itself,
   *    if and wherever such third-party acknowledgements 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 names 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.collections.functors;
  
  import java.io.Serializable;
  
  import org.apache.commons.collections.Predicate;
  
  /**
   * Predicate implementation that returns true if the input is null.
   * 
   * @since Commons Collections 3.0
   * @version $Revision: 1.1 $ $Date: 2003/11/23 19:11:21 $
   *
   * @author Stephen Colebourne
   */
  public final class NullPredicate implements Predicate, Serializable {
  
      /** Serial version UID */
      static final long serialVersionUID = 7533784454832764388L;
      
      /** Singleton predicate instance */    
      public static final Predicate INSTANCE = new NullPredicate();
      
      /**
       * Restricted constructor.
       */
      private NullPredicate() {
          super();
      }
  
      /**
       * Return true if the object equals null.
       */
      public boolean evaluate(Object object) {
          return (object == null);
      }
      
  }
  
  
  
  1.1                  jakarta-commons/collections/src/java/org/apache/commons/collections/functors/NullIsTruePredicate.java
  
  Index: NullIsTruePredicate.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/functors/NullIsTruePredicate.java,v 1.1 2003/11/23 19:11:21 scolebourne Exp $
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001-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 acknowledgement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgement may appear in the software itself,
   *    if and wherever such third-party acknowledgements 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 names 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.collections.functors;
  
  import java.io.Serializable;
  
  import org.apache.commons.collections.Predicate;
  
  /**
   * Predicate implementation that returns true if the input is null.
   * 
   * @since Commons Collections 3.0
   * @version $Revision: 1.1 $ $Date: 2003/11/23 19:11:21 $
   *
   * @author Stephen Colebourne
   */
  public final class NullIsTruePredicate implements Predicate, Serializable {
  
      /** Serial version UID */
      static final long serialVersionUID = -7625133768987126273L;
      
      /** The predicate to decorate */
      private final Predicate iPredicate;
      
      /**
       * Factory to create the null true predicate.
       * 
       * @param predicate  the predicate to decorate, not null
       * @return the predicate
       * @throws IllegalArgumentException if the predicate is null
       */
      public static Predicate getInstance(Predicate predicate) {
          if (predicate == null) {
              throw new IllegalArgumentException("Predicate must not be null");
          }
          return new NullIsTruePredicate(predicate);
      }
  
      /**
       * Constructor that performs no validation.
       * Use <code>getInstance</code> if you want that.
       * 
       * @param predicate  the predicate to call after the null check
       */
      public NullIsTruePredicate(Predicate predicate) {
          super();
          iPredicate = predicate;
      }
  
      /**
       * Return true if the object equals null else call the decorated predicate.
       */
      public boolean evaluate(Object object) {
          if (object == null) {
              return true;
          }
          return iPredicate.evaluate(object);
      }
      
  }
  
  
  
  1.13      +24 -268   jakarta-commons/collections/src/java/org/apache/commons/collections/PredicateUtils.java
  
  Index: PredicateUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/PredicateUtils.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- PredicateUtils.java	23 Nov 2003 17:01:36 -0000	1.12
  +++ PredicateUtils.java	23 Nov 2003 19:11:21 -0000	1.13
  @@ -63,8 +63,19 @@
   import java.util.Iterator;
   import java.util.Set;
   
  +import org.apache.commons.collections.functors.EqualPredicate;
   import org.apache.commons.collections.functors.ExceptionPredicate;
  +import org.apache.commons.collections.functors.FalsePredicate;
   import org.apache.commons.collections.functors.FunctorException;
  +import org.apache.commons.collections.functors.IdentityPredicate;
  +import org.apache.commons.collections.functors.InstanceofPredicate;
  +import org.apache.commons.collections.functors.NotNullPredicate;
  +import org.apache.commons.collections.functors.NotPredicate;
  +import org.apache.commons.collections.functors.NullIsExceptionPredicate;
  +import org.apache.commons.collections.functors.NullIsFalsePredicate;
  +import org.apache.commons.collections.functors.NullIsTruePredicate;
  +import org.apache.commons.collections.functors.NullPredicate;
  +import org.apache.commons.collections.functors.TruePredicate;
   
   /**
    * <code>PredicateUtils</code> provides reference implementations and utilities
  @@ -99,23 +110,6 @@
   public class PredicateUtils {
   
       /**
  -     * A predicate that always returns true
  -     */
  -    private static final Predicate TRUE_PREDICATE = new ConstantPredicate(true);
  -    /**
  -     * A predicate that always returns false
  -     */
  -    private static final Predicate FALSE_PREDICATE = new ConstantPredicate(false);
  -    /**
  -     * A predicate that returns true if the object is null
  -     */
  -    private static final Predicate NULL_PREDICATE = new IdentityPredicate(null);
  -    /**
  -     * A predicate that returns true if the object is not null
  -     */
  -    private static final Predicate NOT_NULL_PREDICATE = new NotPredicate(NULL_PREDICATE);
  -
  -    /**
        * This class is not normally instantiated.
        */
       public PredicateUtils() {
  @@ -141,7 +135,7 @@
        * @return the predicate
        */
       public static Predicate truePredicate() {
  -        return TRUE_PREDICATE;
  +        return TruePredicate.INSTANCE;
       }
   
       /**
  @@ -150,7 +144,7 @@
        * @return the predicate
        */
       public static Predicate falsePredicate() {
  -        return FALSE_PREDICATE;
  +        return FalsePredicate.INSTANCE;
       }
   
       /**
  @@ -159,7 +153,7 @@
        * @return the predicate
        */
       public static Predicate nullPredicate() {
  -        return NULL_PREDICATE;
  +        return NullPredicate.INSTANCE;
       }
   
       /**
  @@ -168,7 +162,7 @@
        * @return the predicate
        */
       public static Predicate notNullPredicate() {
  -        return NOT_NULL_PREDICATE;
  +        return NotNullPredicate.INSTANCE;
       }
   
       /**
  @@ -179,10 +173,7 @@
        * @return the predicate
        */
       public static Predicate equalPredicate(Object value) {
  -        if (value == null) {
  -            return NULL_PREDICATE;
  -        }
  -        return new EqualPredicate(value);
  +        return EqualPredicate.getInstance(value);
       }
   
       /**
  @@ -193,10 +184,7 @@
        * @return the predicate
        */
       public static Predicate identityPredicate(Object value) {
  -        if (value == null) {
  -            return NULL_PREDICATE;
  -        }
  -        return new IdentityPredicate(value);
  +        return IdentityPredicate.getInstance(value);
       }
       
       /**
  @@ -209,10 +197,7 @@
        * @throws IllegalArgumentException if the class is null
        */
       public static Predicate instanceofPredicate(Class type) {
  -        if (type == null) {
  -            throw new IllegalArgumentException("The type to check instanceof must not be null");
  -        }
  -        return new InstanceofPredicate(type);
  +        return InstanceofPredicate.getInstance(type);
       }
   
       /**
  @@ -454,10 +439,7 @@
        * @throws IllegalArgumentException if the predicate is null
        */
       public static Predicate notPredicate(Predicate predicate) {
  -        if (predicate == null) {
  -            throw new IllegalArgumentException("The predicate must not be null");
  -        }
  -        return new NotPredicate(predicate);
  +        return NotPredicate.getInstance(predicate);
       }
   
       // Adaptors
  @@ -492,10 +474,7 @@
        * @throws IllegalArgumentException if the predicate is null.
        */
       public static Predicate nullIsExceptionPredicate(Predicate predicate){
  -        if (predicate == null) {
  -            throw new IllegalArgumentException("The predicate must not be null");
  -        }
  -        return new NullIsExceptionPredicate( predicate);
  +        return NullIsExceptionPredicate.getInstance(predicate);
       }
   
       /**
  @@ -508,10 +487,7 @@
        * @throws IllegalArgumentException if the predicate is null.
        */
       public static Predicate nullIsFalsePredicate(Predicate predicate){
  -        if (predicate == null) {
  -            throw new IllegalArgumentException("The predicate must not be null");
  -        }
  -        return new NullIsFalsePredicate(predicate);
  +        return NullIsFalsePredicate.getInstance(predicate);
       }
   
       /**
  @@ -524,10 +500,7 @@
        * @throws IllegalArgumentException if the predicate is null.
        */
       public static Predicate nullIsTruePredicate(Predicate predicate){
  -        if (predicate == null) {
  -            throw new IllegalArgumentException("The predicate must not be null");
  -        }
  -        return new NullIsTruePredicate(predicate);
  +        return NullIsTruePredicate.getInstance(predicate);
       }
   
       /**
  @@ -581,32 +554,6 @@
           return preds;
       }
   
  -    // ConstantPredicate
  -    //----------------------------------------------------------------------------------
  -
  -    /**
  -     * ConstantPredicate returns the same instance each time.
  -     */
  -    private static class ConstantPredicate implements Predicate, Serializable {
  -        /** The constant value to return each time */
  -        private final boolean iConstant;
  -
  -        /**
  -         * Constructor to store constant
  -         */
  -        private ConstantPredicate(boolean constant) {
  -            super();
  -            iConstant = constant;
  -        }
  -
  -        /**
  -         * Always return constant
  -         */
  -        public boolean evaluate(Object object) {
  -            return iConstant;
  -        }
  -    }
  -
       // AllPredicate
       //----------------------------------------------------------------------------------
   
  @@ -704,110 +651,6 @@
           }
       }
   
  -    // NotPredicate
  -    //----------------------------------------------------------------------------------
  -
  -    /**
  -     * NotPredicate returns the opposite of the wrapped predicate
  -     */
  -    private static class NotPredicate implements Predicate, Serializable {
  -        /** The predicate to call */
  -        private final Predicate iPredicate;
  -
  -        /**
  -         * Constructor
  -         */
  -        private NotPredicate(Predicate predicate) {
  -            super();
  -            iPredicate = predicate;
  -        }
  -
  -        /**
  -         * Return true if the wrapped predicate returns false, and vice versa
  -         */
  -        public boolean evaluate(Object object) {
  -            return !iPredicate.evaluate(object);
  -        }
  -    }
  -
  -    // InstanceofPredicate
  -    //----------------------------------------------------------------------------------
  -
  -    /**
  -     * InstanceofPredicate checks the type of an object
  -     */
  -    private static class InstanceofPredicate implements Predicate, Serializable {
  -        /** The type to check for */
  -        private final Class iType;
  -
  -        /**
  -         * Constructor
  -         */
  -        public InstanceofPredicate(Class type) {
  -            super();
  -            iType = type;
  -        }
  -
  -        /**
  -         * Return true if the object is an instanceof the type of the predicate.
  -         */
  -        public boolean evaluate(Object object) {
  -            return iType.isInstance(object);
  -        }
  -    }
  -
  -    // EqualPredicate
  -    //----------------------------------------------------------------------------------
  -
  -    /**
  -     * EqualPredicate that checks if the object is a particular value by equals().
  -     */
  -    private static class EqualPredicate implements Predicate, Serializable {
  -        /** The object to compare to */
  -        private final Object iValue;
  -
  -        /**
  -         * Constructor
  -         */
  -        public EqualPredicate(Object value) {
  -            super();
  -            iValue = value;
  -        }
  -
  -        /**
  -         * Return true if the object is equals() to the value stored in the predicate.
  -         */
  -        public boolean evaluate(Object object) {
  -            return iValue.equals(object);
  -        }
  -    }
  -
  -    // IdentityPredicate
  -    //----------------------------------------------------------------------------------
  -
  -    /**
  -     * IdentityPredicate that checks if the object is a particular value by identity.
  -     */
  -    private static class IdentityPredicate implements Predicate, Serializable {
  -        /** The object to compare identity to */
  -        private final Object iValue;
  -
  -        /**
  -         * Constructor
  -         */
  -        public IdentityPredicate(Object value) {
  -            super();
  -            iValue = value;
  -        }
  -
  -        /**
  -         * Return true if the object is equals() to the value stored in the predicate.
  -         */
  -        public boolean evaluate(Object object) {
  -            return iValue == object;
  -        }
  -    }
  -
       // UniquePredicate
       //----------------------------------------------------------------------------------
   
  @@ -865,93 +708,6 @@
                           + (result == null ? "null object" : result.getClass().getName()));
               }
               return ((Boolean) result).booleanValue();
  -        }
  -    }
  -
  -    // NullIsExceptionPredicate
  -    //----------------------------------------------------------------------------------
  -
  -    /**
  -     * NullIsExceptionPredicate returns an exception if null is passed in.
  -     */
  -    private static class NullIsExceptionPredicate implements Predicate, Serializable {
  -        /** The predicate to call */
  -        private final Predicate iPredicate;
  -        
  -        /**
  -         * Constructor
  -         */
  -        private NullIsExceptionPredicate(Predicate predicate){
  -            super();
  -            iPredicate = predicate;
  -        }
  -        
  -        /**
  -         * Return an exception if null
  -         */
  -        public boolean evaluate(Object object){
  -            if (object == null) {
  -                throw new FunctorException("NullIsExceptionPredicate: Input Object must not be null");
  -            }
  -            return iPredicate.evaluate(object);
  -        }
  -    }
  -
  -    // NullIsFalsePredicate
  -    //----------------------------------------------------------------------------------
  -
  -    /**
  -     * NullIsFalsePredicate returns false if null is passed in.
  -     */
  -    private static class NullIsFalsePredicate implements Predicate, Serializable {
  -        /** The predicate to call */
  -        private final Predicate iPredicate;
  -        
  -        /**
  -         * Constructor
  -         */
  -        private NullIsFalsePredicate(Predicate predicate){
  -            super();
  -            iPredicate = predicate;
  -        }
  -        
  -        /**
  -         * Return false if null
  -         */
  -        public boolean evaluate(Object object){
  -            if (object == null) {
  -                return false;
  -            }
  -            return iPredicate.evaluate(object);
  -        }
  -    }
  -
  -    // NullIsTruePredicate
  -    //----------------------------------------------------------------------------------
  -
  -    /**
  -     * NullIsTruePredicate returns true if null is passed in.
  -     */
  -    private static class NullIsTruePredicate implements Predicate, Serializable {
  -        /** The predicate to call */
  -        private final Predicate iPredicate;
  -        
  -        /**
  -         * Constructor
  -         */
  -        private NullIsTruePredicate(Predicate predicate){
  -            super();
  -            iPredicate = predicate;
  -        }
  -        
  -        /**
  -         * Return true if null
  -         */
  -        public boolean evaluate(Object object){
  -            if (object == null) {
  -                return true;
  -            }
  -            return iPredicate.evaluate(object);
           }
       }
   
  
  
  

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