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 com.google.common.base.Preconditions.checkNotNull;
20 import com.google.common.annotations.Beta;
21 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
23 import java.util.function.BiFunction;
24 import java.util.function.Function;
27 * An immutable TrieMap.
29 * @author Robert Varga
31 * @param <K> the type of keys maintained by this map
32 * @param <V> the type of mapped values
35 public final class ImmutableTrieMap<K, V> extends TrieMap<K, V> {
36 private static final long serialVersionUID = 1L;
38 @SuppressFBWarnings(value = "SE_BAD_FIELD", justification = "Handled by SerializationProxy")
39 private final INode<K, V> root;
41 ImmutableTrieMap(final INode<K, V> root, final Equivalence<? super K> equiv) {
43 this.root = checkNotNull(root);
52 public V compute(final K key, final BiFunction<? super K, ? super V, ? extends V> remappingFunction) {
57 public V computeIfAbsent(final K key, final Function<? super K, ? extends V> mappingFunction) {
62 public V computeIfPresent(final K key, final BiFunction<? super K, ? super V, ? extends V> remappingFunction) {
67 public V merge(final K key, final V value, final BiFunction<? super V, ? super V, ? extends V> remappingFunction) {
72 public V put(final K key, final V value) {
77 @SuppressWarnings("checkstyle:parameterName")
78 public void putAll(final Map<? extends K, ? extends V> m) {
83 public V putIfAbsent(final K key, final V value) {
88 public V remove(final Object key) {
93 public boolean remove(final Object key, final Object value) {
98 public boolean replace(final K key, final V oldValue, final V newValue) {
103 public V replace(final K key, final V value) {
109 return root.size(this);
113 public TrieMap<K, V> mutableSnapshot() {
114 return new MutableTrieMap<>(equiv(), new INode<>(new Gen(), root.gcasRead(this)));
118 public ImmutableTrieMap<K, V> immutableSnapshot() {
123 ImmutableEntrySet<K, V> createEntrySet() {
124 return new ImmutableEntrySet<>(this);
128 ImmutableKeySet<K> createKeySet() {
129 return new ImmutableKeySet<>(this);
133 boolean isReadOnly() {
138 ImmutableIterator<K, V> iterator() {
139 return immutableIterator();
143 INode<K, V> RDCSS_READ_ROOT(final boolean abort) {
147 static UnsupportedOperationException unsupported() {
148 return new UnsupportedOperationException("Attempted to modify a read-only view");