hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r744577 - /httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/params/BasicHttpParams.java
Date Sat, 14 Feb 2009 22:32:21 GMT
Author: sebb
Date: Sat Feb 14 22:32:20 2009
New Revision: 744577

URL: http://svn.apache.org/viewvc?rev=744577&view=rev
Log:
Make HashMap final to improve thread-safety
Add some Javadoc

Modified:
    httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/params/BasicHttpParams.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=744577&r1=744576&r2=744577&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
Sat Feb 14 22:32:20 2009
@@ -55,33 +55,22 @@
     private static final long serialVersionUID = -7086398485908701455L;
 
     /** Map of HTTP parameters that this collection contains. */
-    private HashMap parameters;
+    private final HashMap parameters = new HashMap();
 
     public BasicHttpParams() {
         super();
     }
 
     public Object getParameter(final String name) {
-        // See if the parameter has been explicitly defined
-        Object param = null;
-        if (this.parameters != null) {
-            param = this.parameters.get(name);
-        }    
-        return param;
+        return this.parameters.get(name);
     }
 
     public HttpParams setParameter(final String name, final Object value) {
-        if (this.parameters == null) {
-            this.parameters = new HashMap();
-        }
         this.parameters.put(name, value);
         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);
@@ -95,7 +84,7 @@
     /**
      * Assigns the value to all the parameter with the given names
      * 
-     * @param names array of parameter name
+     * @param names array of parameter names
      * @param value parameter value
      */ 
     public void setParameters(final String[] names, final Object value) {
@@ -104,19 +93,40 @@
         }
     }
 
+    /**
+     * Is the parameter set?
+     * <p>
+     * Uses {@link #getParameter(String)} (which is overrideable) to
+     * fetch the parameter value, if any.
+     * <p>
+     * Also @see {@link #isParameterSetLocally(String)}
+     * 
+     * @param name parameter name
+     * @return true if parameter is defined and non-null
+     */
     public boolean isParameterSet(final String name) {
         return getParameter(name) != null;
     }
         
+    /**
+     * Is the parameter set in this object?
+     * <p>
+     * The parameter value is fetched directly.
+     * <p>
+     * Also @see {@link #isParameterSet(String)}
+     * 
+     * @param name parameter name
+     * @return true if parameter is defined and non-null
+     */
     public boolean isParameterSetLocally(final String name) {
-        return this.parameters != null && this.parameters.get(name) != null;
+        return this.parameters.get(name) != null;
     }
         
     /**
      * Removes all parameters from this collection.
      */
     public void clear() {
-        this.parameters = null;
+        this.parameters.clear();
     }
 
     /**
@@ -146,9 +156,6 @@
      * @param target    the parameters to which to copy
      */
     protected void copyParams(HttpParams target) {
-        if (this.parameters == null)
-            return;
-
         Iterator iter = parameters.entrySet().iterator();
         while (iter.hasNext()) {
             Map.Entry me = (Map.Entry) iter.next();



Mime
View raw message