You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by ba...@apache.org on 2001/11/26 18:15:33 UTC

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

bayard      01/11/26 09:15:33

  Modified:    collections/src/java/org/apache/commons/collections
                        CollectionUtils.java
  Log:
  An empty iterator. It is immutable and always the same object instance.
  Submitted by:	Christopher Elkins <ch...@scardini.com>
  
  Revision  Changes    Path
  1.6       +30 -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.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- CollectionUtils.java	2001/08/29 16:10:29	1.5
  +++ CollectionUtils.java	2001/11/26 17:15:33	1.6
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/CollectionUtils.java,v 1.5 2001/08/29 16:10:29 jstrachan Exp $
  - * $Revision: 1.5 $
  - * $Date: 2001/08/29 16:10:29 $
  + * $Header: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/CollectionUtils.java,v 1.6 2001/11/26 17:15:33 bayard Exp $
  + * $Revision: 1.6 $
  + * $Date: 2001/11/26 17:15:33 $
    *
    * ====================================================================
    *
  @@ -77,10 +77,35 @@
    *
    * @author Rodney Waldhoff
    *
  - * @version $Id: CollectionUtils.java,v 1.5 2001/08/29 16:10:29 jstrachan Exp $
  + * @version $Id: CollectionUtils.java,v 1.6 2001/11/26 17:15:33 bayard Exp $
    */
   public class CollectionUtils {
  +
  +    /**
  +     * The empty iterator (immutable).
  +     */
  +    public static final Iterator EMPTY_ITERATOR = new EmptyIterator();
  +
       /**
  +     * 'Hidden' class which acts as an EmptyIterator.
  +     * An alternative is to use: Collections.EMPTY_LIST.iterator();
  +     * however that will create a new iterator object each time.
  +     */
  +    private static class EmptyIterator implements Iterator {
  +        public boolean hasNext() {
  +            return false;
  +        }
  +
  +        public Object next() {
  +            throw new NoSuchElementException();
  +        }
  +
  +        public void remove() {
  +            throw new UnsupportedOperationException();
  +        }
  +    }
  +
  +    /**
        * Returns a {@link Collection} containing the union
        * of the given {@link Collection}s.
        * <p>
  @@ -502,6 +527,7 @@
               return null;
           }
       }
  +
   
       /** Reverses the order of the given array */
       public static void reverseArray(Object[] array) {
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>