tiles-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From apetre...@apache.org
Subject svn commit: r937811 - in /tiles/sandbox/trunk/tiles-request: tiles-request-api/src/main/java/org/apache/tiles/request/collection/ tiles-request-api/src/test/java/org/apache/tiles/request/collection/ tiles-request-servlet/src/main/java/org/apache/tiles/...
Date Sun, 25 Apr 2010 15:12:47 GMT
Author: apetrelli
Date: Sun Apr 25 15:12:47 2010
New Revision: 937811

URL: http://svn.apache.org/viewvc?rev=937811&view=rev
Log:
TILESSB-31
Refactoring to reduce code. Added more tests.

Added:
    tiles/sandbox/trunk/tiles-request/tiles-request-api/src/main/java/org/apache/tiles/request/collection/ReadOnlyEnumerationMap.java
      - copied, changed from r937783, tiles/sandbox/trunk/tiles-request/tiles-request-api/src/main/java/org/apache/tiles/request/collection/ParameterMap.java
    tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/ReadOnlyEnumerationMapEntrySetTest.java
      - copied, changed from r937783, tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/ParameterMapEntrySetTest.java
    tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/ReadOnlyEnumerationMapTest.java
      - copied, changed from r937783, tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/ParameterMapTest.java
    tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/ReadOnlyEnumerationMapValuesCollectionTest.java
      - copied, changed from r937783, tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/ParameterMapValuesCollectionTest.java
    tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/ScopeMapEntrySetTest.java   (with props)
    tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/ScopeMapTest.java   (with props)
Removed:
    tiles/sandbox/trunk/tiles-request/tiles-request-api/src/main/java/org/apache/tiles/request/collection/ParameterMap.java
    tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/ParameterMapEntrySetTest.java
    tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/ParameterMapTest.java
    tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/ParameterMapValuesCollectionTest.java
Modified:
    tiles/sandbox/trunk/tiles-request/tiles-request-api/src/main/java/org/apache/tiles/request/collection/AddableParameterMap.java
    tiles/sandbox/trunk/tiles-request/tiles-request-api/src/main/java/org/apache/tiles/request/collection/ScopeMap.java
    tiles/sandbox/trunk/tiles-request/tiles-request-servlet/src/main/java/org/apache/tiles/request/servlet/ServletApplicationContext.java
    tiles/sandbox/trunk/tiles-request/tiles-request-servlet/src/main/java/org/apache/tiles/request/servlet/ServletRequest.java

Modified: tiles/sandbox/trunk/tiles-request/tiles-request-api/src/main/java/org/apache/tiles/request/collection/AddableParameterMap.java
URL: http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles-request/tiles-request-api/src/main/java/org/apache/tiles/request/collection/AddableParameterMap.java?rev=937811&r1=937810&r2=937811&view=diff
==============================================================================
--- tiles/sandbox/trunk/tiles-request/tiles-request-api/src/main/java/org/apache/tiles/request/collection/AddableParameterMap.java (original)
+++ tiles/sandbox/trunk/tiles-request/tiles-request-api/src/main/java/org/apache/tiles/request/collection/AddableParameterMap.java Sun Apr 25 15:12:47 2010
@@ -33,7 +33,7 @@ import org.apache.tiles.request.collecti
  * @version $Rev$ $Date$
  */
 
