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 <robert.varga@pantheon.tech>
package org.opendaylight.yangtools.util;
import com.google.common.base.Preconditions;
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;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
* their size, and determining the size of a TrieMap is expensive, we make sure
* to update it as we go.
*
* 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
*/
*
* @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 static final Logger LOG = LoggerFactory.getLogger(ReadOnlyTrieMap.class);
private final MutableTrieMap<K, V> delegate;
private final MutableTrieMap<K, V> delegate;
private int size;
ReadWriteTrieMap() {
private int size;
ReadWriteTrieMap() {
+ @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);
Map<K, V> toReadOnly() {
final Map<K, V> ret = new ReadOnlyTrieMap<>(delegate, size);
LOG.trace("Converted read-write TrieMap {} to read-only {}", this, ret);
- @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 V put(final K key, final V value) {
final V ret = delegate.put(key, value);
public Set<Entry<K, V>> entrySet() {
return Collections.unmodifiableSet(delegate.entrySet());
}
public Set<Entry<K, V>> 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();
- }