Make ReadWriteTrieMap extend ForwardingMap
[yangtools.git] / common / util / src / main / java / org / opendaylight / yangtools / util / ReadWriteTrieMap.java
index 6250dd3640d2f49e9e847f881903c1f95d56c4ae..788c2d9b66834c961b6e4d1f3ef49c5ae0c35bcf 100644 (file)
@@ -8,11 +8,14 @@
 package org.opendaylight.yangtools.util;
 
 import com.google.common.base.Preconditions;
-import com.romix.scala.collection.concurrent.TrieMap;
+import com.google.common.collect.ForwardingMap;
 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;
 
@@ -21,27 +24,34 @@ import org.slf4j.LoggerFactory;
  * their size, and determining the size of a TrieMap is expensive, we make sure
  * to update it as we go.
  *
- * <p>FIXME: this map does not support modification view the keySet()/values()/entrySet()
- *        methods.
+ * <p>
+ * FIXME: this map does not support modification view the keySet()/values()/entrySet() methods.
  *
  * @param <K> Key type
  * @param <V> Value type
  */
-final class ReadWriteTrieMap<K, V> implements Map<K, V> {
+final class ReadWriteTrieMap<K, V> extends ForwardingMap<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;
     }
 
+    @Override
+    protected Map<K, V> delegate() {
+        return delegate;
+    }
+
     Map<K, V> toReadOnly() {
         final Map<K, V> ret = new ReadOnlyTrieMap<>(delegate, size);
         LOG.trace("Converted read-write TrieMap {} to read-only {}", this, ret);
@@ -58,21 +68,6 @@ final class ReadWriteTrieMap<K, V> implements Map<K, V> {
         return size == 0;
     }
 
-    @Override
-    public boolean containsKey(final Object key) {
-        return delegate.containsKey(key);
-    }
-
-    @Override
-    public boolean containsValue(final Object value) {
-        return delegate.containsValue(value);
-    }
-
-    @Override
-    public V get(final Object key) {
-        return delegate.get(key);
-    }
-
     @Override
     public V put(final K key, final V value) {
         final V ret = delegate.put(key, value);
@@ -92,7 +87,8 @@ final class ReadWriteTrieMap<K, V> implements Map<K, V> {
     }
 
     @Override
-    public void putAll(final Map<? extends K, ? extends V> m) {
+    @SuppressWarnings("checkstyle:parameterName")
+    public void putAll(@Nonnull final Map<? extends K, ? extends V> m) {
         for (Entry<? extends K, ? extends V> e : m.entrySet()) {
             put(e.getKey(), e.getValue());
         }
@@ -118,14 +114,4 @@ final class ReadWriteTrieMap<K, V> implements Map<K, V> {
     public Set<Entry<K, V>> entrySet() {
         return Collections.unmodifiableSet(delegate.entrySet());
     }
-
-    @Override
-    public boolean equals(final Object o) {
-        return delegate.equals(o);
-    }
-
-    @Override
-    public int hashCode() {
-        return delegate.hashCode();
-    }
 }