You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by sc...@apache.org on 2003/11/02 17:29:12 UTC
cvs commit: jakarta-commons/collections/src/java/org/apache/commons/collections/iterators AbstractIteratorDecorator.java AbstractMapIteratorDecorator.java AbstractListIteratorDecorator.java FilterIterator.java ProxyListIterator.java FilterListIterator.java TransformIterator.java ProxyIterator.java
scolebourne 2003/11/02 08:29:12
Modified: collections/src/java/org/apache/commons/collections/iterators
FilterIterator.java ProxyListIterator.java
FilterListIterator.java TransformIterator.java
ProxyIterator.java
Added: collections/src/java/org/apache/commons/collections/iterators
AbstractIteratorDecorator.java
AbstractMapIteratorDecorator.java
AbstractListIteratorDecorator.java
Log:
Refactor ProxyIterators to AbstractDecorators
Revision Changes Path
1.6 +64 -42 jakarta-commons/collections/src/java/org/apache/commons/collections/iterators/FilterIterator.java
Index: FilterIterator.java
===================================================================
RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/iterators/FilterIterator.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- FilterIterator.java 29 Sep 2003 22:02:33 -0000 1.5
+++ FilterIterator.java 2 Nov 2003 16:29:12 -0000 1.6
@@ -59,33 +59,33 @@
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 <code>Predicate</code> evaluates to <code>true</code> are
- * returned.
+ * Decorates an iterator such that only elements matching a predicate filter
+ * are returned.
*
* @since Commons Collections 1.0
* @version $Revision$ $Date$
*
- * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
+ * @author James Strachan
* @author Jan Sorensen
* @author Ralph Wagner
+ * @author Stephen Colebourne
*/
-public class FilterIterator extends ProxyIterator {
-
- /** Holds value of property predicate. */
- private Predicate 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 <code>FilterIterator</code> that will not function
* until {@link #setIterator(Iterator) setIterator} is invoked.
@@ -93,7 +93,7 @@
public FilterIterator() {
super();
}
-
+
/**
* Constructs a new <code>FilterIterator</code> that will not function
* until {@link #setPredicate(Predicate) setPredicate} is invoked.
@@ -101,7 +101,8 @@
* @param iterator the iterator to use
*/
public FilterIterator(Iterator iterator) {
- super(iterator);
+ super();
+ this.iterator = iterator;
}
/**
@@ -112,21 +113,20 @@
* @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 @@
}
/**
- * 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 @@
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;
1.6 +3 -3 jakarta-commons/collections/src/java/org/apache/commons/collections/iterators/ProxyListIterator.java
Index: ProxyListIterator.java
===================================================================
RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/iterators/ProxyListIterator.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- ProxyListIterator.java 29 Sep 2003 22:02:33 -0000 1.5
+++ ProxyListIterator.java 2 Nov 2003 16:29:12 -0000 1.6
@@ -63,7 +63,7 @@
* 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$ $Date$
*
1.5 +72 -59 jakarta-commons/collections/src/java/org/apache/commons/collections/iterators/FilterListIterator.java
Index: FilterListIterator.java
===================================================================
RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/iterators/FilterListIterator.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- FilterListIterator.java 29 Sep 2003 22:02:33 -0000 1.4
+++ FilterListIterator.java 2 Nov 2003 16:29:12 -0000 1.5
@@ -59,6 +59,7 @@
import java.util.ListIterator;
import java.util.NoSuchElementException;
+
import org.apache.commons.collections.Predicate;
/**
@@ -74,11 +75,44 @@
*
* @author Rodney Waldhoff
*/
-public class FilterListIterator extends ProxyListIterator {
+public class FilterListIterator implements ListIterator {
+
+ /** 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 <code>null</code>).
+ */
+ 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 <code>null</code>).
+ */
+ private boolean previousObjectSet = false;
- // Constructors
- //-------------------------------------------------------------------------
+ /**
+ * The index of the element that would be returned by {@link #next}.
+ */
+ private int nextIndex = 0;
+ //-----------------------------------------------------------------------
/**
* Constructs a new <code>FilterListIterator</code> that will not
* function until
@@ -96,7 +130,8 @@
* @param iterator the iterator to use
*/
public FilterListIterator(ListIterator iterator ) {
- super(iterator);
+ super();
+ this.iterator = iterator;
}
/**
@@ -106,7 +141,8 @@
* @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 @@
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 @@
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;
+ }
+
+ /**
+ * 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;
+ }
+ //-----------------------------------------------------------------------
/**
- * Getter for the predicate property.
- * @return value of the predicate property.
+ * 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 @@
}
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 @@
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 <code>null</code>).
- */
- 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 <code>null</code>).
- */
- private boolean previousObjectSet = false;
-
- /**
- * The index of the element that would be returned by {@link #next}.
- */
- private int nextIndex = 0;
}
1.6 +71 -35 jakarta-commons/collections/src/java/org/apache/commons/collections/iterators/TransformIterator.java
Index: TransformIterator.java
===================================================================
RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/iterators/TransformIterator.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- TransformIterator.java 29 Sep 2003 22:02:33 -0000 1.5
+++ TransformIterator.java 2 Nov 2003 16:29:12 -0000 1.6
@@ -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$ $Date$
*
- * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
+ * @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 <code>TransformIterator</code> that will not function
* until the {@link #setIterator(Iterator) setIterator} method is
@@ -84,7 +86,7 @@
public TransformIterator() {
super();
}
-
+
/**
* Constructs a new <code>TransformIterator</code> that won't transform
* elements from the given iterator.
@@ -92,7 +94,8 @@
* @param iterator the iterator to use
*/
public TransformIterator(Iterator iterator) {
- super(iterator);
+ super();
+ this.iterator = iterator;
}
/**
@@ -104,50 +107,83 @@
* @param transformer the transformer to use
*/
public TransformIterator(Iterator iterator, Transformer transformer) {
- super(iterator);
+ super();
+ this.iterator = iterator;
this.transformer = transformer;
}
- // Iterator interface
- //-------------------------------------------------------------------------
+ //-----------------------------------------------------------------------
+ public boolean hasNext() {
+ return iterator.hasNext();
+ }
+
+ /**
+ * 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 the next object
+ * @throws NoSuchElementException if there are no more elements
+ */
public Object next() {
- return transform( super.next() );
+ return transform(iterator.next());
+ }
+
+ public void remove() {
+ iterator.remove();
}
- // Properties
- //-------------------------------------------------------------------------
+ //-----------------------------------------------------------------------
/**
- * Getter for property transformer.
+ * Gets the iterator this iterator is using.
*
- * @return Value of property transformer.
+ * @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;
}
1.6 +4 -4 jakarta-commons/collections/src/java/org/apache/commons/collections/iterators/ProxyIterator.java
Index: ProxyIterator.java
===================================================================
RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/iterators/ProxyIterator.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- ProxyIterator.java 29 Sep 2003 22:02:33 -0000 1.5
+++ ProxyIterator.java 2 Nov 2003 16:29:12 -0000 1.6
@@ -62,11 +62,11 @@
/**
* 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$ $Date$
*
- * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
+ * @author James Strachan
*/
public class ProxyIterator implements Iterator {
1.1 jakarta-commons/collections/src/java/org/apache/commons/collections/iterators/AbstractIteratorDecorator.java
Index: AbstractIteratorDecorator.java
===================================================================
/*
* $Header: /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
* <http://www.apache.org/>.
*
*/
package org.apache.commons.collections.iterators;
import java.util.Iterator;
/**
* Provides basic behaviour for decorating an iterator with extra functionality.
* <p>
* 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();
}
}
1.1 jakarta-commons/collections/src/java/org/apache/commons/collections/iterators/AbstractMapIteratorDecorator.java
Index: AbstractMapIteratorDecorator.java
===================================================================
/*
* $Header: /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
* <http://www.apache.org/>.
*
*/
package org.apache.commons.collections.iterators;
import java.util.Map;
/**
* Provides basic behaviour for decorating a map iterator with extra functionality.
* <p>
* 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();
}
}
1.1 jakarta-commons/collections/src/java/org/apache/commons/collections/iterators/AbstractListIteratorDecorator.java
Index: AbstractListIteratorDecorator.java
===================================================================
/*
* $Header: /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
* <http://www.apache.org/>.
*
*/
package org.apache.commons.collections.iterators;
import java.util.ListIterator;
/**
* Provides basic behaviour for decorating a list iterator with extra functionality.
* <p>
* 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);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org