-public class AddableParameterMap extends ParameterMap {
+public class AddableParameterMap extends ReadOnlyEnumerationMap<String> {
 
     private EnumeratedValuesExtractor request;
 
@@ -51,7 +51,7 @@ public class AddableParameterMap extends
 
     /** {@inheritDoc} */
     public Set<Map.Entry<String, String>> entrySet() {
-        return new ParameterEntrySet();
+        return new AddableParameterEntrySet();
     }
 
     /** {@inheritDoc} */
@@ -71,7 +71,7 @@ public class AddableParameterMap extends
     }
 
 
-    private class ParameterEntrySet extends ParameterMap.ParameterEntrySet {
+    private class AddableParameterEntrySet extends ReadOnlyEnumerationMap<String>.ReadOnlyEnumerationMapEntrySet {
 
         @Override
         public boolean add(java.util.Map.Entry<String, String> e) {

Copied: tiles/sandbox/trunk/tiles-request/tiles-request-api/src/main/java/org/apache/tiles/request/collection/ReadOnlyEnumerationMap.java (from r937783, tiles/sandbox/trunk/tiles-request/tiles-request-api/src/main/java/org/apache/tiles/request/collection/ParameterMap.java)
URL: http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles-request/tiles-request-api/src/main/java/org/apache/tiles/request/collection/ReadOnlyEnumerationMap.java?p2=tiles/sandbox/trunk/tiles-request/tiles-request-api/src/main/java/org/apache/tiles/request/collection/ReadOnlyEnumerationMap.java&p1=tiles/sandbox/trunk/tiles-request/tiles-request-api/src/main/java/org/apache/tiles/request/collection/ParameterMap.java&r1=937783&r2=937811&rev=937811&view=diff
==============================================================================
--- tiles/sandbox/trunk/tiles-request/tiles-request-api/src/main/java/org/apache/tiles/request/collection/ParameterMap.java (original)
+++ tiles/sandbox/trunk/tiles-request/tiles-request-api/src/main/java/org/apache/tiles/request/collection/ReadOnlyEnumerationMap.java Sun Apr 25 15:12:47 2010
@@ -25,6 +25,7 @@ import static org.apache.tiles.request.u
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Enumeration;
+import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
@@ -40,7 +41,9 @@ import org.apache.tiles.request.util.Map
  * @version $Rev$ $Date$
  */
 
-public class ParameterMap extends AbstractEnumerationMap<String> {
+public class ReadOnlyEnumerationMap<V> implements Map<String, V> {
+
+    protected HasKeys<V> request;
 
     /**
      * Constructor.
@@ -49,8 +52,8 @@ public class ParameterMap extends Abstra
      * @param response The response object to use.
      * @since 2.2.0
      */
-    public ParameterMap(HasKeys<String> request) {
-        super(request);
+    public ReadOnlyEnumerationMap(HasKeys<V> request) {
+        this.request = request;
     }
 
     /** {@inheritDoc} */
@@ -66,8 +69,9 @@ public class ParameterMap extends Abstra
 
 
     /** {@inheritDoc} */
+    @SuppressWarnings("unchecked")
     public boolean containsValue(Object value) {
-        String realValue = (String) value;
+        V realValue = (V) value;
         for (Enumeration<String> keysIt = request.getKeys(); keysIt.hasMoreElements(); ) {
             if (realValue.equals(request.getValue(keysIt.nextElement()))) {
                 return true;
@@ -78,13 +82,13 @@ public class ParameterMap extends Abstra
 
 
     /** {@inheritDoc} */
-    public Set<Map.Entry<String, String>> entrySet() {
-        return new ParameterEntrySet();
+    public Set<Map.Entry<String, V>> entrySet() {
+        return new ReadOnlyEnumerationMapEntrySet();
     }
 
 
     /** {@inheritDoc} */
-    public String get(Object key) {
+    public V get(Object key) {
         return (request.getValue(key(key)));
     }
 
@@ -102,19 +106,19 @@ public class ParameterMap extends Abstra
 
 
     /** {@inheritDoc} */
-    public String put(String key, String value) {
+    public V put(String key, V value) {
         throw new UnsupportedOperationException();
     }
 
 
     /** {@inheritDoc} */
-    public void putAll(Map<? extends String, ? extends String> map) {
+    public void putAll(Map<? extends String, ? extends V> map) {
         throw new UnsupportedOperationException();
     }
 
 
     /** {@inheritDoc} */
-    public String remove(Object key) {
+    public V remove(Object key) {
         throw new UnsupportedOperationException();
     }
 
@@ -126,21 +130,57 @@ public class ParameterMap extends Abstra
 
 
     /** {@inheritDoc} */
-    public Collection<String> values() {
-        return new ParameterMapValuesCollection();
+    public Collection<V> values() {
+        return new ReadOnlyEnumerationMapValuesCollection();
     }
 
 
-    class ParameterEntrySet implements Set<Map.Entry<String, String>> {
+    /** {@inheritDoc} */
+    @SuppressWarnings("unchecked")
+    @Override
+    public boolean equals(Object o) {
+        HasKeys<V> otherRequest = ((AbstractEnumerationMap<V>) o).request;
+        boolean retValue = true;
+        Set<String> otherKeys = new HashSet<String>();
+        for (Enumeration<String> attribs = otherRequest.getKeys(); attribs
+                .hasMoreElements();) {
+            otherKeys.add(attribs.nextElement());
+        }
+        for (Enumeration<String> attribs = request.getKeys(); attribs
+                .hasMoreElements()
+                && retValue;) {
+            String parameterName = attribs.nextElement();
+            retValue = request.getValue(parameterName).equals(
+                    otherRequest.getValue(parameterName));
+            otherKeys.remove(parameterName);
+        }
+
+        return retValue && otherKeys.isEmpty();
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public int hashCode() {
+        int retValue = 0;
+        for (Enumeration<String> attribs = request.getKeys(); attribs
+                .hasMoreElements();) {
+            String parameterName = attribs.nextElement();
+            V value = request.getValue(parameterName);
+            retValue += parameterName.hashCode() ^ (value == null ? 0 : value.hashCode());
+        }
+        return retValue;
+    }
+
+    class ReadOnlyEnumerationMapEntrySet implements Set<Map.Entry<String, V>> {
 
         @Override
-        public boolean add(java.util.Map.Entry<String, String> e) {
+        public boolean add(java.util.Map.Entry<String, V> e) {
             throw new UnsupportedOperationException();
         }
 
         @Override
         public boolean addAll(
-                Collection<? extends java.util.Map.Entry<String, String>> c) {
+                Collection<? extends java.util.Map.Entry<String, V>> c) {
             throw new UnsupportedOperationException();
         }
 
@@ -152,15 +192,15 @@ public class ParameterMap extends Abstra
         @SuppressWarnings("unchecked")
         @Override
         public boolean contains(Object o) {
-            return containsEntry((java.util.Map.Entry<String, String>) o);
+            return containsEntry((java.util.Map.Entry<String, V>) o);
         }
 
         @SuppressWarnings("unchecked")
         @Override
         public boolean containsAll(Collection<?> c) {
-            Collection<Map.Entry<String, String>> realCollection =
-                (Collection<Map.Entry<String, String>>) c;
-            for (Map.Entry<String, String> entry : realCollection) {
+            Collection<Map.Entry<String, V>> realCollection =
+                (Collection<Map.Entry<String, V>>) c;
+            for (Map.Entry<String, V> entry : realCollection) {
                 if (!containsEntry(entry)) {
                     return false;
                 }
@@ -170,12 +210,12 @@ public class ParameterMap extends Abstra
 
         @Override
         public boolean isEmpty() {
-            return ParameterMap.this.isEmpty();
+            return ReadOnlyEnumerationMap.this.isEmpty();
         }
 
         @Override
-        public Iterator<java.util.Map.Entry<String, String>> iterator() {
-            return new HeaderEntrySetIterator();
+        public Iterator<java.util.Map.Entry<String, V>> iterator() {
+            return new ReadOnlyEnumerationMapEntrySetIterator();
         }
 
         @Override
@@ -195,7 +235,7 @@ public class ParameterMap extends Abstra
 
         @Override
         public int size() {
-            return ParameterMap.this.size();
+            return ReadOnlyEnumerationMap.this.size();
         }
 
         @Override
@@ -208,13 +248,13 @@ public class ParameterMap extends Abstra
             return toList().toArray(a);
         }
 
-        private boolean containsEntry(Map.Entry<String, String> entry) {
-            String storedValue = request.getValue(key(entry.getKey()));
+        protected boolean containsEntry(Map.Entry<String, V> entry) {
+            V storedValue = request.getValue(key(entry.getKey()));
             return storedValue != null && storedValue.equals(entry.getValue());
         }
 
-        private List<Map.Entry<String, String>> toList() {
-            List<Map.Entry<String, String>> entries = new ArrayList<Map.Entry<String,String>>();
+        private List<Map.Entry<String, V>> toList() {
+            List<Map.Entry<String, V>> entries = new ArrayList<Map.Entry<String,V>>();
             Enumeration<String> names = request.getKeys();
             while (names.hasMoreElements()) {
                 entries.add(extractNextEntry(names));
@@ -222,14 +262,14 @@ public class ParameterMap extends Abstra
             return entries;
         }
 
-        private MapEntry<String, String> extractNextEntry(
+        private MapEntry<String, V> extractNextEntry(
                 Enumeration<String> names) {
             String name = names.nextElement();
-            return new MapEntry<String, String>(name, request.getValue(name),
+            return new MapEntry<String, V>(name, request.getValue(name),
                     false);
         }
 
-        private class HeaderEntrySetIterator implements Iterator<Map.Entry<String, String>> {
+        private class ReadOnlyEnumerationMapEntrySetIterator implements Iterator<Map.Entry<String, V>> {
 
             private Enumeration<String> namesEnumeration = request.getKeys();
 
@@ -239,7 +279,7 @@ public class ParameterMap extends Abstra
             }
 
             @Override
-            public java.util.Map.Entry<String, String> next() {
+            public java.util.Map.Entry<String, V> next() {
                 return extractNextEntry(namesEnumeration);
             }
 
@@ -251,15 +291,15 @@ public class ParameterMap extends Abstra
         }
     }
 
-    private class ParameterMapValuesCollection implements Collection<String> {
+    private class ReadOnlyEnumerationMapValuesCollection implements Collection<V> {
 
         @Override
-        public boolean add(String e) {
+        public boolean add(V e) {
             throw new UnsupportedOperationException();
         }
 
         @Override
-        public boolean addAll(Collection<? extends String> c) {
+        public boolean addAll(Collection<? extends V> c) {
             throw new UnsupportedOperationException();
         }
 
@@ -289,12 +329,12 @@ public class ParameterMap extends Abstra
 
         @Override
         public boolean isEmpty() {
-            return ParameterMap.this.isEmpty();
+            return ReadOnlyEnumerationMap.this.isEmpty();
         }
 
         @Override
-        public Iterator<String> iterator() {
-            return new HeaderValuesCollectionIterator();
+        public Iterator<V> iterator() {
+            return new ReadOnlyEnumerationMapValuesCollectionIterator();
         }
 
         @Override
@@ -314,7 +354,7 @@ public class ParameterMap extends Abstra
 
         @Override
         public int size() {
-            return ParameterMap.this.size();
+            return ReadOnlyEnumerationMap.this.size();
         }
 
         @Override
@@ -327,8 +367,8 @@ public class ParameterMap extends Abstra
             return toList().toArray(a);
         }
 
-        private List<String> toList() {
-            List<String> entries = new ArrayList<String>();
+        private List<V> toList() {
+            List<V> entries = new ArrayList<V>();
             Enumeration<String> names = request.getKeys();
             while (names.hasMoreElements()) {
                 entries.add(request.getValue(names.nextElement()));
@@ -337,7 +377,7 @@ public class ParameterMap extends Abstra
         }
 
 
-        private class HeaderValuesCollectionIterator implements Iterator<String> {
+        private class ReadOnlyEnumerationMapValuesCollectionIterator implements Iterator<V> {
 
             private Enumeration<String> namesEnumeration = request.getKeys();
 
@@ -347,7 +387,7 @@ public class ParameterMap extends Abstra
             }
 
             @Override
-            public String next() {
+            public V next() {
                 return request.getValue(namesEnumeration.nextElement());
             }
 

Modified: tiles/sandbox/trunk/tiles-request/tiles-request-api/src/main/java/org/apache/tiles/request/collection/ScopeMap.java
URL: http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles-request/tiles-request-api/src/main/java/org/apache/tiles/request/collection/ScopeMap.java?rev=937811&r1=937810&r2=937811&view=diff
==============================================================================
--- tiles/sandbox/trunk/tiles-request/tiles-request-api/src/main/java/org/apache/tiles/request/collection/ScopeMap.java (original)
+++ tiles/sandbox/trunk/tiles-request/tiles-request-api/src/main/java/org/apache/tiles/request/collection/ScopeMap.java Sun Apr 25 15:12:47 2010
@@ -22,11 +22,9 @@ package org.apache.tiles.request.collect
 
 import static org.apache.tiles.request.util.RequestUtil.*;
 
-import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Enumeration;
 import java.util.Iterator;
-import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
@@ -40,7 +38,7 @@ import org.apache.tiles.request.util.Map
  * @version $Rev$ $Date$
  */
 
-public class ScopeMap extends AbstractEnumerationMap<Object> {
+public class ScopeMap extends ReadOnlyEnumerationMap<Object> {
 
     private AttributeExtractor context;
 
@@ -63,65 +61,24 @@ public class ScopeMap extends AbstractEn
         }
     }
 
-
-    /** {@inheritDoc} */
-    public boolean containsKey(Object key) {
-        return context.getValue(key(key)) != null;
-    }
-
-
-    /** {@inheritDoc} */
-    public boolean containsValue(Object value) {
-        if (value == null) {
-            return (false);
-        }
-        Enumeration<String> keys = context.getKeys();
-        while (keys.hasMoreElements()) {
-            Object next = context.getValue(keys.nextElement());
-            if (next == value) {
-                return true;
-            }
-        }
-        return false;
-    }
-
-
     /** {@inheritDoc} */
     public Set<Map.Entry<String, Object>> entrySet() {
-        return new ServletApplicationScopeEntrySet();
-    }
-
-
-
-    /** {@inheritDoc} */
-    public Object get(Object key) {
-        return context.getValue(key(key));
+        return new ScopeEntrySet();
     }
 
     /** {@inheritDoc} */
-    public boolean isEmpty() {
-        return !context.getKeys().hasMoreElements();
-    }
-
-
-    /** {@inheritDoc} */
     public Set<String> keySet() {
         return new RemovableKeySet(context);
     }
 
-
     /** {@inheritDoc} */
     public Object put(String key, Object value) {
-        if (value == null) {
-            return remove(key);
-        }
         String skey = key(key);
         Object previous = context.getValue(skey);
         context.setValue(skey, value);
         return previous;
     }
 
-
     /** {@inheritDoc} */
     public void putAll(Map<? extends String, ? extends Object> map) {
         Iterator<? extends String> keys = map.keySet().iterator();
@@ -131,7 +88,6 @@ public class ScopeMap extends AbstractEn
         }
     }
 
-
     /** {@inheritDoc} */
     public Object remove(Object key) {
         String skey = key(key);
@@ -140,25 +96,18 @@ public class ScopeMap extends AbstractEn
         return (previous);
     }
 
-
-    /** {@inheritDoc} */
-    public int size() {
-        return enumerationSize(context.getKeys());
-    }
-
-
-    /** {@inheritDoc} */
-    public Collection<Object> values() {
-        return new ServletApplicationScopeValuesCollection();
-    }
-
-    private class ServletApplicationScopeEntrySet implements Set<Map.Entry<String, Object>> {
+    private class ScopeEntrySet extends ReadOnlyEnumerationMap<Object>.ReadOnlyEnumerationMapEntrySet {
 
         @Override
         public boolean add(java.util.Map.Entry<String, Object> e) {
-            Object oldValue = get(e.getKey());
-            put(e.getKey(), e.getValue());
-            return oldValue == null || !oldValue.equals(e.getValue());
+            String key = e.getKey();
+            Object value = e.getValue();
+            Object oldValue = get(key);
+            if (oldValue == null || !oldValue.equals(value)) {
+                context.setValue(key, value);
+                return true;
+            }
+            return false;
         }
 
         @Override
@@ -178,40 +127,12 @@ public class ScopeMap extends AbstractEn
 
         @SuppressWarnings("unchecked")
         @Override
-        public boolean contains(Object o) {
-            return containsEntry((java.util.Map.Entry<String, Object>) o);
-        }
-
-        @SuppressWarnings("unchecked")
-        @Override
-        public boolean containsAll(Collection<?> c) {
-            Collection<Map.Entry<String, Object>> realCollection =
-                (Collection<Map.Entry<String, Object>>) c;
-            for (Map.Entry<String, Object> entry : realCollection) {
-                if (!containsEntry(entry)) {
-                    return false;
-                }
-            }
-            return true;
-        }
-
-        @Override
-        public boolean isEmpty() {
-            return ScopeMap.this.isEmpty();
-        }
-
-        @Override
-        public Iterator<java.util.Map.Entry<String, Object>> iterator() {
-            return new ServletApplicationScopeEntrySetIterator();
-        }
-
-        @SuppressWarnings("unchecked")
-        @Override
         public boolean remove(Object o) {
             Map.Entry<String, Object> entry = (java.util.Map.Entry<String, Object>) o;
-            Object currentValue = get(entry.getKey());
+            String key = entry.getKey();
+            Object currentValue = context.getValue(key);
             if (currentValue != null && currentValue.equals(entry.getValue())) {
-                context.removeValue(entry.getKey());
+                context.removeValue(key);
                 return true;
             }
             return false;
@@ -233,173 +154,16 @@ public class ScopeMap extends AbstractEn
         public boolean retainAll(Collection<?> c) {
             Collection<Map.Entry<String, Object>> realCollection = (Collection<java.util.Map.Entry<String, Object>>) c;
             boolean retValue = false;
-            for (Map.Entry<String, Object> entry : realCollection) {
-                if (containsEntry(entry)) {
-                    retValue |= remove(entry);
+            for (Enumeration<String> keys = context.getKeys(); keys.hasMoreElements(); ) {
+                String key = keys.nextElement();
+                Object value = context.getValue(key);
+                Map.Entry<String, Object> entry = new MapEntry<String, Object>(key, value, false);
+                if (!realCollection.contains(entry)) {
+                    retValue = true;
+                    context.removeValue(key);
                 }
             }
             return retValue;
         }
-
-        @Override
-        public int size() {
-            return ScopeMap.this.size();
-        }
-
-        @Override
-        public Object[] toArray() {
-            return toList().toArray();
-        }
-
-        @Override
-        public <T> T[] toArray(T[] a) {
-            return toList().toArray(a);
-        }
-
-        private boolean containsEntry(Map.Entry<String, Object> entry) {
-            Object storedValue = context.getValue(key(entry.getKey()));
-            return storedValue != null && storedValue.equals(entry.getValue());
-        }
-
-        private List<Map.Entry<String, Object>> toList() {
-            List<Map.Entry<String, Object>> entries = new ArrayList<Map.Entry<String,Object>>();
-            Enumeration<String> names = context.getKeys();
-            while (names.hasMoreElements()) {
-                entries.add(extractNextEntry(names));
-            }
-            return entries;
-        }
-
-        private MapEntry<String, Object> extractNextEntry(
-                Enumeration<String> names) {
-            String name = names.nextElement();
-            return new MapEntry<String, Object>(name, context.getValue(name),
-                    false);
-        }
-
-        private class ServletApplicationScopeEntrySetIterator implements Iterator<Map.Entry<String, Object>> {
-
-            private Enumeration<String> namesEnumeration = context.getKeys();
-
-            @Override
-            public boolean hasNext() {
-                return namesEnumeration.hasMoreElements();
-            }
-
-            @Override
-            public java.util.Map.Entry<String, Object> next() {
-                return extractNextEntry(namesEnumeration);
-            }
-
-            @Override
-            public void remove() {
-                throw new UnsupportedOperationException();
-            }
-
-        }
-    }
-
-    private class ServletApplicationScopeValuesCollection implements Collection<Object> {
-
-        @Override
-        public boolean add(Object e) {
-            throw new UnsupportedOperationException();
-        }
-
-        @Override
-        public boolean addAll(Collection<? extends Object> c) {
-            throw new UnsupportedOperationException();
-        }
-
-        @Override
-        public void clear() {
-            ScopeMap.this.clear();
-        }
-
-        @Override
-        public boolean contains(Object o) {
-            return containsValue(o);
-        }
-
-        @SuppressWarnings("unchecked")
-        @Override
-        public boolean containsAll(Collection<?> c) {
-            Collection<String> realCollection = (Collection<String>) c;
-            for (String value : realCollection) {
-                if (!containsValue(value)) {
-                    return false;
-                }
-            }
-            return true;
-        }
-
-        @Override
-        public boolean isEmpty() {
-            return ScopeMap.this.isEmpty();
-        }
-
-        @Override
-        public Iterator<Object> iterator() {
-            return new ServletApplicationScopeValuesCollectionIterator();
-        }
-
-        @Override
-        public boolean remove(Object o) {
-            throw new UnsupportedOperationException();
-        }
-
-        @Override
-        public boolean removeAll(Collection<?> c) {
-            throw new UnsupportedOperationException();
-        }
-
-        @Override
-        public boolean retainAll(Collection<?> c) {
-            throw new UnsupportedOperationException();
-        }
-
-        @Override
-        public int size() {
-            return ScopeMap.this.size();
-        }
-
-        @Override
-        public Object[] toArray() {
-            return toList().toArray();
-        }
-
-        @Override
-        public <T> T[] toArray(T[] a) {
-            return toList().toArray(a);
-        }
-
-        private List<Object> toList() {
-            List<Object> entries = new ArrayList<Object>();
-            Enumeration<String> names = context.getKeys();
-            while (names.hasMoreElements()) {
-                entries.add(context.getValue(names.nextElement()));
-            }
-            return entries;
-        }
-
-        private class ServletApplicationScopeValuesCollectionIterator implements Iterator<Object> {
-
-            private Enumeration<String> namesEnumeration = context.getKeys();
-
-            @Override
-            public boolean hasNext() {
-                return namesEnumeration.hasMoreElements();
-            }
-
-            @Override
-            public Object next() {
-                return context.getValue(namesEnumeration.nextElement());
-            }
-
-            @Override
-            public void remove() {
-                throw new UnsupportedOperationException();
-            }
-        }
     }
 }

Copied: tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/ReadOnlyEnumerationMapEntrySetTest.java (from r937783, tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/ParameterMapEntrySetTest.java)
URL: http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/ReadOnlyEnumerationMapEntrySetTest.java?p2=tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/ReadOnlyEnumerationMapEntrySetTest.java&p1=tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/ParameterMapEntrySetTest.java&r1=937783&r2=937811&rev=937811&view=diff
==============================================================================
--- tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/ParameterMapEntrySetTest.java (original)
+++ tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/ReadOnlyEnumerationMapEntrySetTest.java Sun Apr 25 15:12:47 2010
@@ -17,16 +17,16 @@ import org.junit.Before;
 import org.junit.Test;
 
 /**
- * Tests {@link ParameterMap#entrySet()}
+ * Tests {@link ReadOnlyEnumerationMap#entrySet()}
  *
  * @version $Rev$ $Date$
  */
-public class ParameterMapEntrySetTest {
-    private HasKeys<String> extractor;
+public class ReadOnlyEnumerationMapEntrySetTest {
+    private HasKeys<Integer> extractor;
 
-    private ParameterMap map;
+    private ReadOnlyEnumerationMap<Integer> map;
 
-    private Set<Map.Entry<String, String>> entrySet;
+    private Set<Map.Entry<String, Integer>> entrySet;
 
     /**
      * Sets up the test.
@@ -35,7 +35,7 @@ public class ParameterMapEntrySetTest {
     @Before
     public void setUp() {
         extractor = createMock(HasKeys.class);
-        map = new ParameterMap(extractor);
+        map = new ReadOnlyEnumerationMap<Integer>(extractor);
         entrySet = map.entrySet();
     }
 
@@ -69,13 +69,13 @@ public class ParameterMapEntrySetTest {
     @SuppressWarnings("unchecked")
     @Test
     public void testContains() {
-        Map.Entry<String, String> entry = createMock(Map.Entry.class);
+        Map.Entry<String, Integer> entry = createMock(Map.Entry.class);
         Enumeration<String> values2 = createMock(Enumeration.class);
 
         expect(entry.getKey()).andReturn("two");
-        expect(entry.getValue()).andReturn("value2");
+        expect(entry.getValue()).andReturn(2);
 
-        expect(extractor.getValue("two")).andReturn("value2");
+        expect(extractor.getValue("two")).andReturn(2);
 
         replay(extractor, entry, values2);
         assertTrue(entrySet.contains(entry));
@@ -88,19 +88,19 @@ public class ParameterMapEntrySetTest {
     @SuppressWarnings("unchecked")
     @Test
     public void testContainsAll() {
-        Map.Entry<String, String> entry1 = createMock(Map.Entry.class);
-        Map.Entry<String, String> entry2 = createMock(Map.Entry.class);
+        Map.Entry<String, Integer> entry1 = createMock(Map.Entry.class);
+        Map.Entry<String, Integer> entry2 = createMock(Map.Entry.class);
 
         expect(entry1.getKey()).andReturn("one");
-        expect(entry1.getValue()).andReturn("value1");
+        expect(entry1.getValue()).andReturn(1);
         expect(entry2.getKey()).andReturn("two");
-        expect(entry2.getValue()).andReturn("value2");
+        expect(entry2.getValue()).andReturn(2);
 
-        expect(extractor.getValue("one")).andReturn("value1");
-        expect(extractor.getValue("two")).andReturn("value2");
+        expect(extractor.getValue("one")).andReturn(1);
+        expect(extractor.getValue("two")).andReturn(2);
 
         replay(extractor, entry1, entry2);
-        List<Map.Entry<String, String>> coll = new ArrayList<Map.Entry<String,String>>();
+        List<Map.Entry<String, Integer>> coll = new ArrayList<Map.Entry<String, Integer>>();
         coll.add(entry1);
         coll.add(entry2);
         assertTrue(entrySet.containsAll(coll));
@@ -118,7 +118,7 @@ public class ParameterMapEntrySetTest {
         expect(entry1.getKey()).andReturn("one");
         expect(entry1.getValue()).andReturn("value4");
 
-        expect(extractor.getValue("one")).andReturn("value1");
+        expect(extractor.getValue("one")).andReturn(1);
 
         replay(extractor, entry1);
         List<Map.Entry<String, String>> coll = new ArrayList<Map.Entry<String,String>>();
@@ -155,13 +155,13 @@ public class ParameterMapEntrySetTest {
         expect(keys.hasMoreElements()).andReturn(true);
         expect(keys.nextElement()).andReturn("two");
 
-        expect(extractor.getValue("two")).andReturn("value2");
+        expect(extractor.getValue("two")).andReturn(2);
 
         replay(extractor, keys);
-        Iterator<Map.Entry<String, String>> entryIt = entrySet.iterator();
+        Iterator<Map.Entry<String, Integer>> entryIt = entrySet.iterator();
         assertTrue(entryIt.hasNext());
-        MapEntry<String, String> entry = new MapEntry<String, String>(
-                "two", "value2", false);
+        MapEntry<String, Integer> entry = new MapEntry<String, Integer>(
+                "two", 2, false);
         assertEquals(entry, entryIt.next());
         verify(extractor, keys);
     }
@@ -245,12 +245,12 @@ public class ParameterMapEntrySetTest {
         expect(keys.nextElement()).andReturn("two");
         expect(keys.hasMoreElements()).andReturn(false);
 
-        expect(extractor.getValue("one")).andReturn("value1");
-        expect(extractor.getValue("two")).andReturn("value2");
+        expect(extractor.getValue("one")).andReturn(1);
+        expect(extractor.getValue("two")).andReturn(2);
 
-        MapEntry<String, String>[] entryArray = new MapEntry[2];
-        entryArray[0] = new MapEntry<String, String>("one", "value1", false);
-        entryArray[1] = new MapEntry<String, String>("two", "value2", false);
+        MapEntry<String, Integer>[] entryArray = new MapEntry[2];
+        entryArray[0] = new MapEntry<String, Integer>("one", 1, false);
+        entryArray[1] = new MapEntry<String, Integer>("two", 2, false);
 
         replay(extractor, keys, values1, values2);
         assertArrayEquals(entryArray, entrySet.toArray());
@@ -274,12 +274,12 @@ public class ParameterMapEntrySetTest {
         expect(keys.nextElement()).andReturn("two");
         expect(keys.hasMoreElements()).andReturn(false);
 
-        expect(extractor.getValue("one")).andReturn("value1");
-        expect(extractor.getValue("two")).andReturn("value2");
+        expect(extractor.getValue("one")).andReturn(1);
+        expect(extractor.getValue("two")).andReturn(2);
 
-        MapEntry<String, String>[] entryArray = new MapEntry[2];
-        entryArray[0] = new MapEntry<String, String>("one", "value1", false);
-        entryArray[1] = new MapEntry<String, String>("two", "value2", false);
+        MapEntry<String, Integer>[] entryArray = new MapEntry[2];
+        entryArray[0] = new MapEntry<String, Integer>("one", 1, false);
+        entryArray[1] = new MapEntry<String, Integer>("two", 2, false);
 
         replay(extractor, keys, values1, values2);
         MapEntry<String, String>[] realArray = new MapEntry[2];

Copied: tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/ReadOnlyEnumerationMapTest.java (from r937783, tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/ParameterMapTest.java)
URL: http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/ReadOnlyEnumerationMapTest.java?p2=tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/ReadOnlyEnumerationMapTest.java&p1=tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/ParameterMapTest.java&r1=937783&r2=937811&rev=937811&view=diff
==============================================================================
--- tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/ParameterMapTest.java (original)
+++ tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/ReadOnlyEnumerationMapTest.java Sun Apr 25 15:12:47 2010
@@ -10,33 +10,33 @@ import static org.junit.Assert.*;
 import java.util.Enumeration;
 import java.util.HashMap;
 
-import org.apache.tiles.request.collection.extractor.EnumeratedValuesExtractor;
 import org.apache.tiles.request.collection.extractor.HasKeys;
 import org.junit.Before;
 import org.junit.Test;
 
 /**
- * Tests {@link ParameterMap}.
+ * Tests {@link ReadOnlyEnumerationMap}.
  *
  * @version $Rev$ $Date$
  */
-public class ParameterMapTest {
+public class ReadOnlyEnumerationMapTest {
 
-    private HasKeys<String> extractor;
+    private HasKeys<Integer> extractor;
 
-    private ParameterMap map;
+    private ReadOnlyEnumerationMap<Integer> map;
 
     /**
      * Sets up the test.
      */
+    @SuppressWarnings("unchecked")
     @Before
     public void setUp() {
-        extractor = createMock(EnumeratedValuesExtractor.class);
-        map = new ParameterMap(extractor);
+        extractor = createMock(HasKeys.class);
+        map = new ReadOnlyEnumerationMap<Integer>(extractor);
     }
 
     /**
-     * Test method for {@link org.apache.tiles.request.collection.ParameterMap#clear()}.
+     * Test method for {@link org.apache.tiles.request.collection.ReadOnlyEnumerationMap#clear()}.
      */
     @Test(expected=UnsupportedOperationException.class)
     public void testClear() {
@@ -44,11 +44,11 @@ public class ParameterMapTest {
     }
 
     /**
-     * Test method for {@link org.apache.tiles.request.collection.ParameterMap#containsKey(java.lang.Object)}.
+     * Test method for {@link org.apache.tiles.request.collection.ReadOnlyEnumerationMap#containsKey(java.lang.Object)}.
      */
     @Test
     public void testContainsKey() {
-        expect(extractor.getValue("one")).andReturn("value1");
+        expect(extractor.getValue("one")).andReturn(1);
         expect(extractor.getValue("two")).andReturn(null);
 
         replay(extractor);
@@ -58,7 +58,7 @@ public class ParameterMapTest {
     }
 
     /**
-     * Test method for {@link org.apache.tiles.request.collection.ParameterMap#containsValue(java.lang.Object)}.
+     * Test method for {@link org.apache.tiles.request.collection.ReadOnlyEnumerationMap#containsValue(java.lang.Object)}.
      */
     @SuppressWarnings("unchecked")
     @Test
@@ -71,16 +71,16 @@ public class ParameterMapTest {
         expect(keys.hasMoreElements()).andReturn(true);
         expect(keys.nextElement()).andReturn("two");
 
-        expect(extractor.getValue("one")).andReturn("value1");
-        expect(extractor.getValue("two")).andReturn("value2");
+        expect(extractor.getValue("one")).andReturn(1);
+        expect(extractor.getValue("two")).andReturn(2);
 
         replay(extractor, keys);
-        assertTrue(map.containsValue("value2"));
+        assertTrue(map.containsValue(2));
         verify(extractor, keys);
     }
 
     /**
-     * Test method for {@link org.apache.tiles.request.collection.ParameterMap#containsValue(java.lang.Object)}.
+     * Test method for {@link org.apache.tiles.request.collection.ReadOnlyEnumerationMap#containsValue(java.lang.Object)}.
      */
     @SuppressWarnings("unchecked")
     @Test
@@ -94,28 +94,28 @@ public class ParameterMapTest {
         expect(keys.nextElement()).andReturn("two");
         expect(keys.hasMoreElements()).andReturn(false);
 
-        expect(extractor.getValue("one")).andReturn("value1");
-        expect(extractor.getValue("two")).andReturn("value2");
+        expect(extractor.getValue("one")).andReturn(1);
+        expect(extractor.getValue("two")).andReturn(1);
 
         replay(extractor, keys);
-        assertFalse(map.containsValue("value3"));
+        assertFalse(map.containsValue(3));
         verify(extractor, keys);
     }
 
     /**
-     * Test method for {@link org.apache.tiles.request.collection.ParameterMap#get(java.lang.Object)}.
+     * Test method for {@link org.apache.tiles.request.collection.ReadOnlyEnumerationMap#get(java.lang.Object)}.
      */
     @Test
     public void testGet() {
-        expect(extractor.getValue("two")).andReturn("value2");
+        expect(extractor.getValue("two")).andReturn(2);
 
         replay(extractor);
-        assertEquals("value2", map.get("two"));
+        assertEquals(new Integer(2), map.get("two"));
         verify(extractor);
     }
 
     /**
-     * Test method for {@link org.apache.tiles.request.collection.ParameterMap#isEmpty()}.
+     * Test method for {@link org.apache.tiles.request.collection.ReadOnlyEnumerationMap#isEmpty()}.
      */
     @SuppressWarnings("unchecked")
     @Test
@@ -131,7 +131,7 @@ public class ParameterMapTest {
     }
 
     /**
-     * Test method for {@link org.apache.tiles.request.collection.ParameterMap#isEmpty()}.
+     * Test method for {@link org.apache.tiles.request.collection.ReadOnlyEnumerationMap#isEmpty()}.
      */
     @SuppressWarnings("unchecked")
     @Test
@@ -147,7 +147,7 @@ public class ParameterMapTest {
     }
 
     /**
-     * Test method for {@link org.apache.tiles.request.collection.ParameterMap#keySet()}.
+     * Test method for {@link org.apache.tiles.request.collection.ReadOnlyEnumerationMap#keySet()}.
      */
     @Test
     public void testKeySet() {
@@ -157,23 +157,23 @@ public class ParameterMapTest {
     }
 
     /**
-     * Test method for {@link org.apache.tiles.request.collection.ParameterMap#put(java.lang.String, java.lang.String[])}.
+     * Test method for {@link org.apache.tiles.request.collection.ReadOnlyEnumerationMap#put(java.lang.String, java.lang.String[])}.
      */
     @Test(expected=UnsupportedOperationException.class)
     public void testPut() {
-        map.put("one", "value1");
+        map.put("one", 1);
     }
 
     /**
-     * Test method for {@link org.apache.tiles.request.collection.ParameterMap#putAll(java.util.Map)}.
+     * Test method for {@link org.apache.tiles.request.collection.ReadOnlyEnumerationMap#putAll(java.util.Map)}.
      */
     @Test(expected=UnsupportedOperationException.class)
     public void testPutAll() {
-        map.putAll(new HashMap<String, String>());
+        map.putAll(new HashMap<String, Integer>());
     }
 
     /**
-     * Test method for {@link org.apache.tiles.request.collection.ParameterMap#remove(java.lang.Object)}.
+     * Test method for {@link org.apache.tiles.request.collection.ReadOnlyEnumerationMap#remove(java.lang.Object)}.
      */
     @Test(expected=UnsupportedOperationException.class)
     public void testRemove() {
@@ -181,7 +181,7 @@ public class ParameterMapTest {
     }
 
     /**
-     * Test method for {@link org.apache.tiles.request.collection.ParameterMap#size()}.
+     * Test method for {@link org.apache.tiles.request.collection.ReadOnlyEnumerationMap#size()}.
      */
     @SuppressWarnings("unchecked")
     @Test
@@ -199,4 +199,109 @@ public class ParameterMapTest {
         assertEquals(2, map.size());
         verify(extractor, keys);
     }
+
+    /**
+     * Test method for {@link org.apache.tiles.extractor.collection.AbstractEnumerationMap#hashCode()}.
+     */
+    @SuppressWarnings("unchecked")
+    @Test
+    public void testHashCode() {
+        Enumeration<String> keys = createMock(Enumeration.class);
+
+        expect(extractor.getKeys()).andReturn(keys);
+
+        expect(keys.hasMoreElements()).andReturn(true);
+        expect(keys.nextElement()).andReturn("first");
+        expect(keys.hasMoreElements()).andReturn(true);
+        expect(keys.nextElement()).andReturn("second");
+        expect(keys.hasMoreElements()).andReturn(false);
+
+        Integer value1 = 1;
+
+        expect(extractor.getValue("first")).andReturn(value1);
+        expect(extractor.getValue("second")).andReturn(null);
+
+        replay(extractor, keys);
+        assertEquals(("first".hashCode() ^ value1.hashCode())
+                + ("second".hashCode() ^ 0), map.hashCode());
+        verify(extractor, keys);
+    }
+
+    /**
+     * Test method for {@link org.apache.tiles.extractor.collection.AbstractEnumerationMap#equals(java.lang.Object)}.
+     */
+    @SuppressWarnings("unchecked")
+    @Test
+    public void testEqualsObject() {
+        HasKeys<Integer> otherRequest = createMock(HasKeys.class);
+        AbstractEnumerationMap<Integer> otherMap = createMockBuilder(
+                AbstractEnumerationMap.class).withConstructor(otherRequest)
+                .createMock();
+        Enumeration<String> keys = createMock(Enumeration.class);
+        Enumeration<String> otherKeys = createMock(Enumeration.class);
+
+        expect(extractor.getKeys()).andReturn(keys);
+        expect(otherRequest.getKeys()).andReturn(otherKeys);
+
+        expect(keys.hasMoreElements()).andReturn(true);
+        expect(keys.nextElement()).andReturn("first");
+        expect(keys.hasMoreElements()).andReturn(true);
+        expect(keys.nextElement()).andReturn("second");
+        expect(keys.hasMoreElements()).andReturn(false);
+
+        expect(extractor.getValue("first")).andReturn(1);
+        expect(extractor.getValue("second")).andReturn(2);
+
+        expect(otherKeys.hasMoreElements()).andReturn(true);
+        expect(otherKeys.nextElement()).andReturn("first");
+        expect(otherKeys.hasMoreElements()).andReturn(true);
+        expect(otherKeys.nextElement()).andReturn("second");
+        expect(otherKeys.hasMoreElements()).andReturn(false);
+
+        expect(otherRequest.getValue("first")).andReturn(1);
+        expect(otherRequest.getValue("second")).andReturn(2);
+
+        replay(extractor, otherRequest, otherMap, keys, otherKeys);
+        assertTrue(map.equals(otherMap));
+        verify(extractor, otherRequest, otherMap, keys, otherKeys);
+    }
+
+    /**
+     * Test method for {@link org.apache.tiles.extractor.collection.AbstractEnumerationMap#equals(java.lang.Object)}.
+     */
+    @SuppressWarnings("unchecked")
+    @Test
+    public void testEqualsObjectFalse() {
+        HasKeys<Integer> otherRequest = createMock(HasKeys.class);
+        AbstractEnumerationMap<Integer> otherMap = createMockBuilder(
+                AbstractEnumerationMap.class).withConstructor(otherRequest)
+                .createMock();
+        Enumeration<String> keys = createMock(Enumeration.class);
+        Enumeration<String> otherKeys = createMock(Enumeration.class);
+
+        expect(extractor.getKeys()).andReturn(keys);
+        expect(otherRequest.getKeys()).andReturn(otherKeys);
+
+        expect(keys.hasMoreElements()).andReturn(true);
+        expect(keys.nextElement()).andReturn("first");
+        expect(keys.hasMoreElements()).andReturn(true);
+        expect(keys.nextElement()).andReturn("second");
+        expect(keys.hasMoreElements()).andReturn(false);
+
+        expect(extractor.getValue("first")).andReturn(1);
+        expect(extractor.getValue("second")).andReturn(2);
+
+        expect(otherKeys.hasMoreElements()).andReturn(true);
+        expect(otherKeys.nextElement()).andReturn("first");
+        expect(otherKeys.hasMoreElements()).andReturn(true);
+        expect(otherKeys.nextElement()).andReturn("second");
+        expect(otherKeys.hasMoreElements()).andReturn(false);
+
+        expect(otherRequest.getValue("first")).andReturn(1);
+        expect(otherRequest.getValue("second")).andReturn(3);
+
+        replay(extractor, otherRequest, otherMap, keys, otherKeys);
+        assertFalse(map.equals(otherMap));
+        verify(extractor, otherRequest, otherMap, keys, otherKeys);
+    }
 }

Copied: tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/ReadOnlyEnumerationMapValuesCollectionTest.java (from r937783, tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/ParameterMapValuesCollectionTest.java)
URL: http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/ReadOnlyEnumerationMapValuesCollectionTest.java?p2=tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/ReadOnlyEnumerationMapValuesCollectionTest.java&p1=tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/ParameterMapValuesCollectionTest.java&r1=937783&r2=937811&rev=937811&view=diff
==============================================================================
--- tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/ParameterMapValuesCollectionTest.java (original)
+++ tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/ReadOnlyEnumerationMapValuesCollectionTest.java Sun Apr 25 15:12:47 2010
@@ -10,30 +10,30 @@ import java.util.Enumeration;
 import java.util.Iterator;
 import java.util.List;
 
-import org.apache.tiles.request.collection.extractor.EnumeratedValuesExtractor;
 import org.apache.tiles.request.collection.extractor.HasKeys;
 import org.junit.Before;
 import org.junit.Test;
 
 /**
- * Tests {@link ParameterMap#values()}.
+ * Tests {@link ReadOnlyEnumerationMap#values()}.
  *
  * @version $Rev$ $Date$
  */
-public class ParameterMapValuesCollectionTest {
-    private HasKeys<String> extractor;
+public class ReadOnlyEnumerationMapValuesCollectionTest {
+    private HasKeys<Integer> extractor;
 
-    private ParameterMap map;
+    private ReadOnlyEnumerationMap<Integer> map;
 
-    private Collection<String> coll;
+    private Collection<Integer> coll;
 
     /**
      * Sets up the test.
      */
+    @SuppressWarnings("unchecked")
     @Before
     public void setUp() {
-        extractor = createMock(EnumeratedValuesExtractor.class);
-        map = new ParameterMap(extractor);
+        extractor = createMock(HasKeys.class);
+        map = new ReadOnlyEnumerationMap<Integer>(extractor);
         coll = map.values();
     }
 
@@ -75,11 +75,11 @@ public class ParameterMapValuesCollectio
         expect(keys.hasMoreElements()).andReturn(true);
         expect(keys.nextElement()).andReturn("two");
 
-        expect(extractor.getValue("one")).andReturn("value1");
-        expect(extractor.getValue("two")).andReturn("value2");
+        expect(extractor.getValue("one")).andReturn(1);
+        expect(extractor.getValue("two")).andReturn(2);
 
         replay(extractor, keys);
-        assertTrue(coll.contains("value2"));
+        assertTrue(coll.contains(2));
         verify(extractor, keys);
     }
 
@@ -98,11 +98,11 @@ public class ParameterMapValuesCollectio
         expect(keys.nextElement()).andReturn("two");
         expect(keys.hasMoreElements()).andReturn(false);
 
-        expect(extractor.getValue("one")).andReturn("value1");
-        expect(extractor.getValue("two")).andReturn("value2");
+        expect(extractor.getValue("one")).andReturn(1);
+        expect(extractor.getValue("two")).andReturn(2);
 
         replay(extractor, keys);
-        assertFalse(coll.contains("value3"));
+        assertFalse(coll.contains(3));
         verify(extractor, keys);
     }
 
@@ -120,13 +120,13 @@ public class ParameterMapValuesCollectio
         expect(keys.hasMoreElements()).andReturn(true);
         expect(keys.nextElement()).andReturn("two");
 
-        expect(extractor.getValue("one")).andReturn("value1");
-        expect(extractor.getValue("two")).andReturn("value2");
+        expect(extractor.getValue("one")).andReturn(1);
+        expect(extractor.getValue("two")).andReturn(2);
 
         replay(extractor, keys);
-        List<String> coll = new ArrayList<String>();
-        coll.add("value1");
-        coll.add("value2");
+        List<Integer> coll = new ArrayList<Integer>();
+        coll.add(1);
+        coll.add(2);
         assertTrue(this.coll.containsAll(coll));
         verify(extractor, keys);
     }
@@ -146,12 +146,12 @@ public class ParameterMapValuesCollectio
         expect(keys.nextElement()).andReturn("two");
         expect(keys.hasMoreElements()).andReturn(false);
 
-        expect(extractor.getValue("one")).andReturn("value1");
-        expect(extractor.getValue("two")).andReturn("value2");
+        expect(extractor.getValue("one")).andReturn(1);
+        expect(extractor.getValue("two")).andReturn(2);
 
         replay(extractor, keys);
-        List<String> coll = new ArrayList<String>();
-        coll.add("value3");
+        List<Integer> coll = new ArrayList<Integer>();
+        coll.add(3);
         assertFalse(this.coll.containsAll(coll));
         verify(extractor, keys);
     }
@@ -184,12 +184,12 @@ public class ParameterMapValuesCollectio
         expect(keys.hasMoreElements()).andReturn(true);
         expect(keys.nextElement()).andReturn("two");
 
-        expect(extractor.getValue("two")).andReturn("value2");
+        expect(extractor.getValue("two")).andReturn(2);
 
         replay(extractor, keys);
-        Iterator<String> entryIt = coll.iterator();
+        Iterator<Integer> entryIt = coll.iterator();
         assertTrue(entryIt.hasNext());
-        assertEquals("value2", entryIt.next());
+        assertEquals(new Integer(2), entryIt.next());
         verify(extractor, keys);
     }
 
@@ -270,10 +270,10 @@ public class ParameterMapValuesCollectio
         expect(keys.nextElement()).andReturn("two");
         expect(keys.hasMoreElements()).andReturn(false);
 
-        expect(extractor.getValue("one")).andReturn("value1");
-        expect(extractor.getValue("two")).andReturn("value2");
+        expect(extractor.getValue("one")).andReturn(1);
+        expect(extractor.getValue("two")).andReturn(2);
 
-        String[] entryArray = new String[] {"value1", "value2"};
+        Integer[] entryArray = new Integer[] {1, 2};
 
         replay(extractor, keys);
         assertArrayEquals(entryArray, coll.toArray());
@@ -295,13 +295,13 @@ public class ParameterMapValuesCollectio
         expect(keys.nextElement()).andReturn("two");
         expect(keys.hasMoreElements()).andReturn(false);
 
-        expect(extractor.getValue("one")).andReturn("value1");
-        expect(extractor.getValue("two")).andReturn("value2");
+        expect(extractor.getValue("one")).andReturn(1);
+        expect(extractor.getValue("two")).andReturn(2);
 
-        String[] entryArray = new String[] {"value1", "value2"};
+        Integer[] entryArray = new Integer[] {1, 2};
 
         replay(extractor, keys);
-        String[] realArray = new String[2];
+        Integer[] realArray = new Integer[2];
         assertArrayEquals(entryArray, coll.toArray(realArray));
         verify(extractor, keys);
     }

Added: tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/ScopeMapEntrySetTest.java
URL: http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/ScopeMapEntrySetTest.java?rev=937811&view=auto
==============================================================================
--- tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/ScopeMapEntrySetTest.java (added)
+++ tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/ScopeMapEntrySetTest.java Sun Apr 25 15:12:47 2010
@@ -0,0 +1,214 @@
+package org.apache.tiles.request.collection;
+
+
+import static org.easymock.EasyMock.*;
+import static org.easymock.classextension.EasyMock.*;
+import static org.junit.Assert.*;
+
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.tiles.request.collection.extractor.AttributeExtractor;
+import org.apache.tiles.request.util.MapEntry;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Tests {@link ScopeMap#entrySet()}
+ *
+ * @version $Rev$ $Date$
+ */
+public class ScopeMapEntrySetTest {
+
+    private ScopeMap map;
+
+    private AttributeExtractor extractor;
+
+    private Set<Map.Entry<String, Object>> entrySet;
+
+    /**
+     * Sets up the test.
+     */
+    @Before
+    public void setUp() {
+        extractor = createMock(AttributeExtractor.class);
+        map = new ScopeMap(extractor);
+        entrySet = map.entrySet();
+    }
+
+    /**
+     * Tests {@link Set#add(Object)}
+     */
+    @Test
+    public void testAdd() {
+        Map.Entry<String, Object> entry = createMock(Map.Entry.class);
+
+        expect(entry.getKey()).andReturn("one");
+        expect(entry.getValue()).andReturn(1);
+        expect(extractor.getValue("one")).andReturn(null);
+
+        extractor.setValue("one", 1);
+
+        replay(extractor, entry);
+        assertTrue(entrySet.add(entry));
+        verify(extractor, entry);
+    }
+
+    /**
+     * Tests {@link Set#add(Object)}
+     */
+    @Test
+    public void testAddNoEffect() {
+        Map.Entry<String, Object> entry = createMock(Map.Entry.class);
+
+        expect(entry.getKey()).andReturn("one");
+        expect(entry.getValue()).andReturn(1);
+        expect(extractor.getValue("one")).andReturn(1);
+
+        replay(extractor, entry);
+        assertFalse(entrySet.add(entry));
+        verify(extractor, entry);
+    }
+
+    /**
+     * Tests {@link Set#addAll(java.util.Collection)}
+     */
+    @Test
+    public void testAddAll() {
+        Map.Entry<String, Object> entry1 = createMock(Map.Entry.class);
+        Map.Entry<String, Object> entry2 = createMock(Map.Entry.class);
+
+        expect(entry1.getKey()).andReturn("one");
+        expect(entry1.getValue()).andReturn(1);
+        expect(entry2.getKey()).andReturn("two");
+        expect(entry2.getValue()).andReturn(2);
+        expect(extractor.getValue("one")).andReturn(null);
+        expect(extractor.getValue("two")).andReturn(null);
+
+        extractor.setValue("one", 1);
+        extractor.setValue("two", 2);
+
+        replay(extractor, entry1, entry2);
+        List<Map.Entry<String, Object>> coll = new ArrayList<Map.Entry<String,Object>>();
+        coll.add(entry1);
+        coll.add(entry2);
+        assertTrue(entrySet.addAll(coll));
+        verify(extractor, entry1, entry2);
+    }
+
+    /**
+     * Test method for {@link org.apache.tiles.request.collection.ScopeMap#clear()}.
+     */
+    @SuppressWarnings("unchecked")
+    @Test
+    public void testClear() {
+        Enumeration<String> keys = createMock(Enumeration.class);
+
+        expect(extractor.getKeys()).andReturn(keys);
+        expect(keys.hasMoreElements()).andReturn(true);
+        expect(keys.nextElement()).andReturn("one");
+        expect(keys.hasMoreElements()).andReturn(true);
+        expect(keys.nextElement()).andReturn("two");
+        expect(keys.hasMoreElements()).andReturn(false);
+
+        extractor.removeValue("one");
+        extractor.removeValue("two");
+
+        replay(extractor, keys);
+        entrySet.clear();
+        verify(extractor, keys);
+    }
+
+    /**
+     * Tests {@link Set#remove(Object)}
+     */
+    @Test
+    public void testRemove() {
+        Map.Entry<String, Object> entry = createMock(Map.Entry.class);
+
+        expect(entry.getKey()).andReturn("one");
+        expect(entry.getValue()).andReturn(1);
+        expect(extractor.getValue("one")).andReturn(1);
+        extractor.removeValue("one");
+
+        replay(extractor, entry);
+        assertTrue(entrySet.remove(entry));
+        verify(extractor, entry);
+    }
+
+    /**
+     * Tests {@link Set#remove(Object)}
+     */
+    @Test
+    public void testRemoveNoEffect() {
+        Map.Entry<String, Object> entry = createMock(Map.Entry.class);
+
+        expect(entry.getKey()).andReturn("one");
+        expect(extractor.getValue("one")).andReturn(null);
+
+        replay(extractor, entry);
+        assertFalse(entrySet.remove(entry));
+        verify(extractor, entry);
+    }
+
+    /**
+     * Tests {@link Set#addAll(java.util.Collection)}
+     */
+    @Test
+    public void testRemoveAll() {
+        Map.Entry<String, Object> entry1 = createMock(Map.Entry.class);
+        Map.Entry<String, Object> entry2 = createMock(Map.Entry.class);
+
+        expect(entry1.getKey()).andReturn("one");
+        expect(entry1.getValue()).andReturn(1);
+        expect(entry2.getKey()).andReturn("two");
+        expect(entry2.getValue()).andReturn(2);
+        expect(extractor.getValue("one")).andReturn(1);
+        expect(extractor.getValue("two")).andReturn(2);
+        extractor.removeValue("one");
+        extractor.removeValue("two");
+
+        replay(extractor, entry1, entry2);
+        List<Map.Entry<String, Object>> coll = new ArrayList<Map.Entry<String,Object>>();
+        coll.add(entry1);
+        coll.add(entry2);
+        assertTrue(entrySet.removeAll(coll));
+        verify(extractor, entry1, entry2);
+    }
+
+    /**
+     * Tests {@link Set#addAll(java.util.Collection)}
+     */
+    @Test
+    public void testRetainAll() {
+        Enumeration<String> keys = createMock(Enumeration.class);
+
+        expect(extractor.getKeys()).andReturn(keys);
+        expect(keys.hasMoreElements()).andReturn(true);
+        expect(keys.nextElement()).andReturn("one");
+        expect(keys.hasMoreElements()).andReturn(true);
+        expect(keys.nextElement()).andReturn("two");
+        expect(keys.hasMoreElements()).andReturn(true);
+        expect(keys.nextElement()).andReturn("three");
+        expect(keys.hasMoreElements()).andReturn(false);
+
+        Map.Entry<String, Object> entry1 = new MapEntry("one", 1, false);
+        Map.Entry<String, Object> entry2 = new MapEntry("two", 2, false);
+
+        expect(extractor.getValue("one")).andReturn(1);
+        expect(extractor.getValue("two")).andReturn(3);
+        expect(extractor.getValue("three")).andReturn(4);
+        extractor.removeValue("two");
+        extractor.removeValue("three");
+
+        replay(extractor, keys);
+        List<Map.Entry<String, Object>> coll = new ArrayList<Map.Entry<String,Object>>();
+        coll.add(entry1);
+        coll.add(entry2);
+        assertTrue(entrySet.retainAll(coll));
+        verify(extractor, keys);
+    }
+}

Propchange: tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/ScopeMapEntrySetTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/ScopeMapEntrySetTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/ScopeMapTest.java
URL: http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/ScopeMapTest.java?rev=937811&view=auto
==============================================================================
--- tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/ScopeMapTest.java (added)
+++ tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/ScopeMapTest.java Sun Apr 25 15:12:47 2010
@@ -0,0 +1,113 @@
+/**
+ *
+ */
+package org.apache.tiles.request.collection;
+
+import static org.easymock.EasyMock.*;
+import static org.easymock.classextension.EasyMock.*;
+import static org.junit.Assert.*;
+
+import java.util.Enumeration;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+import org.apache.tiles.request.collection.extractor.AttributeExtractor;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Tests {@link ScopeMap}.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ScopeMapTest {
+
+    private ScopeMap map;
+
+    private AttributeExtractor extractor;
+
+    /**
+     * Sets up the test.
+     */
+    @Before
+    public void setUp() {
+        extractor = createMock(AttributeExtractor.class);
+        map = new ScopeMap(extractor);
+    }
+
+    /**
+     * Test method for {@link org.apache.tiles.request.collection.ScopeMap#clear()}.
+     */
+    @SuppressWarnings("unchecked")
+    @Test
+    public void testClear() {
+        Enumeration<String> keys = createMock(Enumeration.class);
+
+        expect(extractor.getKeys()).andReturn(keys);
+        expect(keys.hasMoreElements()).andReturn(true);
+        expect(keys.nextElement()).andReturn("one");
+        expect(keys.hasMoreElements()).andReturn(true);
+        expect(keys.nextElement()).andReturn("two");
+        expect(keys.hasMoreElements()).andReturn(false);
+
+        extractor.removeValue("one");
+        extractor.removeValue("two");
+
+        replay(extractor, keys);
+        map.clear();
+        verify(extractor, keys);
+    }
+
+    /**
+     * Test method for {@link org.apache.tiles.request.collection.ScopeMap#keySet()}.
+     */
+    @Test
+    public void testKeySet() {
+        replay(extractor);
+        assertTrue(map.keySet() instanceof RemovableKeySet);
+        verify(extractor);
+    }
+
+    /**
+     * Test method for {@link org.apache.tiles.request.collection.ScopeMap#put(java.lang.String, java.lang.Object)}.
+     */
+    @Test
+    public void testPutStringObject() {
+        expect(extractor.getValue("one")).andReturn(null);
+        extractor.setValue("one", 1);
+
+        replay(extractor);
+        assertNull(map.put("one", 1));
+        verify(extractor);
+    }
+
+    /**
+     * Test method for {@link org.apache.tiles.request.collection.ScopeMap#putAll(java.util.Map)}.
+     */
+    @Test
+    public void testPutAllMapOfQextendsStringQextendsObject() {
+        Map<String, Object> items = new LinkedHashMap<String, Object>();
+        items.put("one", 1);
+        items.put("two", 2);
+
+        extractor.setValue("one", 1);
+        extractor.setValue("two", 2);
+
+        replay(extractor);
+        map.putAll(items);
+        verify(extractor);
+    }
+
+    /**
+     * Test method for {@link org.apache.tiles.request.collection.ScopeMap#remove(java.lang.Object)}.
+     */
+    @Test
+    public void testRemoveObject() {
+        expect(extractor.getValue("one")).andReturn(1);
+        extractor.removeValue("one");
+
+        replay(extractor);
+        assertEquals(new Integer(1), map.remove("one"));
+        verify(extractor);
+    }
+}

Propchange: tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/ScopeMapTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/collection/ScopeMapTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Modified: tiles/sandbox/trunk/tiles-request/tiles-request-servlet/src/main/java/org/apache/tiles/request/servlet/ServletApplicationContext.java
URL: http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles-request/tiles-request-servlet/src/main/java/org/apache/tiles/request/servlet/ServletApplicationContext.java?rev=937811&r1=937810&r2=937811&view=diff
==============================================================================
--- tiles/sandbox/trunk/tiles-request/tiles-request-servlet/src/main/java/org/apache/tiles/request/servlet/ServletApplicationContext.java (original)
+++ tiles/sandbox/trunk/tiles-request/tiles-request-servlet/src/main/java/org/apache/tiles/request/servlet/ServletApplicationContext.java Sun Apr 25 15:12:47 2010
@@ -29,7 +29,7 @@ import java.util.Set;
 import javax.servlet.ServletContext;
 
 import org.apache.tiles.request.ApplicationContext;
-import org.apache.tiles.request.collection.ParameterMap;
+import org.apache.tiles.request.collection.ReadOnlyEnumerationMap;
 import org.apache.tiles.request.collection.ScopeMap;
 import org.apache.tiles.request.servlet.extractor.ApplicationScopeExtractor;
 import org.apache.tiles.request.servlet.extractor.InitParameterExtractor;
@@ -90,7 +90,7 @@ public class ServletApplicationContext i
     public Map<String, String> getInitParams() {
 
         if ((initParam == null) && (servletContext != null)) {
-            initParam = new ParameterMap(new InitParameterExtractor(servletContext));
+            initParam = new ReadOnlyEnumerationMap<String>(new InitParameterExtractor(servletContext));
         }
         return (initParam);
 

Modified: tiles/sandbox/trunk/tiles-request/tiles-request-servlet/src/main/java/org/apache/tiles/request/servlet/ServletRequest.java
URL: http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles-request/tiles-request-servlet/src/main/java/org/apache/tiles/request/servlet/ServletRequest.java?rev=937811&r1=937810&r2=937811&view=diff
==============================================================================
--- tiles/sandbox/trunk/tiles-request/tiles-request-servlet/src/main/java/org/apache/tiles/request/servlet/ServletRequest.java (original)
+++ tiles/sandbox/trunk/tiles-request/tiles-request-servlet/src/main/java/org/apache/tiles/request/servlet/ServletRequest.java Sun Apr 25 15:12:47 2010
@@ -36,7 +36,7 @@ import org.apache.tiles.request.Abstract
 import org.apache.tiles.request.ApplicationContext;
 import org.apache.tiles.request.collection.AddableParameterMap;
 import org.apache.tiles.request.collection.HeaderValuesMap;
-import org.apache.tiles.request.collection.ParameterMap;
+import org.apache.tiles.request.collection.ReadOnlyEnumerationMap;
 import org.apache.tiles.request.collection.ScopeMap;
 import org.apache.tiles.request.servlet.extractor.ParameterExtractor;
 import org.apache.tiles.request.servlet.extractor.RequestScopeExtractor;
@@ -153,7 +153,7 @@ public class ServletRequest extends Abst
     public Map<String, String> getParam() {
 
         if ((param == null) && (request != null)) {
-            param = new ParameterMap(new ParameterExtractor(request));
+            param = new ReadOnlyEnumerationMap<String>(new ParameterExtractor(request));
         }
         return (param);
 



Mime
View raw message