Implement new Resetable Iterator interfaces

Update licence
Update since and version tags


git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@130951 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Stephen Colebourne 2003-01-15 21:53:14 +00:00
parent c08ffff306
commit 55178c1244
4 changed files with 64 additions and 53 deletions

View File

@ -1,13 +1,10 @@
/* /*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/iterators/ArrayIterator.java,v 1.2 2002/12/13 12:01:35 scolebourne Exp $ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/iterators/ArrayIterator.java,v 1.3 2003/01/15 21:53:14 scolebourne Exp $
* $Revision: 1.2 $
* $Date: 2002/12/13 12:01:35 $
*
* ==================================================================== * ====================================================================
* *
* The Apache Software License, Version 1.1 * The Apache Software License, Version 1.1
* *
* Copyright (c) 1999-2002 The Apache Software Foundation. All rights * Copyright (c) 1999-2003 The Apache Software Foundation. All rights
* reserved. * reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -23,11 +20,11 @@
* distribution. * distribution.
* *
* 3. The end-user documentation included with the redistribution, if * 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement: * any, must include the following acknowledgment:
* "This product includes software developed by the * "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)." * Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself, * Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear. * if and wherever such third-party acknowledgments normally appear.
* *
* 4. The names "The Jakarta Project", "Commons", and "Apache Software * 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived * Foundation" must not be used to endorse or promote products derived
@ -36,7 +33,7 @@
* *
* 5. Products derived from this software may not be called "Apache" * 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written * nor may "Apache" appear in their names without prior written
* permission of the Apache Group. * permission of the Apache Software Foundation.
* *
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
@ -63,6 +60,7 @@ package org.apache.commons.collections.iterators;
import java.lang.reflect.Array; import java.lang.reflect.Array;
import java.util.Iterator; import java.util.Iterator;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
/** /**
* Implements an {@link java.util.Iterator Iterator} over an array. * Implements an {@link java.util.Iterator Iterator} over an array.
* <p> * <p>
@ -71,18 +69,19 @@ import java.util.NoSuchElementException;
* {@link org.apache.commons.collections.iterators.ObjectArrayIterator ObjectArrayIterator} * {@link org.apache.commons.collections.iterators.ObjectArrayIterator ObjectArrayIterator}
* class is a better choice, as it will perform better. * class is a better choice, as it will perform better.
* <p> * <p>
* The iterator implements a {@link #reset} method, allowing the reset of the iterator * The iterator implements a {@link #reset} method, allowing the reset of
* back to the start if required. * the iterator back to the start if required.
*
* @since Commons Collections 1.0
* @version $Revision: 1.3 $ $Date: 2003/01/15 21:53:14 $
* *
* @since 1.0
* @author <a href="mailto:jstrachan@apache.org">James Strachan</a> * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
* @author Mauricio S. Moura * @author Mauricio S. Moura
* @author <a href="mailto:mas@apache.org">Michael A. Smith</a> * @author <a href="mailto:mas@apache.org">Michael A. Smith</a>
* @author <a href="mailto:neilotoole@users.sourceforge.net">Neil O'Toole</a> * @author <a href="mailto:neilotoole@users.sourceforge.net">Neil O'Toole</a>
* @author Stephen Colebourne * @author Stephen Colebourne
* @version $Revision: 1.2 $
*/ */
public class ArrayIterator implements Iterator { public class ArrayIterator implements ResetableIterator {
/** The array */ /** The array */
protected Object array; protected Object array;
@ -100,6 +99,7 @@ public class ArrayIterator implements Iterator {
* until {@link #setArray(Object)} is called to establish the array to iterate over. * until {@link #setArray(Object)} is called to establish the array to iterate over.
*/ */
public ArrayIterator() { public ArrayIterator() {
super();
} }
/** /**
@ -111,6 +111,7 @@ public class ArrayIterator implements Iterator {
* @throws NullPointerException if <code>array</code> is <code>null</code> * @throws NullPointerException if <code>array</code> is <code>null</code>
*/ */
public ArrayIterator(Object array) { public ArrayIterator(Object array) {
super();
setArray( array ); setArray( array );
} }

View File

@ -1,13 +1,10 @@
/* /*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/iterators/ArrayListIterator.java,v 1.1 2002/12/13 12:01:35 scolebourne Exp $ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/iterators/ArrayListIterator.java,v 1.2 2003/01/15 21:53:14 scolebourne Exp $
* $Revision: 1.1 $
* $Date: 2002/12/13 12:01:35 $
*
* ==================================================================== * ====================================================================
* *
* The Apache Software License, Version 1.1 * The Apache Software License, Version 1.1
* *
* Copyright (c) 1999-2002 The Apache Software Foundation. All rights * Copyright (c) 1999-2003 The Apache Software Foundation. All rights
* reserved. * reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -23,11 +20,11 @@
* distribution. * distribution.
* *
* 3. The end-user documentation included with the redistribution, if * 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement: * any, must include the following acknowledgment:
* "This product includes software developed by the * "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)." * Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself, * Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear. * if and wherever such third-party acknowledgments normally appear.
* *
* 4. The names "The Jakarta Project", "Commons", and "Apache Software * 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived * Foundation" must not be used to endorse or promote products derived
@ -36,7 +33,7 @@
* *
* 5. Products derived from this software may not be called "Apache" * 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written * nor may "Apache" appear in their names without prior written
* permission of the Apache Group. * permission of the Apache Software Foundation.
* *
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
@ -63,6 +60,7 @@ package org.apache.commons.collections.iterators;
import java.lang.reflect.Array; import java.lang.reflect.Array;
import java.util.ListIterator; import java.util.ListIterator;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
/** /**
* Implements a {@link java.util.ListIterator ListIterator} over an array. * Implements a {@link java.util.ListIterator ListIterator} over an array.
* <p> * <p>
@ -79,12 +77,13 @@ import java.util.NoSuchElementException;
* @see java.util.Iterator * @see java.util.Iterator
* @see java.util.ListIterator * @see java.util.ListIterator
* *
* @since 2.2 * @since Commons Collections 2.2
* @version $Revision: 1.2 $ $Date: 2003/01/15 21:53:14 $
*
* @author <a href="mailto:neilotoole@users.sourceforge.net">Neil O'Toole</a> * @author <a href="mailto:neilotoole@users.sourceforge.net">Neil O'Toole</a>
* @author Stephen Colebourne * @author Stephen Colebourne
* @version $Revision: 1.1 $
*/ */
public class ArrayListIterator extends ArrayIterator implements ListIterator { public class ArrayListIterator extends ArrayIterator implements ResetableListIterator {
/** /**
* Holds the index of the last item returned by a call to <code>next()</code> or <code>previous()</code>. This * Holds the index of the last item returned by a call to <code>next()</code> or <code>previous()</code>. This

View File

@ -1,13 +1,10 @@
/* /*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/iterators/SingletonIterator.java,v 1.2 2002/08/17 11:29:38 scolebourne Exp $ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/iterators/SingletonIterator.java,v 1.3 2003/01/15 21:51:05 scolebourne Exp $
* $Revision: 1.2 $
* $Date: 2002/08/17 11:29:38 $
*
* ==================================================================== * ====================================================================
* *
* The Apache Software License, Version 1.1 * The Apache Software License, Version 1.1
* *
* Copyright (c) 1999-2002 The Apache Software Foundation. All rights * Copyright (c) 1999-2003 The Apache Software Foundation. All rights
* reserved. * reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -23,11 +20,11 @@
* distribution. * distribution.
* *
* 3. The end-user documentation included with the redistribution, if * 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement: * any, must include the following acknowledgment:
* "This product includes software developed by the * "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)." * Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself, * Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear. * if and wherever such third-party acknowledgments normally appear.
* *
* 4. The names "The Jakarta Project", "Commons", and "Apache Software * 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived * Foundation" must not be used to endorse or promote products derived
@ -36,7 +33,7 @@
* *
* 5. Products derived from this software may not be called "Apache" * 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written * nor may "Apache" appear in their names without prior written
* permission of the Apache Group. * permission of the Apache Software Foundation.
* *
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
@ -62,16 +59,18 @@ package org.apache.commons.collections.iterators;
import java.util.Iterator; import java.util.Iterator;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
/** /**
* <p><code>SingletonIterator</code> is an {@link Iterator} over a single * <p><code>SingletonIterator</code> is an {@link Iterator} over a single
* object instance.</p> * object instance.</p>
* *
* @since 2.0 * @since Commons Collections 2.0
* @version $Revision: 1.3 $ $Date: 2003/01/15 21:51:05 $
*
* @author <a href="mailto:jstrachan@apache.org">James Strachan</a> * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
* @author <a href="mailto:scolebourne@joda.org">Stephen Colebourne</a> * @author Stephen Colebourne
* @version $Revision: 1.2 $
*/ */
public class SingletonIterator implements Iterator { public class SingletonIterator implements ResetableIterator {
private boolean first = true; private boolean first = true;
private Object object; private Object object;
@ -111,7 +110,6 @@ public class SingletonIterator implements Iterator {
throw new NoSuchElementException(); throw new NoSuchElementException();
} }
Object answer = object; Object answer = object;
object = null;
first = false; first = false;
return answer; return answer;
} }
@ -125,4 +123,11 @@ public class SingletonIterator implements Iterator {
throw new UnsupportedOperationException("remove() is not supported by this iterator"); throw new UnsupportedOperationException("remove() is not supported by this iterator");
} }
/**
* Reset the iterator to the start.
*/
public void reset() {
first = true;
}
} }

View File

@ -1,13 +1,10 @@
/* /*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/iterators/SingletonListIterator.java,v 1.2 2002/08/19 21:56:18 pjack Exp $ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/iterators/SingletonListIterator.java,v 1.3 2003/01/15 21:51:05 scolebourne Exp $
* $Revision: 1.2 $
* $Date: 2002/08/19 21:56:18 $
*
* ==================================================================== * ====================================================================
* *
* The Apache Software License, Version 1.1 * The Apache Software License, Version 1.1
* *
* Copyright (c) 1999-2002 The Apache Software Foundation. All rights * Copyright (c) 1999-2003 The Apache Software Foundation. All rights
* reserved. * reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -23,11 +20,11 @@
* distribution. * distribution.
* *
* 3. The end-user documentation included with the redistribution, if * 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement: * any, must include the following acknowledgment:
* "This product includes software developed by the * "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)." * Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself, * Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear. * if and wherever such third-party acknowledgments normally appear.
* *
* 4. The names "The Jakarta Project", "Commons", and "Apache Software * 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived * Foundation" must not be used to endorse or promote products derived
@ -36,7 +33,7 @@
* *
* 5. Products derived from this software may not be called "Apache" * 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written * nor may "Apache" appear in their names without prior written
* permission of the Apache Group. * permission of the Apache Software Foundation.
* *
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
@ -66,11 +63,12 @@ import java.util.NoSuchElementException;
* <p><code>SingletonIterator</code> is an {@link ListIterator} over a single * <p><code>SingletonIterator</code> is an {@link ListIterator} over a single
* object instance.</p> * object instance.</p>
* *
* @since 2.1 * @since Commons Collections 2.1
* @author <a href="mailto:scolebourne@joda.org">Stephen Colebourne</a> * @version $Revision: 1.3 $ $Date: 2003/01/15 21:51:05 $
* @version $Id: SingletonListIterator.java,v 1.2 2002/08/19 21:56:18 pjack Exp $ *
* @author Stephen Colebourne
*/ */
public class SingletonListIterator implements ListIterator { public class SingletonListIterator implements ResetableListIterator {
private boolean first = true; private boolean first = true;
private boolean nextCalled = false; private boolean nextCalled = false;
@ -195,4 +193,12 @@ public class SingletonListIterator implements ListIterator {
this.object = obj; this.object = obj;
} }
/**
* Reset the iterator back to the start.
*/
public void reset() {
first = true;
nextCalled = false;
}
} }