You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jmeter.apache.org by pm...@apache.org on 2013/01/05 20:24:30 UTC

svn commit: r1429362 - /jmeter/trunk/src/jorphan/org/apache/jorphan/collections/HashTree.java

Author: pmouawad
Date: Sat Jan  5 19:24:29 2013
New Revision: 1429362

URL: http://svn.apache.org/viewvc?rev=1429362&view=rev
Log:
Factor out constructor

Modified:
    jmeter/trunk/src/jorphan/org/apache/jorphan/collections/HashTree.java

Modified: jmeter/trunk/src/jorphan/org/apache/jorphan/collections/HashTree.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/jorphan/org/apache/jorphan/collections/HashTree.java?rev=1429362&r1=1429361&r2=1429362&view=diff
==============================================================================
--- jmeter/trunk/src/jorphan/org/apache/jorphan/collections/HashTree.java (original)
+++ jmeter/trunk/src/jorphan/org/apache/jorphan/collections/HashTree.java Sat Jan  5 19:24:29 2013
@@ -63,14 +63,14 @@ public class HashTree implements Seriali
      * Creates an empty new HashTree.
      */
     public HashTree() {
-        data = new HashMap<Object, HashTree>();
+        this(null, null);
     }
 
     /**
      * Allow subclasses to provide their own Map.
      */
     protected HashTree(Map<Object, HashTree> _map) {
-        data = _map;
+        this(_map, null);
     }
 
     /**
@@ -79,8 +79,23 @@ public class HashTree implements Seriali
      * @param key
      */
     public HashTree(Object key) {
-        data = new HashMap<Object, HashTree>();
-        data.put(key, new HashTree());
+        this(new HashMap<Object, HashTree>(), key);
+    }
+    
+    /**
+     * Uses the new HashTree if not null and adds the given object as a top-level node if not null
+     * @param _map
+     * @param key
+     */
+    public HashTree(Map<Object, HashTree> _map, Object key) {
+        if(_map != null) {
+            data = _map;
+        } else {
+            data = new HashMap<Object, HashTree>();
+        }
+        if(key != null) {
+            data.put(key, new HashTree());
+        }
     }
 
     /**



Re: svn commit: r1429362 - /jmeter/trunk/src/jorphan/org/apache/jorphan/collections/HashTree.java

Posted by sebb <se...@gmail.com>.
On 5 January 2013 19:24,  <pm...@apache.org> wrote:
> Author: pmouawad
> Date: Sat Jan  5 19:24:29 2013
> New Revision: 1429362
>
> URL: http://svn.apache.org/viewvc?rev=1429362&view=rev
> Log:
> Factor out constructor
>
> Modified:
>     jmeter/trunk/src/jorphan/org/apache/jorphan/collections/HashTree.java
>
> Modified: jmeter/trunk/src/jorphan/org/apache/jorphan/collections/HashTree.java
> URL: http://svn.apache.org/viewvc/jmeter/trunk/src/jorphan/org/apache/jorphan/collections/HashTree.java?rev=1429362&r1=1429361&r2=1429362&view=diff
> ==============================================================================
> --- jmeter/trunk/src/jorphan/org/apache/jorphan/collections/HashTree.java (original)
> +++ jmeter/trunk/src/jorphan/org/apache/jorphan/collections/HashTree.java Sat Jan  5 19:24:29 2013
> @@ -63,14 +63,14 @@ public class HashTree implements Seriali
>       * Creates an empty new HashTree.
>       */
>      public HashTree() {
> -        data = new HashMap<Object, HashTree>();
> +        this(null, null);
>      }
>
>      /**
>       * Allow subclasses to provide their own Map.
>       */
>      protected HashTree(Map<Object, HashTree> _map) {
> -        data = _map;
> +        this(_map, null);
>      }
>
>      /**
> @@ -79,8 +79,23 @@ public class HashTree implements Seriali
>       * @param key
>       */
>      public HashTree(Object key) {
> -        data = new HashMap<Object, HashTree>();
> -        data.put(key, new HashTree());
> +        this(new HashMap<Object, HashTree>(), key);
> +    }
> +
> +    /**
> +     * Uses the new HashTree if not null and adds the given object as a top-level node if not null
> +     * @param _map
> +     * @param key
> +     */
> +    public HashTree(Map<Object, HashTree> _map, Object key) {

This creates a new public ctor.
Is it really needed?
If not, make it private.

It can always be made protected or public later.

> +        if(_map != null) {
> +            data = _map;
> +        } else {
> +            data = new HashMap<Object, HashTree>();
> +        }
> +        if(key != null) {
> +            data.put(key, new HashTree());
> +        }
>      }
>
>      /**
>
>