diff --git a/src/java/org/apache/commons/collections/IteratorUtils.java b/src/java/org/apache/commons/collections/IteratorUtils.java index 75f7f8f19..2177ac8fa 100644 --- a/src/java/org/apache/commons/collections/IteratorUtils.java +++ b/src/java/org/apache/commons/collections/IteratorUtils.java @@ -1,5 +1,5 @@ /* - * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/IteratorUtils.java,v 1.14 2003/11/02 15:27:53 scolebourne Exp $ + * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/IteratorUtils.java,v 1.15 2003/11/08 18:43:12 scolebourne Exp $ * ==================================================================== * * The Apache Software License, Version 1.1 @@ -70,7 +70,6 @@ import java.util.List; import java.util.ListIterator; import java.util.Map; import java.util.NoSuchElementException; -import java.util.Map.Entry; import org.apache.commons.collections.iterators.ArrayIterator; import org.apache.commons.collections.iterators.ArrayListIterator; @@ -87,6 +86,7 @@ import org.apache.commons.collections.iterators.ObjectArrayListIterator; import org.apache.commons.collections.iterators.ResetableIterator; import org.apache.commons.collections.iterators.ResetableListIterator; import org.apache.commons.collections.iterators.ResetableMapIterator; +import org.apache.commons.collections.iterators.ResetableOrderedMapIterator; import org.apache.commons.collections.iterators.SingletonIterator; import org.apache.commons.collections.iterators.SingletonListIterator; import org.apache.commons.collections.iterators.TransformIterator; @@ -97,7 +97,7 @@ import org.apache.commons.collections.iterators.TransformIterator; * {@link org.apache.commons.collections.iterators} subpackage. * * @since Commons Collections 2.1 - * @version $Revision: 1.14 $ $Date: 2003/11/02 15:27:53 $ + * @version $Revision: 1.15 $ $Date: 2003/11/08 18:43:12 $ * * @author Stephen Colebourne * @author Phil Steitz @@ -118,6 +118,10 @@ public class IteratorUtils { * A map iterator over no elements */ public static final ResetableMapIterator EMPTY_MAP_ITERATOR = new EmptyMapIterator(); + /** + * A map iterator over no elements + */ + public static final ResetableOrderedMapIterator EMPTY_ORDERED_MAP_ITERATOR = new EmptyOrderedMapIterator(); /** * Prevents instantiation. @@ -164,6 +168,18 @@ public class IteratorUtils { return EMPTY_MAP_ITERATOR; } + /** + * Gets an empty ordered map iterator. + *
+ * This iterator is a valid map iterator object that will iterate + * over nothing. + * + * @return a list iterator over nothing + */ + public static ResetableOrderedMapIterator emptyOrderedMapIterator() { + return EMPTY_ORDERED_MAP_ITERATOR; + } + /** * Gets a singleton iterator. *
@@ -850,7 +866,7 @@ public class IteratorUtils { EmptyMapIterator() { super(); } - + public Object getKey() { throw new IllegalStateException("Iterator contains no elements"); } @@ -862,9 +878,24 @@ public class IteratorUtils { public Object setValue(Object value) { throw new IllegalStateException("Iterator contains no elements"); } + } + + //----------------------------------------------------------------------- + /** + * EmptyOrderedMapIterator class + */ + static class EmptyOrderedMapIterator extends EmptyMapIterator implements ResetableOrderedMapIterator { - public Entry asMapEntry() { - throw new IllegalStateException("Iterator contains no elements"); + EmptyOrderedMapIterator() { + super(); + } + + public boolean hasPrevious() { + return false; + } + + public Object previous() { + throw new NoSuchElementException("Iterator contains no elements"); } } diff --git a/src/java/org/apache/commons/collections/decorators/OrderedMap.java b/src/java/org/apache/commons/collections/decorators/OrderedMap.java index 7948c15f9..40524c534 100644 --- a/src/java/org/apache/commons/collections/decorators/OrderedMap.java +++ b/src/java/org/apache/commons/collections/decorators/OrderedMap.java @@ -1,5 +1,5 @@ /* - * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/decorators/Attic/OrderedMap.java,v 1.5 2003/11/04 23:36:23 scolebourne Exp $ + * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/decorators/Attic/OrderedMap.java,v 1.6 2003/11/08 18:43:12 scolebourne Exp $ * ==================================================================== * * The Apache Software License, Version 1.1 @@ -66,7 +66,7 @@ import java.util.List; import java.util.Map; import java.util.Set; -import org.apache.commons.collections.iterators.DefaultMapIterator; +import org.apache.commons.collections.iterators.EntrySetMapIterator; import org.apache.commons.collections.iterators.MapIterator; import org.apache.commons.collections.pairs.AbstractMapEntry; @@ -80,7 +80,7 @@ import org.apache.commons.collections.pairs.AbstractMapEntry; * original position in the iteration. * * @since Commons Collections 3.0 - * @version $Revision: 1.5 $ $Date: 2003/11/04 23:36:23 $ + * @version $Revision: 1.6 $ $Date: 2003/11/08 18:43:12 $ * * @author Henri Yandell * @author Stephen Colebourne @@ -146,7 +146,7 @@ public class OrderedMap extends AbstractMapDecorator implements Map { //----------------------------------------------------------------------- public MapIterator mapIterator() { - return new DefaultMapIterator(this); + return new EntrySetMapIterator(this); } public Set keySet() { diff --git a/src/java/org/apache/commons/collections/iterators/AbstractMapIteratorDecorator.java b/src/java/org/apache/commons/collections/iterators/AbstractMapIteratorDecorator.java index 9d7cb8767..ba02e5578 100644 --- a/src/java/org/apache/commons/collections/iterators/AbstractMapIteratorDecorator.java +++ b/src/java/org/apache/commons/collections/iterators/AbstractMapIteratorDecorator.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/AbstractMapIteratorDecorator.java,v 1.1 2003/11/02 16:29:12 scolebourne Exp $ + * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/iterators/AbstractMapIteratorDecorator.java,v 1.2 2003/11/08 18:43:12 scolebourne Exp $ * ==================================================================== * * The Apache Software License, Version 1.1 @@ -57,15 +57,13 @@ */ package org.apache.commons.collections.iterators; -import java.util.Map; - /** * Provides basic behaviour for decorating a map iterator with extra functionality. *
* 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 $
+ * @version $Revision: 1.2 $ $Date: 2003/11/08 18:43:12 $
*
* @author Stephen Colebourne
*/
@@ -123,8 +121,4 @@ public class AbstractMapIteratorDecorator implements MapIterator {
return iterator.setValue(obj);
}
- public Map.Entry asMapEntry() {
- return iterator.asMapEntry();
- }
-
}
diff --git a/src/java/org/apache/commons/collections/iterators/DefaultMapIterator.java b/src/java/org/apache/commons/collections/iterators/EntrySetMapIterator.java
similarity index 86%
rename from src/java/org/apache/commons/collections/iterators/DefaultMapIterator.java
rename to src/java/org/apache/commons/collections/iterators/EntrySetMapIterator.java
index 0263859e9..e63864775 100644
--- a/src/java/org/apache/commons/collections/iterators/DefaultMapIterator.java
+++ b/src/java/org/apache/commons/collections/iterators/EntrySetMapIterator.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/Attic/DefaultMapIterator.java,v 1.1 2003/11/02 23:40:53 scolebourne Exp $
+ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/iterators/EntrySetMapIterator.java,v 1.1 2003/11/08 18:43:13 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
@@ -60,10 +60,9 @@ package org.apache.commons.collections.iterators;
import java.util.Iterator;
import java.util.Map;
-import org.apache.commons.collections.pairs.TiedMapEntry;
-
/**
* Implements a MapIterator
using a Map entrySet.
+ * Reverse iteration is not supported.
*
* MapIterator it = map.mapIterator(); * while (it.hasNext()) { @@ -74,11 +73,11 @@ import org.apache.commons.collections.pairs.TiedMapEntry; ** * @since Commons Collections 3.0 - * @version $Revision: 1.1 $ $Date: 2003/11/02 23:40:53 $ + * @version $Revision: 1.1 $ $Date: 2003/11/08 18:43:13 $ * * @author Stephen Colebourne */ -public class DefaultMapIterator implements ResetableMapIterator { +public class EntrySetMapIterator implements MapIterator, ResetableMapIterator { private final Map map; private Iterator iterator; @@ -90,7 +89,7 @@ public class DefaultMapIterator implements ResetableMapIterator { * * @param map the map to iterate over */ - public DefaultMapIterator(Map map) { + public EntrySetMapIterator(Map map) { super(); this.map = map; this.iterator = map.entrySet().iterator(); @@ -118,6 +117,7 @@ public class DefaultMapIterator implements ResetableMapIterator { return last.getKey(); } + //----------------------------------------------------------------------- /** * Removes the last returned key from the underlying
Map
.
*
@@ -184,24 +184,6 @@ public class DefaultMapIterator implements ResetableMapIterator {
}
//-----------------------------------------------------------------------
- /**
- * Gets the last returned key-value pair from the underlying Map
- * as a Map Entry instance.
- *
- * The returned entry will not change when next
is called.
- * Changes made to the entry via setValue
will change the map.
- * If you call setValue after next on the iterator, a ConcurrentModificationException
- * may occur.
- *
- * @return the last return key-value pair as an independent Map Entry
- * @throws IllegalStateException if next()
has not yet been called
- * @throws IllegalStateException if remove()
has been called since the
- * last call to next()
- */
- public Map.Entry asMapEntry() {
- return new TiedMapEntry(map, getKey());
- }
-
/**
* Resets the state of the iterator.
*/
diff --git a/src/java/org/apache/commons/collections/iterators/MapIterator.java b/src/java/org/apache/commons/collections/iterators/MapIterator.java
index bf0ec1220..c5aa84aeb 100644
--- a/src/java/org/apache/commons/collections/iterators/MapIterator.java
+++ b/src/java/org/apache/commons/collections/iterators/MapIterator.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/Attic/MapIterator.java,v 1.1 2003/11/02 15:27:54 scolebourne Exp $
+ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/iterators/Attic/MapIterator.java,v 1.2 2003/11/08 18:43:13 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
@@ -58,7 +58,6 @@
package org.apache.commons.collections.iterators;
import java.util.Iterator;
-import java.util.Map;
/**
* Defines an iterator that operates over a Map
.
@@ -83,7 +82,7 @@ import java.util.Map;
*
*
* @since Commons Collections 3.0
- * @version $Revision: 1.1 $ $Date: 2003/11/02 15:27:54 $
+ * @version $Revision: 1.2 $ $Date: 2003/11/08 18:43:13 $
*
* @author Stephen Colebourne
*/
@@ -123,21 +122,6 @@ public interface MapIterator extends Iterator {
*/
Object getValue();
- //-----------------------------------------------------------------------
- /**
- * Gets the last returned key-value pair from the underlying Map
- * as a Map Entry instance.
- *
- * The returned entry must not change when next
is called.
- * Changes made to the entry via setValue
must change the map.
- *
- * @return the last return key-value pair as an independent Map Entry
- * @throws IllegalStateException if next()
has not yet been called
- * @throws IllegalStateException if remove()
has been called since the
- * last call to next()
- */
- Map.Entry asMapEntry();
-
//-----------------------------------------------------------------------
/**
* Removes the last returned key from the underlying Map
(optional operation).
diff --git a/src/java/org/apache/commons/collections/iterators/OrderedMapIterator.java b/src/java/org/apache/commons/collections/iterators/OrderedMapIterator.java
new file mode 100644
index 000000000..2100a56b8
--- /dev/null
+++ b/src/java/org/apache/commons/collections/iterators/OrderedMapIterator.java
@@ -0,0 +1,87 @@
+/*
+ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/iterators/Attic/OrderedMapIterator.java,v 1.1 2003/11/08 18:43:12 scolebourne Exp $
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2001-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
+ * Map
.
+ *
+ * This iterator allows both forward and reverse iteration through the map.
+ *
+ * @since Commons Collections 3.0
+ * @version $Revision: 1.1 $ $Date: 2003/11/08 18:43:12 $
+ *
+ * @author Stephen Colebourne
+ */
+public interface OrderedMapIterator extends MapIterator {
+
+ /**
+ * Checks to see if there is a previous entry that can be iterated to.
+ *
+ * @return true
if the iterator has a previous element
+ */
+ boolean hasPrevious();
+
+ /**
+ * Gets the previous key from the Map
.
+ *
+ * @return the previous key in the iteration
+ * @throws NoSuchElementException if the iteration is finished
+ */
+ Object previous();
+
+}
diff --git a/src/java/org/apache/commons/collections/iterators/ResetableOrderedMapIterator.java b/src/java/org/apache/commons/collections/iterators/ResetableOrderedMapIterator.java
new file mode 100644
index 000000000..061ae82ad
--- /dev/null
+++ b/src/java/org/apache/commons/collections/iterators/ResetableOrderedMapIterator.java
@@ -0,0 +1,77 @@
+/*
+ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/iterators/Attic/ResetableOrderedMapIterator.java,v 1.1 2003/11/08 18:43:13 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
+ *