commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From scolebou...@apache.org
Subject cvs commit: jakarta-commons/collections/src/java/org/apache/commons/collections CollectionUtils.java
Date Sun, 24 Nov 2002 21:11:28 GMT
scolebourne    2002/11/24 13:11:27

  Modified:    collections/src/java/org/apache/commons/collections
                        CollectionUtils.java
  Log:
  Add selectRejected methods, from BluePhelix@web.de (Peter)
  
  Revision  Changes    Path
  1.21      +40 -4     jakarta-commons/collections/src/java/org/apache/commons/collections/CollectionUtils.java
  
  Index: CollectionUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/CollectionUtils.java,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- CollectionUtils.java	24 Nov 2002 16:23:21 -0000	1.20
  +++ CollectionUtils.java	24 Nov 2002 21:11:27 -0000	1.21
  @@ -83,6 +83,7 @@
    * @author Stephen Colebourne
    * @author Steve Downey
    * @author <a href="herve.quiroz@esil.univ-mrs.fr">Herve Quiroz</a>
  + * @author BluePhelix@web.de (Peter)
    * @version $Revision$ $Date$
    */
   public class CollectionUtils {
  @@ -463,6 +464,41 @@
           }
       }
       
  +    /**
  +     * Selects all elements from inputCollection which don't match the given predicate
  +     * into an output collection
  +     * 
  +     * @param inputCollection  the collection to get the input from, may not be null
  +     * @param predicate  the predicate to use, may be null
  +     * @return the elements <b>not</b> matching the predicate (new list)
  +     * @throws NullPointerException if the input collection is null
  +     */
  +    public static Collection selectRejected(Collection inputCollection, Predicate predicate)
{
  +        ArrayList answer = new ArrayList(inputCollection.size());
  +        selectRejected(inputCollection, predicate, answer);
  +        return answer;
  +    }
  +    
  +    /** 
  +     * Selects all elements from inputCollection which don't match the given predicate
  +     * and adds them to outputCollection
  +     * 
  +     * @param inputCollection  the collection to get the input from, may be null
  +     * @param predicate  the predicate to use, may be null
  +     * @param outputCollection  the collection to output into, may not be null
  +     * @return the outputCollection with the the elements <b>not</b> matching
the predicate added
  +     * @throws NullPointerException if the input collection is null
  +     */
  +    public static void selectRejected(Collection inputCollection, Predicate predicate,
Collection outputCollection) {
  +        if (inputCollection != null && predicate != null) {
  +            for (Iterator iter = inputCollection.iterator(); iter.hasNext();) {
  +                Object item = iter.next();
  +                if (predicate.evaluate(item) == false) {
  +                    outputCollection.add(item);
  +                }
  +            }
  +        }
  +    }
       /** 
        * Transforms all elements from inputCollection with the given transformer 
        * and adds them to the outputCollection.
  
  
  

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


Mime
View raw message