hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r609308 - in /httpcomponents/httpcore/trunk/module-main/src: main/java/org/apache/http/params/BasicHttpParams.java main/java/org/apache/http/params/HttpParams.java test/java/org/apache/http/params/TestBasicHttpParams.java
Date Sun, 06 Jan 2008 13:40:35 GMT
Author: olegk
Date: Sun Jan  6 05:40:34 2008
New Revision: 609308

URL: http://svn.apache.org/viewvc?rev=609308&view=rev
Log:
HTTPCORE-136: HttpParams has no removeParameter

Contributed by Andrea Selva <selva.andre at gmail.com>

Modified:
    httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/params/BasicHttpParams.java
    httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/params/HttpParams.java
    httpcomponents/httpcore/trunk/module-main/src/test/java/org/apache/http/params/TestBasicHttpParams.java

Modified: httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/params/BasicHttpParams.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/params/BasicHttpParams.java?rev=609308&r1=609307&r2=609308&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/params/BasicHttpParams.java
(original)
+++ httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/params/BasicHttpParams.java
Sun Jan  6 05:40:34 2008
@@ -127,6 +127,20 @@
         return this;
     }
     
+    public boolean removeParameter(String name) {
+        if (this.parameters == null) {
+            return false;
+        }
+        //this is to avoid the case in which the key has a null value
+        if (this.parameters.containsKey(name)) {
+            this.parameters.remove(name);
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    
     /**
      * Assigns the value to all the parameter with the given names
      * 

Modified: httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/params/HttpParams.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/params/HttpParams.java?rev=609308&r1=609307&r2=609308&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/params/HttpParams.java
(original)
+++ httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/params/HttpParams.java
Sun Jan  6 05:40:34 2008
@@ -69,6 +69,15 @@
      * @return  a new set of parameters holding the same values as this one
      */
     HttpParams copy();
+    
+    /**
+     * Removes the parameter with the specified name.
+     * 
+     * @param name parameter name
+     * 
+     * @return true if the parameter existed and has been removed, false else.
+     */
+    boolean removeParameter(String name);
 
     /** 
      * Returns a {@link Long} parameter value with the given name. 

Modified: httpcomponents/httpcore/trunk/module-main/src/test/java/org/apache/http/params/TestBasicHttpParams.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/module-main/src/test/java/org/apache/http/params/TestBasicHttpParams.java?rev=609308&r1=609307&r2=609308&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/module-main/src/test/java/org/apache/http/params/TestBasicHttpParams.java
(original)
+++ httpcomponents/httpcore/trunk/module-main/src/test/java/org/apache/http/params/TestBasicHttpParams.java
Sun Jan  6 05:40:34 2008
@@ -93,5 +93,19 @@
         assertEquals("parent parameter not known in copy",
                      "something", copy.getParameter("parent+"));
     }
+    
+    public void testRemoveParam() {
+        BasicHttpParams params = new BasicHttpParams();
+        params.setParameter("param1", "paramValue1");
+        assertTrue("The parameter should be removed successfully", 
+                params.removeParameter("param1"));
+        assertFalse("The parameter should not be present", 
+                params.removeParameter("param1"));
+        
+        //try a remove from an empty params
+        params = new BasicHttpParams();
+        assertFalse("The parameter should not be present", 
+                params.removeParameter("param1"));
+    }
 
 }



Mime
View raw message