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;
22 import java.util.function.BiFunction;
23 import java.util.function.Function;
26 * An immutable TrieMap
28 * @author Robert Varga
30 * @param <K> the type of keys maintained by this map
31 * @param <V> the type of mapped values
34 public final class ImmutableTrieMap<K, V> extends TrieMap<K, V> {
35 private final INode<K, V> root;
37 ImmutableTrieMap(final INode<K, V> root, final Equivalence<? super K> equiv) {
39 this.root = checkNotNull(root);
48 public V compute(final K key, final BiFunction<? super K, ? super V, ? extends V> remappingFunction) {
53 public V computeIfAbsent(final K key, final Function<? super K, ? extends V> mappingFunction) {
58 public V computeIfPresent(final K key, final BiFunction<? super K, ? super V, ? extends V> remappingFunction) {
63 public V merge(final K key, final V value, final BiFunction<? super V, ? super V, ? extends V> remappingFunction) {
68 public V put(final K key, final V value) {
73 public void putAll(final Map<? extends K, ? extends V> m) {
78 public V putIfAbsent(final K key, final V value) {
83 public V remove(final Object key) {
88 public boolean remove(final Object key, final Object value) {
93 public boolean replace(final K key, final V oldValue, final V newValue) {
98 public V replace(final K key, final V value) {
104 return root.cachedSize(this);
108 public final TrieMap<K, V> mutableSnapshot() {
109 return new MutableTrieMap<>(equiv(), new INode<>(new Gen(), root.gcasRead(this)));
113 public ImmutableTrieMap<K, V> immutableSnapshot() {
118 boolean isReadOnly() {
123 INode<K, V> RDCSS_READ_ROOT(final boolean abort) {
127 private static UnsupportedOperationException unsupported() {
128 return new UnsupportedOperationException("Attempted to modify a read-only view");