BUG-7464: Switch to use forked TrieMap 43/51843/7
authorRobert Varga <rovarga@cisco.com>
Tue, 14 Feb 2017 09:13:49 +0000 (10:13 +0100)
committerRobert Varga <nite@hq.sk>
Wed, 19 Jul 2017 12:46:53 +0000 (12:46 +0000)
Switch from dead upstream to our forked version of TrieMap.

Change-Id: Ide40b87b96d16500e2a8566d3d627ca1aac8d762
Signed-off-by: Robert Varga <rovarga@cisco.com>
common/util/pom.xml
common/util/src/main/java/org/opendaylight/yangtools/util/MapAdaptor.java
common/util/src/main/java/org/opendaylight/yangtools/util/ReadOnlyTrieMap.java
common/util/src/main/java/org/opendaylight/yangtools/util/ReadWriteTrieMap.java
common/util/src/test/java/org/opendaylight/yangtools/util/ReadWriteTrieMapTest.java
third-party/triemap/src/main/java/org/opendaylight/yangtools/triemap/MutableTrieMap.java
third-party/triemap/src/main/java/org/opendaylight/yangtools/triemap/TrieMap.java

index f12e86ebcd3e36a39b111aabcf9c1535e153acf1..b0ca73f8f85b8d22960e51e4b97b6922e1c84e11 100644 (file)
             <artifactId>concepts</artifactId>
         </dependency>
         <dependency>
-            <groupId>com.google.guava</groupId>
-            <artifactId>guava</artifactId>
+            <groupId>org.opendaylight.yangtools</groupId>
+            <artifactId>triemap</artifactId>
         </dependency>
         <dependency>
-            <groupId>com.github.romix</groupId>
-            <artifactId>java-concurrent-hash-trie-map</artifactId>
+            <groupId>com.google.guava</groupId>
+            <artifactId>guava</artifactId>
         </dependency>
 
         <dependency>
index 3e5fec119dbd2aa77aac70aa4afac2bffa5a948e..6ca8710b185827002033224bd930a8450c4bd39c 100644 (file)
@@ -10,11 +10,12 @@ package org.opendaylight.yangtools.util;
 import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.Maps;
-import com.romix.scala.collection.concurrent.TrieMap;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Map.Entry;
+import org.opendaylight.yangtools.triemap.MutableTrieMap;
+import org.opendaylight.yangtools.triemap.TrieMap;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -217,7 +218,7 @@ public final class MapAdaptor {
          * which will maintain the size for us.
          */
         LOG.trace("Copying input {} to a TrieMap ({} entries)", input, size);
-        final TrieMap<K, V> map = new TrieMap<>();
+        final MutableTrieMap<K, V> map = TrieMap.create();
         map.putAll(input);
         final Map<K, V> ret = new ReadOnlyTrieMap<>(map, size);
         LOG.trace("Read-only TrieMap is {}", ret);
index 0082ff3f5f782191e97c5de564601f4743b44757..465f668450bf99926972497287505f32fbcccd9e 100644 (file)
@@ -9,9 +9,10 @@ package org.opendaylight.yangtools.util;
 
 import com.google.common.base.Preconditions;
 import com.google.common.collect.ForwardingMap;
-import com.romix.scala.collection.concurrent.TrieMap;
 import java.util.Map;
 import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
+import org.opendaylight.yangtools.triemap.ImmutableTrieMap;
+import org.opendaylight.yangtools.triemap.MutableTrieMap;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -24,30 +25,30 @@ import org.slf4j.LoggerFactory;
  */
 final class ReadOnlyTrieMap<K, V> extends ForwardingMap<K, V> {
     @SuppressWarnings("rawtypes")
-    private static final AtomicReferenceFieldUpdater<ReadOnlyTrieMap, TrieMap> UPDATER =
-            AtomicReferenceFieldUpdater.newUpdater(ReadOnlyTrieMap.class, TrieMap.class, "readOnly");
+    private static final AtomicReferenceFieldUpdater<ReadOnlyTrieMap, ImmutableTrieMap> UPDATER =
+            AtomicReferenceFieldUpdater.newUpdater(ReadOnlyTrieMap.class, ImmutableTrieMap.class, "readOnly");
     private static final Logger LOG = LoggerFactory.getLogger(ReadOnlyTrieMap.class);
-    private final TrieMap<K, V> readWrite;
+    private final MutableTrieMap<K, V> readWrite;
     private final int size;
-    private volatile TrieMap<K, V> readOnly;
+    private volatile ImmutableTrieMap<K, V> readOnly;
 
-    ReadOnlyTrieMap(final TrieMap<K, V> map, final int size) {
+    ReadOnlyTrieMap(final MutableTrieMap<K, V> map, final int size) {
         super();
         this.readWrite = Preconditions.checkNotNull(map);
         this.size = size;
     }
 
     Map<K, V> toReadWrite() {
-        final Map<K, V> ret = new ReadWriteTrieMap<>(readWrite.snapshot(), size);
+        final Map<K, V> ret = new ReadWriteTrieMap<>(readWrite.mutableSnapshot(), size);
         LOG.trace("Converted read-only TrieMap {} to read-write {}", this, ret);
         return ret;
     }
 
     @Override
     protected Map<K, V> delegate() {
-        TrieMap<K, V> ret = readOnly;
+        ImmutableTrieMap<K, V> ret = readOnly;
         if (ret == null) {
-            ret = readWrite.readOnlySnapshot();
+            ret = readWrite.immutableSnapshot();
             if (!UPDATER.compareAndSet(this, null, ret)) {
                 ret = readOnly;
             }
index 4d91e1812d8ff41c105b9892996baaa9e47d2950..bf8c06a33b0d0e5b3a5358247d09564676306205 100644 (file)
@@ -8,12 +8,13 @@
 package org.opendaylight.yangtools.util;
 
 import com.google.common.base.Preconditions;
-import com.romix.scala.collection.concurrent.TrieMap;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Map;
 import java.util.Set;
 import javax.annotation.Nonnull;
+import org.opendaylight.yangtools.triemap.MutableTrieMap;
+import org.opendaylight.yangtools.triemap.TrieMap;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -30,15 +31,15 @@ import org.slf4j.LoggerFactory;
  */
 final class ReadWriteTrieMap<K, V> implements Map<K, V> {
     private static final Logger LOG = LoggerFactory.getLogger(ReadOnlyTrieMap.class);
-    private final TrieMap<K, V> delegate;
+    private final MutableTrieMap<K, V> delegate;
     private int size;
 
     ReadWriteTrieMap() {
-        this.delegate = new TrieMap<>();
+        this.delegate = TrieMap.create();
         this.size = 0;
     }
 
-    ReadWriteTrieMap(final TrieMap<K, V> delegate, final int size) {
+    ReadWriteTrieMap(final MutableTrieMap<K, V> delegate, final int size) {
         this.delegate = Preconditions.checkNotNull(delegate);
         this.size = size;
     }
@@ -130,4 +131,9 @@ final class ReadWriteTrieMap<K, V> implements Map<K, V> {
     public int hashCode() {
         return delegate.hashCode();
     }
+
+    @Override
+    public String toString() {
+        return delegate.toString();
+    }
 }
index 8af39c471f0a01ff7cf821603169309c6cdd2523..d7f79056f6217c182f18efc3b26cd6f3ece6ef91 100644 (file)
@@ -9,22 +9,24 @@ package org.opendaylight.yangtools.util;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
-import com.romix.scala.collection.concurrent.TrieMap;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Set;
 import org.junit.Test;
+import org.opendaylight.yangtools.triemap.MutableTrieMap;
+import org.opendaylight.yangtools.triemap.TrieMap;
 
 public class ReadWriteTrieMapTest {
 
     @Test
     public void testMethodsOfReadWriteTrieMap() {
-        final TrieMap<String, String> trieMap = new TrieMap<>();
+        final MutableTrieMap<String, String> trieMap = TrieMap.create();
         trieMap.put("0", "zero");
         trieMap.put("1", "one");
 
@@ -51,24 +53,21 @@ public class ReadWriteTrieMapTest {
         final Collection<String> trieMapValues = readWriteTrieMap.values();
         assertEquals("Size of values should be '3'.", 3, trieMapValues.size());
 
-        assertTrue("Entry set of readWriteTrieMap and trieMap should by equals.",
-            convertSetEntryToMap(readWriteTrieMap.entrySet()).equals(trieMap));
+        assertEquals(convertSetEntryToMap(readWriteTrieMap.entrySet()), trieMap);
 
         trieMap.put("2", "two");
         final ReadWriteTrieMap<String, String> readWriteTrieMap2 = new ReadWriteTrieMap<>(trieMap, 4);
 
-        assertFalse("Objects readWriteTrieMap and readOnlyTrieMap2 should be different.",
-            readWriteTrieMap.equals(readWriteTrieMap2));
-        assertFalse("Hash codes of object readWriteTrieMap and readOnelyTrieMap2 should be different.",
-            readWriteTrieMap.hashCode() == readWriteTrieMap2.hashCode());
+        assertNotEquals(readWriteTrieMap, readWriteTrieMap2);
+        assertEquals(readWriteTrieMap.hashCode(), readWriteTrieMap2.hashCode());
 
         final Map<String, String> readOnlyTrieMap = readWriteTrieMap.toReadOnly();
         readWriteTrieMap.clear();
-        assertEquals("Size of readWriteTrieMap should be '0'.", 0, readWriteTrieMap.size());
-        assertEquals("Size of readOnlyTrieMap should be '6'.", 6, readOnlyTrieMap.size());
+        assertEquals(0, readWriteTrieMap.size());
+        assertEquals(6, readOnlyTrieMap.size());
     }
 
-    public Map<String, String> convertSetEntryToMap(final Set<Entry<String, String>> input) {
+    private static Map<String, String> convertSetEntryToMap(final Set<Entry<String, String>> input) {
         Map<String, String> resultMap = new HashMap<>();
         for (Entry<String, String> entry : input) {
             resultMap.put(entry.getKey(), entry.getValue());
index 26fbba0816f59a44e9dd22c5d4e81654cc13bc8f..72c8b19870f7f9365893554f4dae32dbf47b797b 100644 (file)
@@ -35,7 +35,7 @@ import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
  * @param <V> the type of mapped values
  */
 @Beta
-final class MutableTrieMap<K, V> extends TrieMap<K, V> {
+public final class MutableTrieMap<K, V> extends TrieMap<K, V> {
     private static final long serialVersionUID = 1L;
 
     @SuppressWarnings("rawtypes")
index 5bcefcaa1e46f289e86bb6b606f9986d56cd8e93..36cf5cc3613d140d4b634ca6aa9219c0a146dca4 100644 (file)
@@ -50,7 +50,7 @@ public abstract class TrieMap<K, V> extends AbstractMap<K, V> implements Concurr
         this.equiv = equiv;
     }
 
-    public static <K, V> TrieMap<K, V> create() {
+    public static <K, V> MutableTrieMap<K, V> create() {
         return new MutableTrieMap<>(Equivalence.equals());
     }