View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      https://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  package org.apache.commons.collections4;
19  
20  import java.util.Map;
21  
22  /**
23   * The "write" subset of the {@link Map} interface.
24   * <p>
25   * NOTE: in the original {@link Map} interface, {@link Map#put(Object, Object)} is known to have the same return type as {@link Map#get(Object)}, namely
26   * {@code V}. {@link Put} makes no assumptions in this regard (there is no association with, nor even knowledge of, a "reading" interface) and thus defines
27   * {@link #put(Object, Object)} as returning {@link Object}.
28   * </p>
29   *
30   * @param <K> The type of the keys in this map.
31   * @param <V> The type of the values in this map.
32   * @since 4.0
33   * @see Get
34   */
35  public interface Put<K, V> {
36  
37      /**
38       * Removes all of the mappings from this map.
39       *
40       * @see Map#clear()
41       */
42      void clear();
43  
44      /**
45       * Associates the specified value with the specified key in this map.
46       * <p>
47       * Note that the return type is Object, rather than V as in the Map interface. See the class Javadoc for further info.
48       * </p>
49       *
50       * @param key   key with which the specified value is to be associated.
51       * @param value value to be associated with the specified key.
52       * @return The previous value associated with {@code key}, or {@code null} if there was no mapping for {@code key}. (A {@code null} return can also indicate
53       *         that the map previously associated {@code null} with {@code key}, if the implementation supports {@code null} values.)
54       * @see Map#put(Object, Object)
55       */
56      Object put(K key, V value);
57  
58      /**
59       * Copies all of the mappings from the specified map to this map.
60       *
61       * @param t mappings to be stored in this map.
62       * @see Map#putAll(Map)
63       */
64      void putAll(Map<? extends K, ? extends V> t);
65  }