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 Sat, 25 Jan 2003 11:29:37 GMT
scolebourne    2003/01/25 03:29:37

  Modified:    collections/src/java/org/apache/commons/collections
                        CollectionUtils.java
  Log:
  Improve performance by not using local variables in iterator loops
  Javadoc null comment tidying
  from Peter KoBek
  
  Revision  Changes    Path
  1.27      +15 -21    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.26
  retrieving revision 1.27
  diff -u -r1.26 -r1.27
  --- CollectionUtils.java	20 Jan 2003 01:29:30 -0000	1.26
  +++ CollectionUtils.java	25 Jan 2003 11:29:37 -0000	1.27
  @@ -366,17 +366,15 @@
       /** 
        * Executes the given closure on each element in the collection.
        * <p>
  -     * If the input collection is null, there is no change made.
  +     * If the input collection or closure is null, there is no change made.
        * 
        * @param collection  the collection to get the input from, may be null
  -     * @param closure  the closure to perform, may not be null
  -     * @throws NullPointerException if the closure is null
  +     * @param closure  the closure to perform, may be null
        */
       public static void forAllDo(Collection collection, Closure closure) {
  -        if (collection != null) {
  -            for (Iterator iter = collection.iterator(); iter.hasNext();) {
  -                Object element = iter.next();
  -                closure.execute(element);
  +        if (collection != null && closure != null) {
  +            for (Iterator it = collection.iterator(); it.hasNext();) {
  +                closure.execute(it.next());
               }
           }
       }
  @@ -392,10 +390,9 @@
        */
       public static void filter(Collection collection, Predicate predicate) {
           if (collection != null && predicate != null) {
  -            for (Iterator iter = collection.iterator(); iter.hasNext();) {
  -                Object element = iter.next();
  -                if (predicate.evaluate(element) == false) {
  -                    iter.remove();
  +            for (Iterator it = collection.iterator(); it.hasNext();) {
  +                if (predicate.evaluate(it.next()) == false) {
  +                    it.remove();
                   }
               }
           }
  @@ -420,9 +417,8 @@
           if (collection != null && transformer != null) {
               if (collection instanceof List) {
                   List list = (List) collection;
  -                for (ListIterator iter = list.listIterator(); iter.hasNext();) {
  -                    Object element = iter.next();
  -                    iter.set(transformer.transform(element));
  +                for (ListIterator it = list.listIterator(); it.hasNext();) {
  +                    it.set(transformer.transform(it.next()));
                   }
               } else {
                   Collection resultCollection = collect(collection, transformer);
  @@ -435,19 +431,17 @@
       /** 
        * Counts the number of elements in the input collection that match the predicate.
        * <p>
  -     * A <code>null</code> predicate matches no elements.
  +     * A <code>null</code> collection or predicate matches no elements.
        * 
  -     * @param inputCollection  the collection to get the input from, may not be null
  +     * @param inputCollection  the collection to get the input from, may be null
        * @param predicate  the predicate to use, may be null
        * @return the number of matches for the predicate in the collection
  -     * @throws NullPointerException if the input collection is null
        */
       public static int countMatches(Collection inputCollection, Predicate predicate) {
           int count = 0;
           if (inputCollection != null && predicate != null) {
               for (Iterator it = inputCollection.iterator(); it.hasNext();) {
  -                Object item = it.next();
  -                if (predicate.evaluate(item)) {
  +                if (predicate.evaluate(it.next())) {
                       count++;
                   }
               }
  
  
  

--
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