2 * (C) Copyright 2016 Pantheon Technologies, s.r.o. and others.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.opendaylight.yangtools.triemap;
18 import static java.util.Objects.requireNonNull;
20 import com.google.common.collect.ForwardingObject;
21 import java.io.Serializable;
22 import java.util.Collection;
25 import java.util.concurrent.ConcurrentMap;
26 import java.util.function.BiFunction;
27 import java.util.function.Function;
30 * This is a port of Scala's TrieMap class from the Scala Collections library. This implementation does not support
31 * null keys nor null values.
33 * @author Aleksandar Prokopec (original Scala implementation)
34 * @author Roman Levenstein (original Java 6 port)
35 * @author Robert Varga
37 * @param <K> the type of keys maintained by this map
38 * @param <V> the type of mapped values
39 * @deprecated use {@link tech.pantheon.triemap.TrieMap} instead.
42 public abstract class TrieMap<K, V> extends ForwardingObject implements ConcurrentMap<K,V>, Serializable {
43 private static final long serialVersionUID = 1L;
45 private final tech.pantheon.triemap.TrieMap<K, V> delegate;
47 TrieMap(final tech.pantheon.triemap.TrieMap<K, V> delegate) {
48 this.delegate = requireNonNull(delegate);
51 public static <K, V> MutableTrieMap<K, V> create() {
52 return new MutableTrieMap<>(tech.pantheon.triemap.TrieMap.create());
56 * Returns a snapshot of this TrieMap. This operation is lock-free and
57 * linearizable. Modification operations on this Map and the returned one
58 * are isolated from each other.
61 * The snapshot is lazily updated - the first time some branch in the
62 * snapshot or this TrieMap are accessed, they are rewritten. This means
63 * that the work of rebuilding both the snapshot and this TrieMap is
64 * distributed across all the threads doing updates or accesses subsequent
65 * to the snapshot creation.
67 * @return A read-write TrieMap containing the contents of this map.
69 public abstract TrieMap<K, V> mutableSnapshot();
72 * Returns a read-only snapshot of this TrieMap. This operation is lock-free
76 * The snapshot is lazily updated - the first time some branch of this
77 * TrieMap are accessed, it is rewritten. The work of creating the snapshot
78 * is thus distributed across subsequent updates and accesses on this
79 * TrieMap by all threads. Note that the snapshot itself is never rewritten
80 * unlike when calling {@link #mutableSnapshot()}, but the obtained snapshot
84 * This method is used by other methods such as `size` and `iterator`.
86 * @return A read-only TrieMap containing the contents of this map.
88 public abstract ImmutableTrieMap<K, V> immutableSnapshot();
91 public final boolean containsKey(final Object key) {
92 return delegate.containsKey(key);
96 public final boolean containsValue(final Object value) {
97 return delegate.containsValue(value);
101 public final Set<Entry<K, V>> entrySet() {
102 return delegate.entrySet();
106 public final Set<K> keySet() {
107 return delegate.keySet();
111 public final V get(final Object key) {
112 return delegate.get(key);
116 public final void clear() {
121 public final V put(final K key, final V value) {
122 return delegate.put(key, value);
126 public final V putIfAbsent(final K key, final V value) {
127 return delegate.putIfAbsent(key, value);
131 public final V remove(final Object key) {
132 return delegate.remove(key);
136 public final boolean remove(final Object key, final Object value) {
137 return delegate.remove(key, value);
141 public final boolean replace(final K key, final V oldValue, final V newValue) {
142 return delegate.replace(key, oldValue, newValue);
146 public final V replace(final K key, final V value) {
147 return delegate.replace(key, value);
151 public final int size() {
152 return delegate.size();
156 public final boolean isEmpty() {
157 return delegate.isEmpty();
161 public final void putAll(final Map<? extends K, ? extends V> m) {
166 public final Collection<V> values() {
167 return delegate.values();
171 public final V compute(final K key, final BiFunction<? super K, ? super V, ? extends V> remappingFunction) {
172 return delegate.compute(key, remappingFunction);
176 public final V computeIfAbsent(final K key, final Function<? super K, ? extends V> mappingFunction) {
177 return delegate.computeIfAbsent(key, mappingFunction);
181 public final V computeIfPresent(final K key,
182 final BiFunction<? super K, ? super V, ? extends V> remappingFunction) {
183 return delegate.computeIfPresent(key, remappingFunction);
187 public final V merge(final K key, final V value,
188 final BiFunction<? super V, ? super V, ? extends V> remappingFunction) {
189 return delegate.merge(key, value, remappingFunction);
193 public final int hashCode() {
194 return delegate.hashCode();
198 public final boolean equals(final Object o) {
199 return delegate.equals(o);
203 protected final tech.pantheon.triemap.TrieMap<K, V> delegate() {