*/
package org.opendaylight.yangtools.util;
+import static java.util.Objects.requireNonNull;
+
+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.slf4j.Logger;
import org.slf4j.LoggerFactory;
-
-import com.google.common.base.Preconditions;
-import com.romix.scala.collection.concurrent.TrieMap;
+import tech.pantheon.triemap.MutableTrieMap;
+import tech.pantheon.triemap.TrieMap;
/**
* A TrieMap facade tracking modifications. Since we change structures based on
* their size, and determining the size of a TrieMap is expensive, we make sure
* to update it as we go.
*
- * 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> {
- private static final Logger LOG = LoggerFactory.getLogger(ReadOnlyTrieMap.class);
- private final TrieMap<K, V> delegate;
+final class ReadWriteTrieMap<K, V> extends ForwardingMap<K, V> {
+ private static final Logger LOG = LoggerFactory.getLogger(ReadWriteTrieMap.class);
+
+ private final MutableTrieMap<K, V> delegate;
+
private int size;
- ReadWriteTrieMap(final TrieMap<K, V> delegate, final int size) {
- this.delegate = Preconditions.checkNotNull(delegate);
+ ReadWriteTrieMap() {
+ this.delegate = TrieMap.create();
+ this.size = 0;
+ }
+
+ ReadWriteTrieMap(final MutableTrieMap<K, V> delegate, final int size) {
+ this.delegate = requireNonNull(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);
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);
}
@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());
}
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();
- }
}