ddafd8d7625c47e5d513731ebbda3e7443719076
[yangtools.git] / common / util / src / main / java / org / opendaylight / yangtools / util / ModifiableMapPhase.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.yangtools.util;
9
10 import com.google.common.annotations.Beta;
11 import com.google.common.collect.ImmutableMap;
12 import java.util.Map;
13 import javax.annotation.Nonnull;
14 import org.opendaylight.yangtools.concepts.Mutable;
15
16 /**
17  * A {@link Map} which can be modified and supports efficient conversion to an unmodifiable map. This interface is the
18  * logical counterpart to {@link UnmodifiableMapPhase}, but it does not require implementations of {@link #toUnmodifiableMap()}
19  * to return an implementation of that interface. The reason for that empty and singleton mappings are efficiently
20  * represented as {@link ImmutableMap}, which does not implement {@link UnmodifiableMapPhase}.
21  *
22  * @param <K> the type of keys maintained by this map
23  * @param <V> the type of mapped values
24  */
25 @Beta
26 public interface ModifiableMapPhase<K, V> extends Map<K, V>, Mutable {
27     /**
28      * Return an isolated unmodifiable version of this map. Returned object must not allow removal, addition or changing
29      * of mappings. Its mappings must match the mappings currently present in this map, but must not be affected by any
30      * subsequent changes to this map.
31      *
32      * @return An unmodifiable version of this map.
33      */
34     @Nonnull Map<K, V> toUnmodifiableMap();
35 }