You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by se...@apache.org on 2010/12/15 20:12:49 UTC
svn commit: r1049669 - in /httpcomponents/httpcore/trunk/httpcore/src:
main/java/org/apache/http/params/ test/java/org/apache/http/params/
Author: sebb
Date: Wed Dec 15 19:12:48 2010
New Revision: 1049669
URL: http://svn.apache.org/viewvc?rev=1049669&view=rev
Log:
Replace entrySet()/HttpParamsSet with getNames()/HttpParamsNames
Added:
httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/params/HttpParamsNames.java (with props)
httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/params/TestDefaultedHttpParams.java (with props)
Removed:
httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/params/HttpParamsSet.java
Modified:
httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/params/AbstractHttpParams.java
httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/params/BasicHttpParams.java
httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/params/DefaultedHttpParams.java
httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/params/TestBasicHttpParams.java
Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/params/AbstractHttpParams.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/params/AbstractHttpParams.java?rev=1049669&r1=1049668&r2=1049669&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/params/AbstractHttpParams.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/params/AbstractHttpParams.java Wed Dec 15 19:12:48 2010
@@ -39,7 +39,7 @@ import org.apache.http.params.HttpParams
*
* @since 4.0
*/
-public abstract class AbstractHttpParams implements HttpParams, HttpParamsSet {
+public abstract class AbstractHttpParams implements HttpParams, HttpParamsNames {
/**
* Instantiates parameters.
@@ -108,15 +108,15 @@ public abstract class AbstractHttpParams
return !getBooleanParameter(name, false);
}
-
/**
- * Provide read-only access to the set of parameters as Map.Entry elements.
- * Must be overridden by subclasses.
- * @return the Set of Map.Entry<String, Object> elements
+ * {@inheritDoc}
+ * <p>
+ * Dummy implementation - must be overridden by subclasses.
+ *
* @since 4.1.1
- * @throws UnsupportedOperationException
+ * @throws UnsupportedOperationException - always
*/
- public Set entrySet() {
+ public Set getNames(){
throw new UnsupportedOperationException();
}
Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/params/BasicHttpParams.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/params/BasicHttpParams.java?rev=1049669&r1=1049668&r2=1049669&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/params/BasicHttpParams.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/params/BasicHttpParams.java Wed Dec 15 19:12:48 2010
@@ -29,6 +29,7 @@ package org.apache.http.params;
import java.io.Serializable;
import java.util.Collections;
+import java.util.HashSet;
import java.util.Map;
import java.util.HashMap;
import java.util.Iterator;
@@ -167,12 +168,15 @@ public class BasicHttpParams extends Abs
}
/**
- * Provide read-only access to the set of parameters as Map.Entry elements.
+ * Returns the current set of names.
*
- * @return the Set of Map.Entry<String, Object> elements
+ * Changes to the underlying HttpParams are not reflected
+ * in the set - it is a snapshot.
+ *
+ * @return the names, as a Set<String>
* @since 4.1.1
*/
- public Set entrySet(){
- return Collections.unmodifiableMap(parameters).entrySet();
+ public Set getNames() {
+ return new HashSet(parameters.keySet());
}
}
Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/params/DefaultedHttpParams.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/params/DefaultedHttpParams.java?rev=1049669&r1=1049668&r2=1049669&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/params/DefaultedHttpParams.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/params/DefaultedHttpParams.java Wed Dec 15 19:12:48 2010
@@ -27,6 +27,7 @@
package org.apache.http.params;
+import java.util.HashSet;
import java.util.Set;
import org.apache.http.params.HttpParams;
@@ -101,24 +102,63 @@ public final class DefaultedHttpParams e
/**
*
* @return the default HttpParams collection
+ * @deprecated (4.1.1) do not use, will be removed in a later version
*/
public HttpParams getDefaults() {
return this.defaults;
}
/**
- * Provide read-only access to the set of local parameters as Map.Entry elements.
- * To get the entrySet for the default parameters,
- * use {@code ((HttpParamsSet) getDefaults()).entrySet()}
- * @return the Set of Map.Entry<String, Object> elements
+ * Returns the current set of names
+ * from both the local and default HttpParams instances.
+ *
+ * Changes to the underlying HttpParams intances are not reflected
+ * in the set - it is a snapshot.
+ *
+ * @return the combined set of names, as a Set<String>
+ * @since 4.1.1
+ * @throws UnsupportedOperationException if either the local or default HttpParams instances do not implement HttpParamsNames
+ */
+ public Set getNames() {
+ Set combined = new HashSet(getNames(defaults));
+ combined.addAll(getNames(local));
+ return combined ;
+ }
+
+ /**
+ * Returns the current set of defaults names.
+ *
+ * Changes to the underlying HttpParams are not reflected
+ * in the set - it is a snapshot.
+ *
+ * @return the names, as a Set<String>
* @since 4.1.1
- * @throws UnsupportedOperationException if local parameters does not implement HttpParamsSet
+ * @throws UnsupportedOperationException if the default HttpParams instance does not implement HttpParamsNames
*/
- public Set entrySet() {
- if (local instanceof HttpParamsSet) {
- return ((HttpParamsSet) local).entrySet();
+ public Set getDefaultNames() {
+ return new HashSet(getNames(defaults));
+ }
+
+ /**
+ * Returns the current set of local names.
+ *
+ * Changes to the underlying HttpParams are not reflected
+ * in the set - it is a snapshot.
+ *
+ * @return the names, as a Set<String>
+ * @since 4.1.1
+ * @throws UnsupportedOperationException if the local HttpParams instance does not implement HttpParamsNames
+ */
+ public Set getLocalNames() {
+ return new HashSet(getNames(local));
+ }
+
+ // Helper method
+ private Set getNames(HttpParams params) {
+ if (params instanceof HttpParamsNames) {
+ return ((HttpParamsNames) params).getNames();
}
- throw new UnsupportedOperationException();
+ throw new UnsupportedOperationException("HttpParams instance does not implement HttpParamsNames");
}
}
Added: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/params/HttpParamsNames.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/params/HttpParamsNames.java?rev=1049669&view=auto
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/params/HttpParamsNames.java (added)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/params/HttpParamsNames.java Wed Dec 15 19:12:48 2010
@@ -0,0 +1,54 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * 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.http.params;
+
+import java.util.Set;
+
+/**
+ * Gives access to the full set of parameter names.
+ *
+ * @see HttpParams
+ *
+ * @since 4.1.1
+ */
+public interface HttpParamsNames {
+
+ /**
+ * Returns the current set of names;
+ * in the case of stacked parameters, returns the names
+ * from all the participating HttpParams instances.
+ *
+ * Changes to the underlying HttpParams are not reflected
+ * in the set - it is a snapshot.
+ *
+ * @return the names, as a Set<String>
+ * @since 4.1.1
+ */
+ Set getNames();
+
+}
Propchange: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/params/HttpParamsNames.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/params/HttpParamsNames.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Modified: httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/params/TestBasicHttpParams.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/params/TestBasicHttpParams.java?rev=1049669&r1=1049668&r2=1049669&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/params/TestBasicHttpParams.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/params/TestBasicHttpParams.java Wed Dec 15 19:12:48 2010
@@ -57,19 +57,19 @@ public class TestBasicHttpParams extends
params.removeParameter("param1"));
}
- public void testIterate() {
+ public void testgetNames() {
BasicHttpParams params = new BasicHttpParams();
- Set entrySet = params.entrySet();
- Iterator iterator = entrySet.iterator();
- assertTrue(entrySet.isEmpty());
- assertFalse(iterator.hasNext());
+ Set nameSet = params.getNames();
+ assertTrue(nameSet.isEmpty());
params.setBooleanParameter("true", true);
- assertFalse(entrySet.isEmpty());
- assertEquals(1, entrySet.size());
- iterator = entrySet.iterator(); // refetch, as iterator is a snapshot
+ assertTrue(nameSet.isEmpty()); // Still empty, as it is a snapshot
+ nameSet = params.getNames();
+ assertFalse(nameSet.isEmpty());
+ assertEquals(1, nameSet.size());
+ Iterator iterator = nameSet.iterator(); // refetch, as iterator is a snapshot
assertTrue("Iterator has an entry",iterator.hasNext());
- Entry entry = (Entry) iterator.next();
+ String entry = (String) iterator.next();
// Note: Java 1.3 requires JUnit 3.8.1 which does not have assertTrue(Boolean)
- assertTrue(((Boolean) entry.getValue()).booleanValue());
+ assertTrue(((Boolean) params.getParameter(entry)).booleanValue());
}
}
Added: httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/params/TestDefaultedHttpParams.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/params/TestDefaultedHttpParams.java?rev=1049669&view=auto
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/params/TestDefaultedHttpParams.java (added)
+++ httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/params/TestDefaultedHttpParams.java Wed Dec 15 19:12:48 2010
@@ -0,0 +1,99 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * 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.http.params;
+
+import java.util.Iterator;
+import java.util.Map.Entry;
+import java.util.Set;
+
+import junit.framework.TestCase;
+
+/**
+ * Unit tests for {@link BasicHttpParams}.
+ *
+ */
+public class TestDefaultedHttpParams extends TestCase {
+
+ public TestDefaultedHttpParams(String testName) {
+ super(testName);
+ }
+
+ public void testAddRemoveParam() {
+ DefaultedHttpParams deflt = new DefaultedHttpParams(new BasicHttpParams(), new BasicHttpParams());
+ assertFalse("The parameter should not be removed successfully", deflt.removeParameter("param1"));
+ deflt.setParameter("param1", "paramValue1");
+ assertEquals(0, deflt.getDefaultNames().size());
+ assertEquals(1, deflt.getNames().size());
+ assertEquals(1, deflt.getLocalNames().size());
+ assertTrue("The parameter should be removed successfully", deflt.removeParameter("param1"));
+ assertFalse("The parameter should not be present", deflt.removeParameter("param1"));
+ assertEquals(0, deflt.getDefaultNames().size());
+ assertEquals(0, deflt.getNames().size());
+ assertEquals(0, deflt.getLocalNames().size());
+ }
+
+ public void testEmptyParams() {
+ DefaultedHttpParams deflt = new DefaultedHttpParams(new BasicHttpParams(), new BasicHttpParams());
+ assertNull("The parameter should not be present", deflt.getParameter("param1"));
+ //try a remove from an empty params
+ assertFalse("The parameter should not be present", deflt.removeParameter("param1"));
+
+ assertEquals(0, deflt.getNames().size());
+ assertEquals(0, deflt.getLocalNames().size());
+ assertEquals(0, deflt.getDefaultNames().size());
+ }
+
+ private HttpParams addParams(String name){
+ BasicHttpParams params = new BasicHttpParams();
+ params.setParameter("common","both");
+ params.setParameter(name,"value");
+ return params;
+ }
+ public void testgetNames() {
+ DefaultedHttpParams params = new DefaultedHttpParams(addParams("local"), addParams("default"));
+
+ Set nameSet = params.getNames();
+ assertEquals(3, nameSet.size());
+ Set localnameSet = params.getLocalNames();
+ assertEquals(2, localnameSet.size());
+ Set defaultnameSet = params.getDefaultNames();
+ assertEquals(2, defaultnameSet.size());
+
+ params.setParameter("new", null);
+ assertEquals(3, nameSet.size()); // Name set not yet updated
+ assertEquals(2, localnameSet.size());
+ assertEquals(2, defaultnameSet.size());
+
+ nameSet = params.getNames();
+ localnameSet = params.getLocalNames();
+ defaultnameSet = params.getDefaultNames();
+ assertEquals(4, nameSet.size());
+ assertEquals(3, localnameSet.size());
+ assertEquals(2, defaultnameSet.size());
+ }
+}
Propchange: httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/params/TestDefaultedHttpParams.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/params/TestDefaultedHttpParams.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision