Switch from dead upstream to our forked version of TrieMap.
Change-Id: Ide40b87b96d16500e2a8566d3d627ca1aac8d762
Signed-off-by: Robert Varga <rovarga@cisco.com>
<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>
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;
* 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);
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;
*/
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;
}
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;
*/
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;
}
public int hashCode() {
return delegate.hashCode();
}
+
+ @Override
+ public String toString() {
+ return delegate.toString();
+ }
}
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");
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());
* @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")
this.equiv = equiv;
}
- public static <K, V> TrieMap<K, V> create() {
+ public static <K, V> MutableTrieMap<K, V> create() {
return new MutableTrieMap<>(Equivalence.equals());
}