/* * (C) Copyright 2016 Pantheon Technologies, s.r.o. and others. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.opendaylight.yangtools.triemap; import static com.google.common.base.Preconditions.checkNotNull; import com.google.common.annotations.Beta; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.util.Map; import java.util.function.BiFunction; import java.util.function.Function; /** * An immutable TrieMap * * @author Robert Varga * * @param the type of keys maintained by this map * @param the type of mapped values */ @Beta public final class ImmutableTrieMap extends TrieMap { private static final long serialVersionUID = 1L; @SuppressFBWarnings(value = "SE_BAD_FIELD", justification = "Handled by SerializationProxy") private final INode root; ImmutableTrieMap(final INode root, final Equivalence equiv) { super(equiv); this.root = checkNotNull(root); } @Override public void clear() { throw unsupported(); } @Override public V compute(final K key, final BiFunction remappingFunction) { throw unsupported(); } @Override public V computeIfAbsent(final K key, final Function mappingFunction) { throw unsupported(); } @Override public V computeIfPresent(final K key, final BiFunction remappingFunction) { throw unsupported(); } @Override public V merge(final K key, final V value, final BiFunction remappingFunction) { throw unsupported(); } @Override public V put(final K key, final V value) { throw unsupported(); } @Override public void putAll(final Map m) { throw unsupported(); } @Override public V putIfAbsent(final K key, final V value) { throw unsupported(); } @Override public V remove(final Object key) { throw unsupported(); } @Override public boolean remove(final Object key, final Object value) { throw unsupported(); } @Override public boolean replace(final K key, final V oldValue, final V newValue) { throw unsupported(); } @Override public V replace(final K key, final V value) { throw unsupported(); } @Override public int size() { return root.cachedSize(this); } @Override public final TrieMap mutableSnapshot() { return new MutableTrieMap<>(equiv(), new INode<>(new Gen(), root.gcasRead(this))); } @Override public ImmutableTrieMap immutableSnapshot() { return this; } @Override boolean isReadOnly() { return true; } @Override INode RDCSS_READ_ROOT(final boolean abort) { return root; } private static UnsupportedOperationException unsupported() { return new UnsupportedOperationException("Attempted to modify a read-only view"); } }