An empty iterator. It is immutable and always the same object instance.

Submitted by:	Christopher Elkins <chrise@scardini.com>


git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@130508 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Henri Yandell 2001-11-26 17:15:33 +00:00
parent 51a5b46632
commit 3d6c8c5fab
1 changed files with 30 additions and 4 deletions

View File

@ -1,7 +1,7 @@
/* /*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/CollectionUtils.java,v 1.5 2001/08/29 16:10:29 jstrachan Exp $ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/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.5 $ * $Revision: 1.6 $
* $Date: 2001/08/29 16:10:29 $ * $Date: 2001/11/26 17:15:33 $
* *
* ==================================================================== * ====================================================================
* *
@ -77,9 +77,34 @@ import java.util.Set;
* *
* @author Rodney Waldhoff * @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 { 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 * Returns a {@link Collection} containing the union
* of the given {@link Collection}s. * of the given {@link Collection}s.
@ -503,6 +528,7 @@ public class CollectionUtils {
} }
} }
/** Reverses the order of the given array */ /** Reverses the order of the given array */
public static void reverseArray(Object[] array) { public static void reverseArray(Object[] array) {
int i = 0; int i = 0;