diff --git a/src/java/org/apache/commons/collections/iterators/AbstractIteratorDecorator.java b/src/java/org/apache/commons/collections/iterators/AbstractIteratorDecorator.java
new file mode 100644
index 000000000..a29c736cb
--- /dev/null
+++ b/src/java/org/apache/commons/collections/iterators/AbstractIteratorDecorator.java
@@ -0,0 +1,115 @@
+/*
+ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/iterators/AbstractIteratorDecorator.java,v 1.1 2003/11/02 16:29:12 scolebourne Exp $
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 1999-2003 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ * any, must include the following acknowledgement:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgement may appear in the software itself,
+ * if and wherever such third-party acknowledgements normally appear.
+ *
+ * 4. The names "The Jakarta Project", "Commons", and "Apache Software
+ * Foundation" must not be used to endorse or promote products derived
+ * from this software without prior written permission. For written
+ * permission, please contact apache@apache.org.
+ *
+ * 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 Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ *
+ * All methods are forwarded to the decorated iterator.
+ *
+ * @since Commons Collections 3.0
+ * @version $Revision: 1.1 $ $Date: 2003/11/02 16:29:12 $
+ *
+ * @author James Strachan
+ * @author Stephen Colebourne
+ */
+public class AbstractIteratorDecorator implements Iterator {
+
+ /** The iterator being decorated */
+ private Iterator iterator;
+
+ //-----------------------------------------------------------------------
+ /**
+ * Constructor that decorates the specified iterator.
+ *
+ * @param iterator the iterator to decorate, must not be null
+ * @throws IllegalArgumentException if the collection is null
+ */
+ public AbstractIteratorDecorator(Iterator iterator) {
+ super();
+ if (iterator == null) {
+ throw new IllegalArgumentException("Iterator must not be null");
+ }
+ this.iterator = iterator;
+ }
+
+ /**
+ * Gets the iterator being decorated.
+ *
+ * @return the decorated iterator
+ */
+ protected Iterator getIterator() {
+ return iterator;
+ }
+
+ //-----------------------------------------------------------------------
+ public boolean hasNext() {
+ return iterator.hasNext();
+ }
+
+ public Object next() {
+ return iterator.next();
+ }
+
+ public void remove() {
+ iterator.remove();
+ }
+
+}
diff --git a/src/java/org/apache/commons/collections/iterators/AbstractListIteratorDecorator.java b/src/java/org/apache/commons/collections/iterators/AbstractListIteratorDecorator.java
new file mode 100644
index 000000000..461068bb6
--- /dev/null
+++ b/src/java/org/apache/commons/collections/iterators/AbstractListIteratorDecorator.java
@@ -0,0 +1,138 @@
+/*
+ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/iterators/AbstractListIteratorDecorator.java,v 1.1 2003/11/02 16:29:12 scolebourne Exp $
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 1999-2003 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ * any, must include the following acknowledgement:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgement may appear in the software itself,
+ * if and wherever such third-party acknowledgements normally appear.
+ *
+ * 4. The names "The Jakarta Project", "Commons", and "Apache Software
+ * Foundation" must not be used to endorse or promote products derived
+ * from this software without prior written permission. For written
+ * permission, please contact apache@apache.org.
+ *
+ * 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 Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ *
+ * All methods are forwarded to the decorated list iterator.
+ *
+ * @since Commons Collections 3.0
+ * @version $Revision: 1.1 $ $Date: 2003/11/02 16:29:12 $
+ *
+ * @author Rodney Waldhoff
+ * @author Stephen Colebourne
+ */
+public class AbstractListIteratorDecorator implements ListIterator {
+
+ /** The iterator being decorated */
+ private ListIterator iterator;
+
+ //-----------------------------------------------------------------------
+ /**
+ * Constructor that decorates the specified iterator.
+ *
+ * @param iterator the iterator to decorate, must not be null
+ * @throws IllegalArgumentException if the collection is null
+ */
+ public AbstractListIteratorDecorator(ListIterator iterator) {
+ super();
+ if (iterator == null) {
+ throw new IllegalArgumentException("ListIterator must not be null");
+ }
+ this.iterator = iterator;
+ }
+
+ /**
+ * Gets the iterator being decorated.
+ *
+ * @return the decorated iterator
+ */
+ protected ListIterator getListIterator() {
+ return iterator;
+ }
+
+ //-----------------------------------------------------------------------
+ public boolean hasNext() {
+ return iterator.hasNext();
+ }
+
+ public Object next() {
+ return iterator.next();
+ }
+
+ public int nextIndex() {
+ return iterator.nextIndex();
+ }
+
+ public boolean hasPrevious() {
+ return iterator.hasPrevious();
+ }
+
+ public Object previous() {
+ return iterator.previous();
+ }
+
+ public int previousIndex() {
+ return iterator.previousIndex();
+ }
+
+ public void remove() {
+ iterator.remove();
+ }
+
+ public void set(Object obj) {
+ iterator.set(obj);
+ }
+
+ public void add(Object obj) {
+ iterator.add(obj);
+ }
+}
diff --git a/src/java/org/apache/commons/collections/iterators/AbstractMapIteratorDecorator.java b/src/java/org/apache/commons/collections/iterators/AbstractMapIteratorDecorator.java
new file mode 100644
index 000000000..9d7cb8767
--- /dev/null
+++ b/src/java/org/apache/commons/collections/iterators/AbstractMapIteratorDecorator.java
@@ -0,0 +1,130 @@
+/*
+ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/iterators/AbstractMapIteratorDecorator.java,v 1.1 2003/11/02 16:29:12 scolebourne Exp $
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 1999-2003 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ * any, must include the following acknowledgement:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgement may appear in the software itself,
+ * if and wherever such third-party acknowledgements normally appear.
+ *
+ * 4. The names "The Jakarta Project", "Commons", and "Apache Software
+ * Foundation" must not be used to endorse or promote products derived
+ * from this software without prior written permission. For written
+ * permission, please contact apache@apache.org.
+ *
+ * 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 Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ *
+ * All methods are forwarded to the decorated map iterator.
+ *
+ * @since Commons Collections 3.0
+ * @version $Revision: 1.1 $ $Date: 2003/11/02 16:29:12 $
+ *
+ * @author Stephen Colebourne
+ */
+public class AbstractMapIteratorDecorator implements MapIterator {
+
+ /** The iterator being decorated */
+ private MapIterator iterator;
+
+ //-----------------------------------------------------------------------
+ /**
+ * Constructor that decorates the specified iterator.
+ *
+ * @param iterator the iterator to decorate, must not be null
+ * @throws IllegalArgumentException if the collection is null
+ */
+ public AbstractMapIteratorDecorator(MapIterator iterator) {
+ super();
+ if (iterator == null) {
+ throw new IllegalArgumentException("MapIterator must not be null");
+ }
+ this.iterator = iterator;
+ }
+
+ /**
+ * Gets the iterator being decorated.
+ *
+ * @return the decorated iterator
+ */
+ protected MapIterator getMapIterator() {
+ return iterator;
+ }
+
+ //-----------------------------------------------------------------------
+ public boolean hasNext() {
+ return iterator.hasNext();
+ }
+
+ public Object next() {
+ return iterator.next();
+ }
+
+ public void remove() {
+ iterator.remove();
+ }
+
+ public Object getKey() {
+ return iterator.getKey();
+ }
+
+ public Object getValue() {
+ return iterator.getValue();
+ }
+
+ public Object setValue(Object obj) {
+ return iterator.setValue(obj);
+ }
+
+ public Map.Entry asMapEntry() {
+ return iterator.asMapEntry();
+ }
+
+}
diff --git a/src/java/org/apache/commons/collections/iterators/FilterIterator.java b/src/java/org/apache/commons/collections/iterators/FilterIterator.java
index 05b631d40..ce8d9c1dc 100644
--- a/src/java/org/apache/commons/collections/iterators/FilterIterator.java
+++ b/src/java/org/apache/commons/collections/iterators/FilterIterator.java
@@ -1,5 +1,5 @@
/*
- * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/iterators/FilterIterator.java,v 1.5 2003/09/29 22:02:33 scolebourne Exp $
+ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/iterators/FilterIterator.java,v 1.6 2003/11/02 16:29:12 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
@@ -59,33 +59,33 @@ package org.apache.commons.collections.iterators;
import java.util.Iterator;
import java.util.NoSuchElementException;
+
import org.apache.commons.collections.Predicate;
/**
- * A Proxy {@link Iterator Iterator} which takes a {@link Predicate Predicate} instance to filter
- * out objects from an underlying {@link Iterator Iterator} instance.
- * Only objects for which the
- * specified Predicate
evaluates to true
are
- * returned.
+ * Decorates an iterator such that only elements matching a predicate filter
+ * are returned.
*
* @since Commons Collections 1.0
- * @version $Revision: 1.5 $ $Date: 2003/09/29 22:02:33 $
+ * @version $Revision: 1.6 $ $Date: 2003/11/02 16:29:12 $
*
- * @author James Strachan
+ * @author James Strachan
* @author Jan Sorensen
* @author Ralph Wagner
+ * @author Stephen Colebourne
*/
-public class FilterIterator extends ProxyIterator {
-
- /** Holds value of property predicate. */
+public class FilterIterator implements Iterator {
+
+ /** The iterator being used */
+ private Iterator iterator;
+ /** The predicate being used */
private Predicate predicate;
-
+ /** The next object in the iteration */
private Object nextObject;
+ /** Whether the next object has been calculated yet */
private boolean nextObjectSet = false;
-
-
- //-------------------------------------------------------------------------
+ //-----------------------------------------------------------------------
/**
* Constructs a new FilterIterator
that will not function
* until {@link #setIterator(Iterator) setIterator} is invoked.
@@ -93,7 +93,7 @@ public class FilterIterator extends ProxyIterator {
public FilterIterator() {
super();
}
-
+
/**
* Constructs a new FilterIterator
that will not function
* until {@link #setPredicate(Predicate) setPredicate} is invoked.
@@ -101,7 +101,8 @@ public class FilterIterator extends ProxyIterator {
* @param iterator the iterator to use
*/
public FilterIterator(Iterator iterator) {
- super(iterator);
+ super();
+ this.iterator = iterator;
}
/**
@@ -112,21 +113,20 @@ public class FilterIterator extends ProxyIterator {
* @param predicate the predicate to use
*/
public FilterIterator(Iterator iterator, Predicate predicate) {
- super(iterator);
+ super();
+ this.iterator = iterator;
this.predicate = predicate;
}
- // Iterator interface
- //-------------------------------------------------------------------------
-
+ //-----------------------------------------------------------------------
/**
- * Returns true if the underlying iterator contains an object that
- * matches the predicate.
+ * Returns true if the underlying iterator contains an object that
+ * matches the predicate.
*
- * @return true if there is another object that matches the predicate
+ * @return true if there is another object that matches the predicate
*/
public boolean hasNext() {
- if ( nextObjectSet ) {
+ if (nextObjectSet) {
return true;
} else {
return setNextObject();
@@ -134,14 +134,14 @@ public class FilterIterator extends ProxyIterator {
}
/**
- * Returns the next object that matches the predicate.
+ * Returns the next object that matches the predicate.
*
- * @return the next object which matches the given predicate
- * @throws NoSuchElementException if there are no more elements that
- * match the predicate
+ * @return the next object which matches the given predicate
+ * @throws NoSuchElementException if there are no more elements that
+ * match the predicate
*/
public Object next() {
- if ( !nextObjectSet ) {
+ if (!nextObjectSet) {
if (!setNextObject()) {
throw new NoSuchElementException();
}
@@ -165,35 +165,57 @@ public class FilterIterator extends ProxyIterator {
if (nextObjectSet) {
throw new IllegalStateException("remove() cannot be called");
}
- getIterator().remove();
+ iterator.remove();
}
-
- // Properties
- //-------------------------------------------------------------------------
- /** Getter for property predicate.
- * @return Value of property predicate.
+ //-----------------------------------------------------------------------
+ /**
+ * Gets the iterator this iterator is using.
+ *
+ * @return the iterator.
+ */
+ public Iterator getIterator() {
+ return iterator;
+ }
+
+ /**
+ * Sets the iterator for this iterator to use.
+ * If iteration has started, this effectively resets the iterator.
+ *
+ * @param iterator the iterator to use
+ */
+ public void setIterator(Iterator iterator) {
+ this.iterator = iterator;
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Gets the predicate this iterator is using.
+ *
+ * @return the predicate.
*/
public Predicate getPredicate() {
return predicate;
}
- /** Setter for property predicate.
- * @param predicate New value of property predicate.
+
+ /**
+ * Sets the predicate this the iterator to use.
+ *
+ * @param predicate the transformer to use
*/
public void setPredicate(Predicate predicate) {
this.predicate = predicate;
}
+ //-----------------------------------------------------------------------
/**
* Set nextObject to the next object. If there are no more
* objects then return false. Otherwise, return true.
*/
private boolean setNextObject() {
- Iterator iterator = getIterator();
- Predicate predicate = getPredicate();
- while ( iterator.hasNext() ) {
+ while (iterator.hasNext()) {
Object object = iterator.next();
- if ( predicate.evaluate( object ) ) {
+ if (predicate.evaluate(object)) {
nextObject = object;
nextObjectSet = true;
return true;
diff --git a/src/java/org/apache/commons/collections/iterators/FilterListIterator.java b/src/java/org/apache/commons/collections/iterators/FilterListIterator.java
index 0086317c9..3f5854bb9 100644
--- a/src/java/org/apache/commons/collections/iterators/FilterListIterator.java
+++ b/src/java/org/apache/commons/collections/iterators/FilterListIterator.java
@@ -1,5 +1,5 @@
/*
- * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/iterators/FilterListIterator.java,v 1.4 2003/09/29 22:02:33 scolebourne Exp $
+ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/iterators/FilterListIterator.java,v 1.5 2003/11/02 16:29:12 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
@@ -59,6 +59,7 @@ package org.apache.commons.collections.iterators;
import java.util.ListIterator;
import java.util.NoSuchElementException;
+
import org.apache.commons.collections.Predicate;
/**
@@ -70,15 +71,48 @@ import org.apache.commons.collections.Predicate;
* returned by the iterator.
*
* @since Commons Collections 2.0
- * @version $Revision: 1.4 $ $Date: 2003/09/29 22:02:33 $
+ * @version $Revision: 1.5 $ $Date: 2003/11/02 16:29:12 $
*
* @author Rodney Waldhoff
*/
-public class FilterListIterator extends ProxyListIterator {
+public class FilterListIterator implements ListIterator {
- // Constructors
- //-------------------------------------------------------------------------
+ /** The iterator being used */
+ private ListIterator iterator;
+ /** The predicate being used */
+ private Predicate predicate;
+
+ /**
+ * The value of the next (matching) object, when
+ * {@link #nextObjectSet} is true.
+ */
+ private Object nextObject;
+
+ /**
+ * Whether or not the {@link #nextObject} has been set
+ * (possibly to null
).
+ */
+ private boolean nextObjectSet = false;
+
+ /**
+ * The value of the previous (matching) object, when
+ * {@link #previousObjectSet} is true.
+ */
+ private Object previousObject;
+
+ /**
+ * Whether or not the {@link #previousObject} has been set
+ * (possibly to null
).
+ */
+ private boolean previousObjectSet = false;
+
+ /**
+ * The index of the element that would be returned by {@link #next}.
+ */
+ private int nextIndex = 0;
+
+ //-----------------------------------------------------------------------
/**
* Constructs a new FilterListIterator
that will not
* function until
@@ -96,7 +130,8 @@ public class FilterListIterator extends ProxyListIterator {
* @param iterator the iterator to use
*/
public FilterListIterator(ListIterator iterator ) {
- super(iterator);
+ super();
+ this.iterator = iterator;
}
/**
@@ -106,7 +141,8 @@ public class FilterListIterator extends ProxyListIterator {
* @param predicate the predicate to use
*/
public FilterListIterator(ListIterator iterator, Predicate predicate) {
- super(iterator);
+ super();
+ this.iterator = iterator;
this.predicate = predicate;
}
@@ -123,9 +159,7 @@ public class FilterListIterator extends ProxyListIterator {
this.predicate = predicate;
}
- // ListIterator interface
- //-------------------------------------------------------------------------
-
+ //-----------------------------------------------------------------------
/** Not supported. */
public void add(Object o) {
throw new UnsupportedOperationException("FilterListIterator.add(Object) is not supported.");
@@ -189,36 +223,52 @@ public class FilterListIterator extends ProxyListIterator {
throw new UnsupportedOperationException("FilterListIterator.set(Object) is not supported.");
}
- // Properties
- //-------------------------------------------------------------------------
+ //-----------------------------------------------------------------------
+ /**
+ * Gets the iterator this iterator is using.
+ *
+ * @return the iterator.
+ */
+ public ListIterator getListIterator() {
+ return iterator;
+ }
/**
- * Getter for the predicate property.
- * @return value of the predicate property.
+ * Sets the iterator for this iterator to use.
+ * If iteration has started, this effectively resets the iterator.
+ *
+ * @param iterator the iterator to use
+ */
+ public void setListIterator(ListIterator iterator) {
+ this.iterator = iterator;
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Gets the predicate this iterator is using.
+ *
+ * @return the predicate.
*/
public Predicate getPredicate() {
return predicate;
}
+
/**
- * Setter for the predicate property.
- * @param predicate new value for the predicate property.
+ * Sets the predicate this the iterator to use.
+ *
+ * @param predicate the transformer to use
*/
public void setPredicate(Predicate predicate) {
this.predicate = predicate;
}
- // Private Methods
- //-------------------------------------------------------------------------
-
+ //-----------------------------------------------------------------------
private void clearNextObject() {
nextObject = null;
nextObjectSet = false;
}
private boolean setNextObject() {
- ListIterator iterator = getListIterator();
- Predicate predicate = getPredicate();
-
// if previousObjectSet,
// then we've walked back one step in the
// underlying list (due to a hasPrevious() call)
@@ -249,9 +299,6 @@ public class FilterListIterator extends ProxyListIterator {
}
private boolean setPreviousObject() {
- ListIterator iterator = getListIterator();
- Predicate predicate = getPredicate();
-
// if nextObjectSet,
// then we've walked back one step in the
// underlying list (due to a hasNext() call)
@@ -276,38 +323,4 @@ public class FilterListIterator extends ProxyListIterator {
return false;
}
- // Attributes
- //-------------------------------------------------------------------------
-
- /** Holds value of property "predicate". */
- private Predicate predicate;
-
- /**
- * The value of the next (matching) object, when
- * {@link #nextObjectSet} is true.
- */
- private Object nextObject;
-
- /**
- * Whether or not the {@link #nextObject} has been set
- * (possibly to null
).
- */
- private boolean nextObjectSet = false;
-
- /**
- * The value of the previous (matching) object, when
- * {@link #previousObjectSet} is true.
- */
- private Object previousObject;
-
- /**
- * Whether or not the {@link #previousObject} has been set
- * (possibly to null
).
- */
- private boolean previousObjectSet = false;
-
- /**
- * The index of the element that would be returned by {@link #next}.
- */
- private int nextIndex = 0;
}
diff --git a/src/java/org/apache/commons/collections/iterators/ProxyIterator.java b/src/java/org/apache/commons/collections/iterators/ProxyIterator.java
index ea5a47991..0179a4edb 100644
--- a/src/java/org/apache/commons/collections/iterators/ProxyIterator.java
+++ b/src/java/org/apache/commons/collections/iterators/ProxyIterator.java
@@ -1,5 +1,5 @@
/*
- * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/iterators/ProxyIterator.java,v 1.5 2003/09/29 22:02:33 scolebourne Exp $
+ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/iterators/ProxyIterator.java,v 1.6 2003/11/02 16:29:12 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
@@ -62,11 +62,11 @@ import java.util.Iterator;
/**
* A Proxy {@link Iterator Iterator} which delegates its methods to a proxy instance.
*
- * @see ProxyListIterator
+ * @deprecated Use AbstractIteratorDecorator
* @since Commons Collections 1.0
- * @version $Revision: 1.5 $ $Date: 2003/09/29 22:02:33 $
+ * @version $Revision: 1.6 $ $Date: 2003/11/02 16:29:12 $
*
- * @author James Strachan
+ * @author James Strachan
*/
public class ProxyIterator implements Iterator {
diff --git a/src/java/org/apache/commons/collections/iterators/ProxyListIterator.java b/src/java/org/apache/commons/collections/iterators/ProxyListIterator.java
index 68becf341..c8e56c986 100644
--- a/src/java/org/apache/commons/collections/iterators/ProxyListIterator.java
+++ b/src/java/org/apache/commons/collections/iterators/ProxyListIterator.java
@@ -1,5 +1,5 @@
/*
- * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/iterators/ProxyListIterator.java,v 1.5 2003/09/29 22:02:33 scolebourne Exp $
+ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/iterators/ProxyListIterator.java,v 1.6 2003/11/02 16:29:12 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
@@ -63,9 +63,9 @@ import java.util.ListIterator;
* A proxy {@link ListIterator ListIterator} which delegates its
* methods to a proxy instance.
*
- * @see ProxyIterator
+ * @deprecated Use AbstractListIteratorDecorator
* @since Commons Collections 2.0
- * @version $Revision: 1.5 $ $Date: 2003/09/29 22:02:33 $
+ * @version $Revision: 1.6 $ $Date: 2003/11/02 16:29:12 $
*
* @author Rodney Waldhoff
*/
diff --git a/src/java/org/apache/commons/collections/iterators/TransformIterator.java b/src/java/org/apache/commons/collections/iterators/TransformIterator.java
index bc226d4f6..93ef2bf85 100644
--- a/src/java/org/apache/commons/collections/iterators/TransformIterator.java
+++ b/src/java/org/apache/commons/collections/iterators/TransformIterator.java
@@ -1,5 +1,5 @@
/*
- * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/iterators/TransformIterator.java,v 1.5 2003/09/29 22:02:33 scolebourne Exp $
+ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/iterators/TransformIterator.java,v 1.6 2003/11/02 16:29:12 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
@@ -58,24 +58,26 @@
package org.apache.commons.collections.iterators;
import java.util.Iterator;
+
import org.apache.commons.collections.Transformer;
/**
- * A Proxy {@link Iterator Iterator} which uses a {@link Transformer Transformer}
- * instance to transform the contents of the {@link Iterator Iterator} into
- * some other form.
+ * Decorates an iterator such that each element returned is transformed.
*
* @since Commons Collections 1.0
- * @version $Revision: 1.5 $ $Date: 2003/09/29 22:02:33 $
+ * @version $Revision: 1.6 $ $Date: 2003/11/02 16:29:12 $
*
- * @author James Strachan
+ * @author James Strachan
+ * @author Stephen Colebourne
*/
-public class TransformIterator extends ProxyIterator {
-
- /** Holds value of property transformer. */
+public class TransformIterator implements Iterator {
+
+ /** The iterator being used */
+ private Iterator iterator;
+ /** The transformer being used */
private Transformer transformer;
-
-
+
+ //-----------------------------------------------------------------------
/**
* Constructs a new TransformIterator
that will not function
* until the {@link #setIterator(Iterator) setIterator} method is
@@ -84,7 +86,7 @@ public class TransformIterator extends ProxyIterator {
public TransformIterator() {
super();
}
-
+
/**
* Constructs a new TransformIterator
that won't transform
* elements from the given iterator.
@@ -92,7 +94,8 @@ public class TransformIterator extends ProxyIterator {
* @param iterator the iterator to use
*/
public TransformIterator(Iterator iterator) {
- super(iterator);
+ super();
+ this.iterator = iterator;
}
/**
@@ -104,50 +107,83 @@ public class TransformIterator extends ProxyIterator {
* @param transformer the transformer to use
*/
public TransformIterator(Iterator iterator, Transformer transformer) {
- super(iterator);
+ super();
+ this.iterator = iterator;
this.transformer = transformer;
}
- // Iterator interface
- //-------------------------------------------------------------------------
- public Object next() {
- return transform( super.next() );
+ //-----------------------------------------------------------------------
+ public boolean hasNext() {
+ return iterator.hasNext();
}
- // Properties
- //-------------------------------------------------------------------------
- /**
- * Getter for property transformer.
+ /**
+ * Gets the next object from the iteration, transforming it using the
+ * current transformer. If the transformer is null, no transformation
+ * occurs and the object from the iterator is returned directly.
*
- * @return Value of property transformer.
+ * @return the next object
+ * @throws NoSuchElementException if there are no more elements
+ */
+ public Object next() {
+ return transform(iterator.next());
+ }
+
+ public void remove() {
+ iterator.remove();
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Gets the iterator this iterator is using.
+ *
+ * @return the iterator.
+ */
+ public Iterator getIterator() {
+ return iterator;
+ }
+
+ /**
+ * Sets the iterator for this iterator to use.
+ * If iteration has started, this effectively resets the iterator.
+ *
+ * @param iterator the iterator to use
+ */
+ public void setIterator(Iterator iterator) {
+ this.iterator = iterator;
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Gets the transformer this iterator is using.
+ *
+ * @return the transformer.
*/
public Transformer getTransformer() {
return transformer;
}
-
+
/**
- * Setter for property transformer.
+ * Sets the transformer this the iterator to use.
+ * A null transformer is a no-op transformer.
*
- * @param transformer New value of property transformer.
+ * @param transformer the transformer to use
*/
public void setTransformer(Transformer transformer) {
this.transformer = transformer;
}
-
- // Implementation methods
- //-------------------------------------------------------------------------
+ //-----------------------------------------------------------------------
/**
- * Transforms the given object using the transformer. If the
- * transformer is null, the original object is returned as-is.
+ * Transforms the given object using the transformer.
+ * If the transformer is null, the original object is returned as-is.
*
- * @param source the object to transform
- * @return the transformed object
+ * @param source the object to transform
+ * @return the transformed object
*/
- protected Object transform( Object source ) {
- Transformer transformer = getTransformer();
- if ( transformer != null ) {
- return transformer.transform( source );
+ protected Object transform(Object source) {
+ if (transformer != null) {
+ return transformer.transform(source);
}
return source;
}