From: Robert Varga Date: Wed, 19 Jul 2017 11:58:20 +0000 (+0200) Subject: Make ReadWriteTrieMap extend ForwardingMap X-Git-Tag: release/nitrogen~28 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=950c070a8c54b026acf7860094d699052611ab54;p=yangtools.git Make ReadWriteTrieMap extend ForwardingMap ForwardingMap gives us some of the implementation details we are duplicating here. Hence subclass ForwardingMap and remove those duplications. Change-Id: I5cb6b839f19f2247fb7fdc78f46127739f484898 Signed-off-by: Robert Varga --- diff --git a/common/util/src/main/java/org/opendaylight/yangtools/util/ReadWriteTrieMap.java b/common/util/src/main/java/org/opendaylight/yangtools/util/ReadWriteTrieMap.java index bf8c06a33b..788c2d9b66 100644 --- a/common/util/src/main/java/org/opendaylight/yangtools/util/ReadWriteTrieMap.java +++ b/common/util/src/main/java/org/opendaylight/yangtools/util/ReadWriteTrieMap.java @@ -8,6 +8,7 @@ package org.opendaylight.yangtools.util; import com.google.common.base.Preconditions; +import com.google.common.collect.ForwardingMap; import java.util.Collection; import java.util.Collections; import java.util.Map; @@ -23,15 +24,17 @@ import org.slf4j.LoggerFactory; * 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. + *

+ * FIXME: this map does not support modification view the keySet()/values()/entrySet() methods. * * @param Key type * @param Value type */ -final class ReadWriteTrieMap implements Map { +final class ReadWriteTrieMap extends ForwardingMap { private static final Logger LOG = LoggerFactory.getLogger(ReadOnlyTrieMap.class); + private final MutableTrieMap delegate; + private int size; ReadWriteTrieMap() { @@ -44,6 +47,11 @@ final class ReadWriteTrieMap implements Map { this.size = size; } + @Override + protected Map delegate() { + return delegate; + } + Map toReadOnly() { final Map ret = new ReadOnlyTrieMap<>(delegate, size); LOG.trace("Converted read-write TrieMap {} to read-only {}", this, ret); @@ -60,21 +68,6 @@ final class ReadWriteTrieMap implements Map { 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); @@ -121,19 +114,4 @@ final class ReadWriteTrieMap implements Map { public Set> entrySet() { return Collections.unmodifiableSet(delegate.entrySet()); } - - @Override - public boolean equals(final Object obj) { - return delegate.equals(obj); - } - - @Override - public int hashCode() { - return delegate.hashCode(); - } - - @Override - public String toString() { - return delegate.toString(); - } }