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:
parent
c08ffff306
commit
55178c1244
|
@ -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 $
|
||||
* $Revision: 1.2 $
|
||||
* $Date: 2002/12/13 12:01:35 $
|
||||
*
|
||||
* $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 $
|
||||
* ====================================================================
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
@ -23,11 +20,11 @@
|
|||
* distribution.
|
||||
*
|
||||
* 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
|
||||
* Apache Software Foundation (http://www.apache.org/)."
|
||||
* Alternately, this acknowlegement may appear in the software itself,
|
||||
* if and wherever such third-party acknowlegements normally appear.
|
||||
* Alternately, this acknowledgment may appear in the software itself,
|
||||
* if and wherever such third-party acknowledgments normally appear.
|
||||
*
|
||||
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
|
||||
* 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"
|
||||
* 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
|
||||
* 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.util.Iterator;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
/**
|
||||
* Implements an {@link java.util.Iterator Iterator} over an array.
|
||||
* <p>
|
||||
|
@ -71,18 +69,19 @@ import java.util.NoSuchElementException;
|
|||
* {@link org.apache.commons.collections.iterators.ObjectArrayIterator ObjectArrayIterator}
|
||||
* class is a better choice, as it will perform better.
|
||||
* <p>
|
||||
* The iterator implements a {@link #reset} method, allowing the reset of the iterator
|
||||
* back to the start if required.
|
||||
* The iterator implements a {@link #reset} method, allowing the reset of
|
||||
* 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 Mauricio S. Moura
|
||||
* @author <a href="mailto:mas@apache.org">Michael A. Smith</a>
|
||||
* @author <a href="mailto:neilotoole@users.sourceforge.net">Neil O'Toole</a>
|
||||
* @author Stephen Colebourne
|
||||
* @version $Revision: 1.2 $
|
||||
*/
|
||||
public class ArrayIterator implements Iterator {
|
||||
public class ArrayIterator implements ResetableIterator {
|
||||
|
||||
/** The 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.
|
||||
*/
|
||||
public ArrayIterator() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -111,6 +111,7 @@ public class ArrayIterator implements Iterator {
|
|||
* @throws NullPointerException if <code>array</code> is <code>null</code>
|
||||
*/
|
||||
public ArrayIterator(Object array) {
|
||||
super();
|
||||
setArray( array );
|
||||
}
|
||||
|
||||
|
|
|
@ -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 $
|
||||
* $Revision: 1.1 $
|
||||
* $Date: 2002/12/13 12:01:35 $
|
||||
*
|
||||
* $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 $
|
||||
* ====================================================================
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
@ -23,11 +20,11 @@
|
|||
* distribution.
|
||||
*
|
||||
* 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
|
||||
* Apache Software Foundation (http://www.apache.org/)."
|
||||
* Alternately, this acknowlegement may appear in the software itself,
|
||||
* if and wherever such third-party acknowlegements normally appear.
|
||||
* Alternately, this acknowledgment may appear in the software itself,
|
||||
* if and wherever such third-party acknowledgments normally appear.
|
||||
*
|
||||
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
|
||||
* 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"
|
||||
* 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
|
||||
* 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.util.ListIterator;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
/**
|
||||
* Implements a {@link java.util.ListIterator ListIterator} over an array.
|
||||
* <p>
|
||||
|
@ -79,12 +77,13 @@ import java.util.NoSuchElementException;
|
|||
* @see java.util.Iterator
|
||||
* @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 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
|
||||
|
|
|
@ -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 $
|
||||
* $Revision: 1.2 $
|
||||
* $Date: 2002/08/17 11:29:38 $
|
||||
*
|
||||
* $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 $
|
||||
* ====================================================================
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
@ -23,11 +20,11 @@
|
|||
* distribution.
|
||||
*
|
||||
* 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
|
||||
* Apache Software Foundation (http://www.apache.org/)."
|
||||
* Alternately, this acknowlegement may appear in the software itself,
|
||||
* if and wherever such third-party acknowlegements normally appear.
|
||||
* Alternately, this acknowledgment may appear in the software itself,
|
||||
* if and wherever such third-party acknowledgments normally appear.
|
||||
*
|
||||
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
|
||||
* 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"
|
||||
* 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
|
||||
* 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.NoSuchElementException;
|
||||
|
||||
/**
|
||||
* <p><code>SingletonIterator</code> is an {@link Iterator} over a single
|
||||
* 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:scolebourne@joda.org">Stephen Colebourne</a>
|
||||
* @version $Revision: 1.2 $
|
||||
* @author Stephen Colebourne
|
||||
*/
|
||||
public class SingletonIterator implements Iterator {
|
||||
public class SingletonIterator implements ResetableIterator {
|
||||
|
||||
private boolean first = true;
|
||||
private Object object;
|
||||
|
@ -111,7 +110,6 @@ public class SingletonIterator implements Iterator {
|
|||
throw new NoSuchElementException();
|
||||
}
|
||||
Object answer = object;
|
||||
object = null;
|
||||
first = false;
|
||||
return answer;
|
||||
}
|
||||
|
@ -125,4 +123,11 @@ public class SingletonIterator implements Iterator {
|
|||
throw new UnsupportedOperationException("remove() is not supported by this iterator");
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the iterator to the start.
|
||||
*/
|
||||
public void reset() {
|
||||
first = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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 $
|
||||
* $Revision: 1.2 $
|
||||
* $Date: 2002/08/19 21:56:18 $
|
||||
*
|
||||
* $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 $
|
||||
* ====================================================================
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
@ -23,11 +20,11 @@
|
|||
* distribution.
|
||||
*
|
||||
* 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
|
||||
* Apache Software Foundation (http://www.apache.org/)."
|
||||
* Alternately, this acknowlegement may appear in the software itself,
|
||||
* if and wherever such third-party acknowlegements normally appear.
|
||||
* Alternately, this acknowledgment may appear in the software itself,
|
||||
* if and wherever such third-party acknowledgments normally appear.
|
||||
*
|
||||
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
|
||||
* 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"
|
||||
* 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
|
||||
* 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
|
||||
* object instance.</p>
|
||||
*
|
||||
* @since 2.1
|
||||
* @author <a href="mailto:scolebourne@joda.org">Stephen Colebourne</a>
|
||||
* @version $Id: SingletonListIterator.java,v 1.2 2002/08/19 21:56:18 pjack Exp $
|
||||
* @since Commons Collections 2.1
|
||||
* @version $Revision: 1.3 $ $Date: 2003/01/15 21:51:05 $
|
||||
*
|
||||
* @author Stephen Colebourne
|
||||
*/
|
||||
public class SingletonListIterator implements ListIterator {
|
||||
public class SingletonListIterator implements ResetableListIterator {
|
||||
|
||||
private boolean first = true;
|
||||
private boolean nextCalled = false;
|
||||
|
@ -195,4 +193,12 @@ public class SingletonListIterator implements ListIterator {
|
|||
this.object = obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the iterator back to the start.
|
||||
*/
|
||||
public void reset() {
|
||||
first = true;
|
||||
nextCalled = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue