BUG-7464: Move INode.newRootNode() 73/49873/6
authorRobert Varga <rovarga@cisco.com>
Fri, 30 Dec 2016 13:15:00 +0000 (14:15 +0100)
committerRobert Varga <rovarga@cisco.com>
Mon, 9 Jan 2017 14:17:12 +0000 (15:17 +0100)
This method is called from TrieMap only, hence we can safely
move it there and make it private.

Change-Id: I842c2c473482b0c081fa51a11bc3f703eaefdc6d
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
third-party/triemap/src/main/java/org/opendaylight/yangtools/triemap/INode.java
third-party/triemap/src/main/java/org/opendaylight/yangtools/triemap/TrieMap.java

index 6c12cd88749ce5689fb75a52f02fdf2a986f3b02..56b606c1fec37da0f98ee21bed16a9f8e663a0a8 100644 (file)
@@ -25,12 +25,6 @@ final class INode<K, V> extends INodeBase<K, V> {
      */
     static final Object RESTART = new Object();
 
-    static <K,V> INode<K,V> newRootNode() {
-        Gen gen = new Gen ();
-        CNode<K, V> cn = new CNode<> (0, new BasicNode[] {}, gen);
-        return new INode<>(gen, cn);
-    }
-
     INode(final Gen gen, final MainNode<K, V> bn) {
         super(gen, bn);
     }
index 5bc64245cf643c8a68417de0df1351c818f59263..881090e7b3b40c93e334e79c27648c088e823e08 100644 (file)
@@ -114,7 +114,7 @@ public class TrieMap<K, V> extends AbstractMap<K, V> implements ConcurrentMap<K,
     }
 
     public TrieMap (final Hashing<K> hashf, final Equiv<K> ef) {
-        this(INode.newRootNode(), hashf, ef, false);
+        this(newRootNode(), hashf, ef, false);
     }
 
     public TrieMap () {
@@ -155,6 +155,13 @@ public class TrieMap<K, V> extends AbstractMap<K, V> implements ConcurrentMap<K,
     // } while (obj != TrieMapSerializationEnd);
     // }
 
+
+    private static <K,V> INode<K,V> newRootNode() {
+        final Gen gen = new Gen();
+        final CNode<K, V> cn = new CNode<>(0, new BasicNode[] {}, gen);
+        return new INode<>(gen, cn);
+    }
+
     final boolean CAS_ROOT (final Object ov, final Object nv) {
         if (isReadOnly()) {
             throw new IllegalStateException("Attempted to modify a read-only snapshot");
@@ -390,7 +397,7 @@ public class TrieMap<K, V> extends AbstractMap<K, V> implements ConcurrentMap<K,
     final public void clear () {
         while (true) {
             INode<K, V> r = RDCSS_READ_ROOT ();
-            if (!RDCSS_ROOT (r, r.gcasRead (this), INode.<K, V>newRootNode ())) {
+            if (!RDCSS_ROOT(r, r.gcasRead(this), newRootNode())) {
                 continue;
             }else{
                 return;
@@ -903,7 +910,7 @@ public class TrieMap<K, V> extends AbstractMap<K, V> implements ConcurrentMap<K,
 
     private void readObject(final ObjectInputStream inputStream) throws IOException, ClassNotFoundException {
         inputStream.defaultReadObject();
-        this.root = INode.newRootNode();
+        this.root = newRootNode();
 
         final boolean ro = inputStream.readBoolean();
         final int size = inputStream.readInt();